利用stat命令获取Linux文件系统和文件的详细状态信息
用途:stat命令用于顯示文件或文件系統(tǒng)的狀態(tài)信息,來(lái)自于coreutils軟件包,一般系統(tǒng)自帶此命令工具,它能獲取與文件系統(tǒng)及文件相關(guān)的許多信息,具體用途見(jiàn)stat的功能選項(xiàng)。這些信息包括inode、atime、ctime、mtime、文件(系統(tǒng))類型、權(quán)限、塊大小、符號(hào)連接等。
語(yǔ)法:stat [OPTION]... FILE... , 可通過(guò)stat --help或man stat獲取它的幫助信息
功能選項(xiàng):功能選項(xiàng)需要結(jié)合-c參數(shù)使用,如利用stat獲取文件的inode信息,則使用stat –c%i /filepath/filename可以獲得/filepath/filename文件的inode編號(hào)。
針對(duì)文件系統(tǒng):
注意:當(dāng)目標(biāo)文件是文件系統(tǒng)時(shí)需要使用-f選項(xiàng),如利用stat獲取文件系統(tǒng)的inode數(shù)量,則使用stat –f –c%c /filepath/filename可以獲得/filepath/filename文件系統(tǒng)的inode數(shù)量。
| %a | Free blocks available to non-superuser | 顯示非超級(jí)用戶的剩余塊信息 |
| %b | Total data blocks in file system | 文件系統(tǒng)上的數(shù)據(jù)塊總數(shù) |
| %c | Total file nodes in file system | 文件系統(tǒng)中inode總數(shù) |
| %d | Free file nodes in file system | 文件系統(tǒng)中剩余的inode數(shù)量 |
| %f | Free blocks in file system | 文件系統(tǒng)中剩余的塊 |
| %C | SELinux security context string | SELinux安全內(nèi)容信息 |
| %i | File System ID in hex | 十六進(jìn)制的文件系統(tǒng)ID |
| %l | Maximum length of filenames | 文件名的最大長(zhǎng)度 |
| %n | File name | 文件名稱 |
| %s | Block size (for faster transfers) | 塊大小(為了更快的傳輸(速度)) |
| %S | Fundamental block size (for block counts) | 最小的塊大小 |
| %t | Type in hex | 十六進(jìn)制文件系統(tǒng)類型 |
| %T | Type in human readable form | 人類可閱讀的文件系統(tǒng)類型 |
針對(duì)文件:
| %a | Access rights in octal | 八進(jìn)制文件訪問(wèn)權(quán)限 |
| %A | Access rights in human readable form | 適合人類閱讀的文件訪問(wèn)權(quán)限 |
| %b | Number of blocks allocated (see %B) | 分配的塊數(shù)量 |
| %B | The size in bytes of each block reported by %b | 塊大小 |
| %C | SELinux security context string | SELinux安全內(nèi)容信息 |
| %d | Device number in decimal | 十進(jìn)制設(shè)備號(hào) |
| %D | Device number in hex | 十六進(jìn)制設(shè)備號(hào) |
| %f | Raw mode in hex | 十六進(jìn)制顯示Raw模式 |
| %F | File type | 獲取文件類型 |
| %g | Group ID of owner | 文件所有者的組ID |
| %G | Group name of owner | 文件所有者的組名稱 |
| %h | Number of hard links | 文件的硬連接數(shù)量 |
| %i | Inode Number | 文件的inode號(hào) |
| %n | File name | 文件名稱 |
| %N | Quoted file name with dereference if symbolic links | 如果是符號(hào)鏈接則顯示映射關(guān)系 |
| %o | I/O block size | I/O塊大小 |
| %s | Total size, in bytes | 文件總大小 |
| %t | Major device type in hex | 十六進(jìn)制的首要設(shè)備類型 |
| %T | Minor device type in hex | 十六進(jìn)制的次要設(shè)備類型 |
| %u | User ID of owner | 文件所有者的用戶ID |
| %U | User name of owner | 文件所有者的用戶名稱 |
| %x | Time of last access | 文件最后的訪問(wèn)時(shí)間(人類可閱讀) |
| %X | Time of last access as seconds since Epoch | 文件最后的訪問(wèn)時(shí)間(UNIX時(shí)間) |
| %y | Time of last modification | 文件最后的內(nèi)容更改時(shí)間(人類可閱讀) |
| %Y | Time of last modification as seconds since Epoch | 文件最后的內(nèi)容更改時(shí)間(UNIX時(shí)間) |
| %z | Time of last change | 文件最后的改變(除了內(nèi)容還包括權(quán)限信息)時(shí)間(人類可閱讀) |
| %Z | Time of last change as seconds since Epoch | 文件最后的改變(除了內(nèi)容還包括權(quán)限信息)時(shí)間(UNIX時(shí)間) |
注意:符號(hào)鏈接文件的內(nèi)容變化不影響mtime和ctime,只對(duì)目標(biāo)文件有影響。
--end--
轉(zhuǎn)載于:https://blog.51cto.com/dgd2010/1629945
總結(jié)
以上是生活随笔為你收集整理的利用stat命令获取Linux文件系统和文件的详细状态信息的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 基于verilog流水灯设计
- 下一篇: 基于FPGA的FFT设计