Linux 下 通过 stat 命令获取文件的属性,例如大小,最后的修改时间等等.
stat的属性使用方法 可以通过
"stat --help" 获取如下内容:
Usage: stat [OPTION] FILE...
Display file or filesystem status.
-f, --filesystem display filesystem status instead of file status
-c --format=FORMAT use the specified FORMAT instead of the default
-L, --dereference follow links
-Z, --context print the security context information if available
-t, --terse print the information in terse form
--help display this help and exit
--version output version information and exit
The valid format sequences for files (without --filesystem):
%A Access rights in human readable form
%a Access rights in octal
%B The size in bytes of each block reported by `%b'
%b Number of blocks allocated (see %B)
%D Device number in hex
%d Device number in decimal
%F File type
%f Raw mode in hex
%G Group name of owner
%g Group ID of owner
%h Number of hard links
%i Inode number
%N Quoted File name with dereference if symbolic link
%n File name
%o IO block size
%s Total size, in bytes
%T Minor device type in hex
%t Major device type in hex
%U User name of owner
%u User ID of owner
%X Time of last access as seconds since Epoch
%x Time of last access
%Y Time of last modification as seconds since Epoch
%y Time of last modification
%Z Time of last change as seconds since Epoch
%z Time of last change
Valid format sequences for file systems:
%a Free blocks available to non-superuser
%b Total data blocks in file system
%c Total file nodes in file system
%d Free file nodes in file system
%f Free blocks in file system
%C - Security context in SELinux
%i File System id in hex
%l Maximum length of filenames
%n File name
%s Optimal transfer block size
%T Type in human readable form
%t Type in hex
使用方式如下:
1. 不带参数 stat /path/to/myfile.ext 输出如下:
File: `myfile.ext'
Size: 1044611 Blocks: 2056 IO Block: 32768 regular file
Device: xxx/xxx Inode: 1543149 Links: 1
Access: (0664/-rw-rw-r--) Uid: (3005410/ xxxxx) Gid: (10001013/xxxxxx)
Access: 2011-08-16 03:01:05.393004000 -0400
Modify: 2011-08-16 04:09:30.714166000 -0400
Change: 2011-08-16 04:09:30.714166000 -0400
2. 带参数 stat -c'%Z|
%s'
myfile.ext 输出如下:
1313486175|1118056
以上使用了'format'参数,此处使用了
%Z Time of last change as seconds since Epoch
与
%s Total size, in bytes
注意,如果使用多个格式标签,需要使用引号将其包裹起来,此处的 |
是自行添加的,可以自行添加\t \n
等等格式字符.
分享到:
相关推荐
查看文件属性有多种方法,且这些方法中偏向不同,具体如下: 1,ls ls -a 查看所有文件 ls -l 查看详细的属性 2,lsattr 查看文件的扩展属性, 如果文件被 chattr +i 添加了写保护, 用lsattr可以...
stat结构描述了文件的属性,主要包括文件的类型、文件大小等等。详细stat结构如下所示: struct stat { mode_t st_mode; // file type & mode(permissions) ino_t st_ino; // i-node number(ser
fhs的使用方法,文件相关的操作命令,stat FILENAME 文件详细属性信息
1.43 lsattr指令:显示文件属性 1.44 mattrib指令:变更或显示MS-DOS文件的属性 1.45 mc指令:菜单式文件管理程序 1.46 mcopy指令:复制MS-DOS文件 1.47 mdel指令:删除MS-DOS文件 1.48 mdir指令:显示MS-DOS目录 ...
文件的基本操作(打开、定位、读写、关闭) I/O效率 文件共享 其他重要I/O函数 ext2文件系统在磁盘的组织 stat、fstat、lstat函数 文件的基本性质 修改文件属性的函数 硬链接与符号连接 目录操作
1、手动实现递归1.1 stat()函数族stat函数族包括:stat,fstat以及lstat函数,都是向用户返回文件的属性信息(元数据)。 代码如下:view plaincopy to clipboardprint?#include int stat(const char*pathname,
简单易懂哦!显示文件长格式信息 void printlong(char *name) { struct stat buf; struct passwd *usr; struct group *grp; int rt;... struct tm *ttime;... //调用lstat 获取文件属性,并对返回值做错
课程内容:Linux文件类型、stat、lstat、fstat获取文件属性、umask掩码、chmod/fchmod修改文件权限、文件系统如何管理文件、link/unlink/remove/rename、symlink/readlinkchdir、getcwd。
linux下使用各种c函数实现ls -l的功能,主要使用stat函数确定文件的属性,具体内容见文档,里面含有各个模块的解释,最后附加啦整体的源代码,仅供参考学习。
onedrive_stat,类似GetFileInformationByHandle等获取文件属性的函数, onedrive_mkdir, 类似CreateDirectory创建目录函数 onedrive_delfile,类似DeleteFile和RemoveDirectory等删除函数。 onedrive_upfile,更新...
在不同模式下使用统计信息-定义最小和最大时期时间戳记,并获取介于两者之间已创建的所有文件 基本特点: Bash脚本 无需安装或代理 使用通用工具提取属性(例如,不同模式下的md5sum,grep,stat) 旨在在具有Bash...
4.2 stat、fstat和lstat函数 4.3 文件类型 4.4 设置用户ID和设置组ID 4.5 文件访问权限 4.6 新文件和目录的所有权 4.7 access函数 4.8 umask函数 4.9 chmod和fchmod函数 4.10 粘住位 ...
4.2 stat、fstat和lstat函数71 目录 4.3 文件类型72 4.4 设置用户id和设置组id 74 4.5 文件访问权限75 4.6 新文件和目录的所有权77 4.7 access函数77 4.8 umask函数79 4.9 chmod和fchmod函数81 4.10 粘住位...
4.2 stat、fstat和lstat函数 71 4.3 文件类型 72 4.4 设置用户ID和设置组ID 74 4.5 文件访问权限 75 4.6 新文件和目录的所有权 77 4.7 access函数 77 4.8 umask函数 79 4.9 chmod和fchmod函数 81 ...
4.2 stat、fstat和lstat函数71 目录 4.3 文件类型72 4.4 设置用户id和设置组id 74 4.5 文件访问权限75 4.6 新文件和目录的所有权77 4.7 access函数77 4.8 umask函数79 4.9 chmod和fchmod函数81 4.10 粘住位...
68 习题 68 第4章 文件和目录 71 4.1 引言 71 4.2 stat、fstat和lstat函数 71 4.3 文件类型 72 4.4 设置用户ID和设置组ID 74 4.5 文件访问权限 75 4.6 新文件和目录的所有权 77 4.7 access函数 77 ...
4.2 stat、fstat和lstat函数 71 4.3 文件类型 72 4.4 设置用户ID和设置组ID 74 4.5 文件访问权限 75 4.6 新文件和目录的所有权 77 4.7 access函数 77 4.8 umask函数 79 4.9 chmod和fchmod函数 81 ...
4.2 stat, fstat和lstat函数 54 4.3 文件类型 55 4.4 设置-用户-ID和设置-组-ID 57 4.5 文件存取许可权 58 4.6 新文件和目录的所有权 60 4.7 access函数 60 4.8 umask函数 62 4.9 chmod和fchmod函数 63 4.10 粘住位 ...