linux stat命令詳解

來源:互聯網
上載者:User

標籤:stat 命令詳解   linux   

linux stat 命令的作用很強大,我們可以根據這個命令列出的資訊,進一步瞭解檔案,最基本的就是檔案的時間變化。

例如:

[[email protected] tmp]$ stat 123.log 

  File: "123.log"

  Size: 24              Blocks: 8          IO Block: 4096   普通檔案

Device: 802h/2050d      Inode: 7077977     Links: 1

Access: (0755/-rwxr-xr-x)  Uid: (  501/   metao)   Gid: (  501/   metao)

Access: 2015-01-08 11:55:52.939370484 +0800

Modify: 2014-12-31 16:58:58.525116667 +0800

Change: 2015-01-08 11:54:50.765180227 +0800


Access:  檔案被訪問的時間。例如:more。但是cat 不會更改這個時間。

Modify:  檔案內容改變的時間。例如:檔案內容有改變,就會更改這個時間。

Change:  檔案狀態改變時間。;例如:chown,chmod會改變這個時間。



下面參考:

http://colinzhouyj.blog.51cto.com/2265679/1288580

stat 命令的具體參數詳解如下:


stat

  -L, --dereference     follow links  如果是連結檔案,則擷取原檔案資訊
  -Z, --context         print the security context information if available
                               列印SElinux安全上下文資訊
  -f, --file-system     display file system status instead of file status
                              顯示檔案所在的檔案系統的狀態
  -c  --format=FORMAT   use the specified FORMAT instead of the default;
                          output a newline after each use of FORMAT
                          自訂輸出格式,結尾有換行
      --printf=FORMAT   like --format, but interpret backslash escapes,
                          and do not output a mandatory trailing newline.
                          If you want a newline, include \n in FORMAT.
                          自訂輸出格式,結尾無分行符號,需手動添加
  -t, --terse           print the information in terse form
                           以簡潔的形式列印輸出資訊(在沒有改變輸出格式的情況下)
      --help     display this help and exit
                    列印協助資訊
      --version  output version information and exit
                     列印版本資訊並退出

可選的檔案資訊輸出格式
  %a   Access rights in octal 八進位格式的檔案存取權限   
  %A   Access rights in human readable form 可讀形式存取權限(ls -l情況下顯示的樣子)
  %b   Number of blocks allocated (see %B)  分配的塊數(單位參照%B的數值)
  %B   The size in bytes of each block reported by %b  
          每個塊的大小(這個值是指硬碟上儲存單元塊的大小,與格式化的block塊大小不同)
  %d   Device number in decimal  裝置號(10進位)
  %D   Device number in hex 裝置號(十六進位)
  %f   Raw mode in hex raw模式(十六進位,可以百度一下raw的意思)
  %F   File type 檔案類型
  %g   Group ID of owner 檔案所有者的組ID
  %G   Group name of owner 檔案所有者的組名
  %h   Number of hard links    永久連結的數量(檔案本身算1個)
  %i   Inode number  inode號
  %n   File name  檔案名稱
  %N   Quoted file name with dereference if symbolic link 
         取消軟串連的檔案名稱引用,變成一般字元串
  %o   I/O block size   系統格式化block的大小
  %s   Total size, in bytes   檔案大小(單位byte)
  %t   Major device type in hex 主要裝置類型(十六進位)
  %T   Minor device type in hex 次要裝置類型(十六進位)
  %u   User ID of owner  所有者的使用者ID
  %U   User name of owner 所有者的使用者名稱
  %x   Time of last access 最後訪問時間
  %X   Time of last access as seconds since Epoch  最後一次訪問時間(大紀元秒)
  %y   Time of last modification 最後修改時間(內容改變) 
  %Y   Time of last modification as seconds since Epoch 最後修改時間(內容改變)
  %z   Time of last change 最後改變時間(檔案屬性,許可權所有者等,格式大紀元秒)
  %Z   Time of last change as seconds since Epoch 
         最後改變時間(檔案屬性,許可權所有者等,格式大紀元秒)
stat -c "%a %A %b %B %d %D %f %F %g %G %h %i %n %N %o %s %t %T %u %U %x %X %y %Y %z %Z" file
可選的分區資訊輸出格式
  %a   Free blocks available to non-superuser 普通使用者可用的block數量      
  %b   Total data blocks in file system 分區的總資料區塊數量       
  %c   Total file nodes in file system 檔案系統的inode總數       
  %d   Free file nodes in file system 空閑inode數量       
  %f   Free blocks in file system 可用的block數量      
  %C   Security context in SELinux selinux 安全上下文       
  %i   File System ID in hex  分區ID(十六進位)  
  %l   Maximum length of filenames 分區檔案名稱最大長度       
  %n   File name  檔案名稱      
  %s   Block size (for faster transfers) 塊大小(都是系統block的大小)
  %S   Fundamental block size (for block counts) 基本塊大小(都是系統block的大小)
  %t   Type in hex 檔案系統類型(格式化的類型,十六進位)
  %T   Type in human readable form 檔案系統類型(格式化的類型,可讀形式)
stat -f -c "%a %b %c %d %f %C %i %l %n %s %S %t %T" file



本文出自 “為夢想而努力!” 部落格,請務必保留此出處http://815632410.blog.51cto.com/1544685/1600626

linux stat命令詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.