linux stat命令參數及用法詳解

來源:互聯網
上載者:User

功能說明:顯示inode內容。
語  法:stat [檔案或目錄]
補充說明:stat以文字的格式來顯示inode的內容。

ls 命令及其許多參數提供了一些非常有用的檔案資訊。另一個不太為人所熟知的命令 stat 提供了一些更為有用的資訊。 

下面示範了如何對可執行檔“oracle”(位於 $ORACLE_HOME/bin 目錄下)使用此命令。  
 
# cd $ORACLE_HOME/bin   
# stat oracle   
  File: `oracle'   
  Size: 93300148        Blocks:182424     IO Block:4096   Regular File   
Device: 343h/835d       Inode: 12009652    Links: 1       
Access: (6751/-rwsr-s--x)  Uid:(  500/  oracle)   Gid:(  500/     dba)   
Access: 2006-08-04 04:30:52.000000000 -0400  
Modify: 2005-11-02 11:49:47.000000000 -0500  
Change: 2005-11-02 11:55:24.000000000 -0500  
注意使用該命令獲得的資訊:除了通常的檔案大小(也可以使用 ls -l 命令獲得)以外,您還獲得了該檔案佔用的塊數。通常的 Linux 塊大小為 512 位元組,因此一個大小為 93,300,148 位元組的檔案將佔用 (93300148/512=) 182226.85 個塊。由於塊都是完整佔用,因此該檔案使用了一些整數個數的塊。無需猜測就可以獲得確切的塊數。 

您還可以從以上輸出中獲得檔案所有權的 GID 和 UID,以及許可權的八進位表示形式 (6751)。如果要將檔案恢複到它現在具有的相同許可權,可以使用 chmod 6751 oracle,而不是顯式拼字這些許可權。 

以上輸出最有用的部分是檔案訪問時間戳記資訊。該輸出顯示,該檔案被訪問的時間是 2006-08-04 04:30:52(顯示在“Access:”的旁邊),即 2006 年 8 月 4 日上午 4:30:52。這是某個人開始使用資料庫的時間。該檔案的date.html' target='_blank'>修改時間是 2005-11-02 11:49:47(顯示在“Modify:”的旁邊)。最後,“Change:”旁邊的時間戳記顯示檔案狀態更改的時間。 

stat 命令的修改符 -f 顯示了有關檔案系統(而非檔案)的資訊: 
 
# stat -f oracle   
  File: "oracle"  
    ID: 0        Namelen:255     Type:ext2/ext3   
Blocks: Total: 24033242   Free: 15419301   Available: 14198462   Size: 4096  
Inodes: Total: 12222464   Free: 12093976     
  
另一個選項 -t 顯示了完全相同的資訊,只不過是在一行中顯示的:    
  
# stat -t oracle    
oracle 93300148 182424 8de9 500 500 343 12009652 1 0 0 1154682061    
1130950187 1130950524 4096  

Everything in Unix is treated as files. This includes devices, directories and sockets — all of these are files. Stat command displays file or filesystem status as explained in this article.

File Stat – Display Information About File

For example, to find out more information about 101hacks.txt file, execute the stat command as shown below.

$ stat 101hacks.txt  File: `/home/sathiyamoorthy/101hacks.txt'  Size: 854       Blocks: 8          IO Block: 4096   regular fileDevice: 801h/2049dInode: 1058122     Links: 1Access: (0600/-rw-------)  Uid: ( 1000/ sathiya)   Gid: ( 1000/ sathiya)Access: 2009-06-28 19:29:57.000000000 +0530Modify: 2009-06-28 19:29:57.000000000 +0530Change: 2009-06-28 19:29:57.000000000 +0530
Details of Linux Stat Command Output
  • File: `/home/sathiyamoorthy/101hacks.txt’ – Absolute path name of the file.
  • Size: 854 – File size in bytes.
  • Blocks: 8 – Total number of blocks used by this file.
  • IO Block: 4096 – IO block size for this file.
  • regular file – Indicates the file type. This indicates that this is a regular file. Following are available file types.
    • regular file. ( ex: all normal files ).
    • directory. ( ex: directories ).
    • socket. ( ex: sockets ).
    • symbolic link. ( ex: symbolic links. )
    • block special file ( ex: hard disk ).
    • character special file. ( ex: terminal device file ).
  • Device: 801h/2049d  – Device number in hex and device number in decimal
  • Inode: 1058122 – Inode number is a unique number for each file which is used for the internal maintenance by the file system.
  • Links: 1 – Number of links to the file
  • Access: (0600/-rw——-): Access specifier displayed in both octal and character format. Let us see explanation about both the format.
  • Uid: ( 1000/ sathiya) – File owner’s user id and user name are displayed.
  • Gid: ( 1000/ sathiya) – File owner’s group id and group name are displayed.
  • Access: 2009-06-28 19:29:57.000000000 +0530 – Last access time of the file.
  • Modify: 2009-06-28 19:29:57.000000000 +0530 – Last modification time of the file.
  • Change: 2009-06-28 19:29:57.000000000 +0530 – Last change time of the inode data of that file.

Dir Stat – Display Information About Directory

You can use the same command to display the information about a directory as shown below.

$ stat /home/rameshFile: `/home/ramesh'Size: 4096 Blocks: 8 IO Block: 4096 directoryDevice: 803h/2051d Inode: 5521409 Links: 7Access: (0755/drwxr-xr-x) Uid: ( 401/ramesh) Gid: ( 401/ramesh)Access: 2009-01-01 12:17:42.000000000 -0800Modify: 2009-01-01 12:07:33.000000000 -0800Change: 2009-01-09 12:07:33.000000000 -0800
Details of File Permission:
File Permission In Octal Format

This information about the file is displayed in the Access field when you execute stat command. Following are the values for read, write and execute permission in Unix.

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.