stat檢視檔案屬性
阿新 • • 發佈:2019-01-22
Linux 下 通過 stat 命令獲取檔案的屬性,例如大小,最後的修改時間等等.
stat的屬性使用方法 可以通過
"stat --help" 獲取如下內容:
Java程式碼- 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
- %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 輸出如下:
Java程式碼- 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 輸出如下:
Java程式碼- 1313486175|1118056
以上使用了'format'引數,此處使用了
Java程式碼- %Z Time of last change as seconds since Epoch
與
Java程式碼- %s Total size, in bytes
注意,如果使用多個格式標籤,需要使用引號將其包裹起來,此處的 | 是自行新增的,可以自行新增\t \n 等等格式字元.