Detailed explanation of linux command state

The state command of the linux command summary

The ls command and its many parameters provide some very useful file information. Another lesser-known command, stat , provides some more useful information.

 man stat

The following demonstrates the information displayed by stat without arguments:

1

2

3

4

5

6

7

8

[root@Gin scripts]# stat date.txt

  File: `date.txt'

  Size: 40              Blocks: 8          IO Block: 4096   regular file

Device: 803h/2051d      Inode: 261790      Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2017-01-29 10:49:25.119790781 +0800

Modify: 2017-01-29 10:49:11.961790098 +0800

Change: 2017-01-29 10:49:11.961790098 +0800

Note the information you get with this command: in addition to the usual file size (which can also be obtained with the ls -l command), you also get the number of blocks the file occupies. The usual Linux block size is 512 bytes, so a file of size 93,300,148 bytes will occupy (93300148/512 =) 182226.85 blocks. Since the blocks are fully occupied, the file uses some integer number of blocks. Get the exact number of blocks without guessing.

You can also get the GID and UID   of file ownership , and the octal representation of permissions (6751) from the above output . If you want to restore the file to the same permissions it has now, you can use chmod 6751oracle instead of spelling out the permissions explicitly.

  The most useful part of the above output is the file access timestamp information. The output shows that the file was accessed at 2006-08-0404:30:52 (displayed next to "Access:" ), which is 4:30:52 AM on August 4 , 2006 . This is when someone starts using the database. The file was modified at 2005-11-02 11:49:47 (displayed next to "Modify:" ). Finally, the timestamp next to "Change:" shows when the file status changed.

The modifier -f of the stat command shows information about the filesystem (not the file):

1

2

3

4

5

6

[root@Gin scripts]# stat -f date.txt

  File: "date.txt"

    ID: ff0d2532e41897c0 Namelen: 255     Type: ext2/ext3

Block size: 4096       Fundamental block size: 4096

Blocks: Total: 1851748    Free: 1286127    Available: 1190396

Inodes: Total: 479552     Free: 409340

The other option -t shows the exact same information, just on one line:

1

2

[root@Gin scripts]# stat -t date.txt

date.txt 40 8 81a4 0 0 803 261790 1 0 0 1485658165 1485658151 1485658151 4096

This is useful for shell scripts, where a simple cut command can be used to get the value for further processing.

Applications:

How to obtain the digital content corresponding to the permissions of the file after the stat /poe command, such as -rw-r--r-- is 644 , it is required to use the command to obtain a number such as 644 or 0644 .

 

1

2

3

4

5

6

7

8

9

10

[root@Gin scripts]# stat date.txt

  File: `date.txt'

  Size: 40              Blocks: 8          IO Block: 4096   regular file

Device: 803h/2051d      Inode: 261790      Links: 1

Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)

Access: 2017-01-29 10:49:25.119790781 +0800

Modify: 2017-01-29 10:49:11.961790098 +0800

Change: 2017-01-29 10:49:11.961790098 +0800

[root@Gin scripts]# stat -c %a date.txt

644

 引用:http://www.cnblogs.com/ginvip/p/6539393.html
细节影响成败,感谢 琴酒网络 的总结整理。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325405963&siteId=291194637