stat查看文件属性

Linux 下 通过 stat 命令获取文件的属性,例如大小,最后的修改时间等等.

 

stat的属性使用方法 可以通过

"stat --help" 获取如下内容:

 

Java代码   收藏代码
  1. Usage: stat [OPTION] FILE...  
  2. Display file or filesystem status.  
  3.   
  4.   -f, --filesystem      display filesystem status instead of file status  
  5.   -c  --format=FORMAT   use the specified FORMAT instead of the default  
  6.   -L, --dereference     follow links  
  7.   -Z, --context         print the security context information if available  
  8.   -t, --terse           print the information in terse form  
  9.       --help     display this help and exit  
  10.       --version  output version information and exit  
  11.   
  12. The valid format sequences for files (without --filesystem):  
  13.   
  14.   %A   Access rights in human readable form  
  15.   %a   Access rights in octal  
  16.   %B   The size in bytes of each block reported by `%b'  
  17.   %b   Number of blocks allocated (see %B)  
  18.   %D   Device number in hex  
  19.   %d   Device number in decimal  
  20.   %F   File type  
  21.   %f   Raw mode in hex  
  22.   %G   Group name of owner  
  23.   %g   Group ID of owner  
  24.   %h   Number of hard links  
  25.   %i   Inode number  
  26.   %N   Quoted File name with dereference if symbolic link  
  27.   %n   File name  
  28.   %o   IO block size  
  29.   %s   Total size, in bytes  
  30.   %T   Minor device type in hex  
  31.   %t   Major device type in hex  
  32.   %U   User name of owner  
  33.   %u   User ID of owner  
  34.   %X   Time of last access as seconds since Epoch  
  35.   %x   Time of last access  
  36.   %Y   Time of last modification as seconds since Epoch  
  37.   %y   Time of last modification  
  38.   %Z   Time of last change as seconds since Epoch  
  39.   %z   Time of last change  
  40.   
  41. Valid format sequences for file systems:  
  42.   
  43.   %a   Free blocks available to non-superuser  
  44.   %b   Total data blocks in file system  
  45.   %c   Total file nodes in file system  
  46.   %d   Free file nodes in file system  
  47.   %f   Free blocks in file system  
  48.   %C - Security context in SELinux  
  49.   %i   File System id in hex  
  50.   %l   Maximum length of filenames  
  51.   %n   File name  
  52.   %s   Optimal transfer block size  
  53.   %T   Type in human readable form  
  54.   %t   Type in hex  

 

使用方式如下:

1. 不带参数   stat /path/to/myfile.ext  输出如下:

Java代码   收藏代码
  1.   File: `myfile.ext'  
  2.   Size: 1044611         Blocks: 2056       IO Block: 32768  regular file  
  3. Device: xxx/xxx Inode: 1543149     Links: 1  
  4. Access: (0664/-rw-rw-r--)  Uid: (3005410/  xxxxx)   Gid: (10001013/xxxxxx)  
  5. Access: 2011-08-16 03:01:05.393004000 -0400  
  6. Modify: 2011-08-16 04:09:30.714166000 -0400  
  7. Change: 2011-08-16 04:09:30.714166000 -0400  

 

2. 带参数   stat -c'%Z| %s' myfile.ext   输出如下:

Java代码   收藏代码
  1. 1313486175|1118056  

 

    以上使用了'format'参数,此处使用了

 

Java代码   收藏代码
  1. %Z   Time of last change as seconds since Epoch  

    与

Java代码   收藏代码
  1. %s   Total size, in bytes  

    注意,如果使用多个格式标签,需要使用引号将其包裹起来,此处的 | 是自行添加的,可以自行添加\t \n 等等格式字符.

 

猜你喜欢

转载自ydlmlh.iteye.com/blog/1953699
今日推荐