|
Tired of the ls command and want to see more of your document about interesting information? Try stat!
ls command may be one of the first user for each Unix command to learn, but it only shows a small portion of the information can give stat command.
stat command to obtain information from the inode file. As you probably already know, every file system there are three sets of dates and times, they include (date and time that is displayed when using the ls -l command) last modification time, last status change time (including file rename) and last access time.
Use a long list mode view the file information, you'll see something like the following:
$ Ls -l trythis
-rwx ------ 1 shs unixdweebs 109Nov112013 trythis
Using the stat command, you will see the following:
$ Stat trythis
File: `trythis'
Size: 109 Blocks: 8 IO Block: 262144 regular file
Device: 18h / 24d Inode: 12731691 Links: 1
Access: (0700 / -rwx ------) Uid: (263 / shs) Gid: (100 / unixdweebs)
Access: 2014-09-09 19: 27: 58.000000000 -0400
Modify: 2013-11-11 08: 40: 10.000000000 -0500
Change: 2013-11-11 08: 40: 10.000000000 -0500
In the above case, the status of files and change file modification date / time are the same, but the access time is quite recent times. We can also see that the file using eight blocks, and file permissions are displayed in two formats - octal (0700) format and rwx format. Inode in the third line of the display is 12731681. file no other hard links (Links: 1). Moreover, this file is a regular file.
Rename the file, you'll see the status change time changes.
Here ctime information, the first designed to create a storage file (create) the date and time, but then I do not know when to become used to store the state to modify (change) the time.
$ Mv trythis trythat
$ Stat trythat
File: `trythat '
Size: 109 Blocks: 8 IO Block: 262144 regular file
Device: 18h / 24d Inode: 12731691 Links: 1
Access: (0700 / -rwx ------) Uid: (263 / shs) Gid: (100 / unixdweebs)
Access: 2014-09-09 19: 27: 58.000000000 -0400
Modify: 2013-11-11 08: 40: 10.000000000 -0500
Change: 2014-09-21 12: 46: 22.000000000 -0400
Change file permissions will change ctime field.
You can also use wildcards with the stat command to list the status of a group of files:
$ Stat myfile *
File: `myfile '
Size: 20 Blocks: 8 IO Block: 262144 regular file
Device: 18h / 24d Inode: 12731803 Links: 1
Access: (0640 / -rw-r -----) Uid: (263 / shs) Gid: (100 / unixdweebs)
Access: 2014-08-23 03: 00: 36.000000000 -0400
Modify: 2014-08-22 12: 02: 12.000000000 -0400
Change: 2014-08-22 12: 02: 12.000000000 -0400
File: `myfile2 '
Size: 20 Blocks: 8 IO Block: 262144 regular file
Device: 18h / 24d Inode: 12731806 Links: 1
Access: (0640 / -rw-r -----) Uid: (263 / shs) Gid: (100 / unixdweebs)
Access: 2014-08-23 03: 00: 36.000000000 -0400
Modify: 2014-08-22 12: 03: 30.000000000 -0400
Change: 2014-08-22 12: 03: 30.000000000 -0400
File: `myfile3 '
Size: 40Blocks: 8 IO Block: 262144 regular file
Device: 18h / 24dInode: 12730533Links: 1
Access: (0640 / -rw-r -----) Uid: (263 / shs) Gid: (100 / unixdweebs)
Access: 2014-08-2303: 00: 36.000000000-0400
Modify: 2014-08-2212: 03: 59.000000000-0400
Change: 2014-08-2212: 03: 59.000000000-0400
If we like it, we can also obtain this information by other commands.
Add "u" option to ls -l command, you will see the results below. Note that this option will show the last access time, and added "c" option will display the status change time (in this case, is the time we rename the file).
$ Ls -lu trythat
-rwx ------ 1 shs unixdweebs 109Sep919: 27 trythat
$ Ls -lc trythat
-rwx ------ 1 shs unixdweebs 109Sep2112: 46 trythat
stat command can also be used with folders.
In this example, we can see that there are many links.
$ Stat bin
File: `bin '
Size: 12288 Blocks: 24 IO Block: 262144 directory
Device: 18h / 24d Inode: 15089714 Links: 9
Access: (0700 / drwx ------) Uid: (263 / shs) Gid: (100 / unixdweebs)
Access: 2014-09-21 03: 00: 45.000000000 -0400
Modify: 2014-09-15 17: 54: 41.000000000 -0400
Change: 2014-09-15 17: 54: 41.000000000 -0400
Here, we can also view a file system.
$ Stat -f / dev / cciss / c0d0p2
File: "/ dev / cciss / c0d0p2"
ID: 0Namelen: 255Type: tmpfs
Block size: 4096Fundamental block size: 4096
Blocks: Total: 259366Free: 259337Available: 259337
Inodes: Total: 223834Free: 223531
Note Namelen (file name length) field, if the file name is longer than 255 characters, you'll be lucky to see the heart symbol in the file name of the place!
stat command also lets you display all the information we want. The following example, we want to see the file type, then the number of hard links.
$ Stat --format =% F trythat
regular file
$ Stat --format =% h trythat
1
In the following example, we look at the file permissions - are available in two formats - then the SELinux security context of the file. Finally, we can format in seconds from Epoch began to view the file access time.
$ Stat --format =% a trythat
700
$ Stat --format =% A trythat
-rwx ------
$ Stat --format =% C trythat
(Null)
$ Stat --format =% X bin
1411282845
Here are all the options available:
% A octal representation of access
Access to readable format of% A
Block number (see% B)% b Distribution
Number of bytes per block% B% b parameter display
% D Device number in decimal notation
% D device number in hexadecimal representation
% F Raw mode hexadecimal representation
% F File Types
% G Group ID of owner
% G Group name of owner
% H Number of hard links
% I Inode number
% N filename
% N if it is a symbolic link, display the linked file name
% O I / O block size
% S byte size of all occupied
Master hexadecimal number% t
Deputy device number% T hexadecimal
% U owner user ID
% U user name owner
% X last access time
% X last access time, the number of seconds since the beginning of the Epoch
% Y last modified
% Y last modified time, the number of seconds since the beginning of the Epoch
% Z Time Last Change
Last Change% Z time, the number of seconds since the beginning of the Epoch
For the file system as well as the following format options:
% A number of blocks available to ordinary users
All data blocks% b file system
All file nodes in file system% c
Available file nodes% d file system
Available nodes% f file system
% C SELinux security context of
% I the hexadecimal representation of the file system ID
The maximum length of the filename% l
Filenames% n File System
% S Block size (for faster transfer)
% S basic block size (for block count)
% T the hexadecimal representation of the type of file system
Filesystem% T-readable format type
This information can be obtained, stat command may be able to help you in a slightly different perspective to understand your document. |
|
|
|