The UNIX stat command is a utility which allows us to search a file or directories inode information to retrieve certain attributes about that file or directory. The command comes with an option '-f' or '--format=[value]' where you define format specifiers for viewing inode file properties.
By default when running the stat utility against a file or directory it will output a lot of information about the file.
sam@asus:~/unix% stat file.txt File: 'file.txt' Size: 17 Blocks: 8 IO Block: 4096 regular file Device: b301h/45825d Inode: 788042 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1000/ sam) Gid: ( 1000/ sam) Access: 2019-04-03 15:50:49.286143171 -0600 Modify: 2019-04-03 15:51:07.000699885 -0600 Change: 2019-04-03 15:51:07.000699885 -0600 Birth: - sam@asus:~/unix%
General File Properties
File type
To view a files file type you would use the '%F' format.
sam@asus:~/unix% stat --format=%F file.txt regular file sam@asus:~/unix%
Total Size (bytes)
To view a files size you would use the '%s' format.
sam@asus:~/unix% stat --format=%s file.txt 17 sam@asus:~/unix%
File name
To view the filename of a file you would use the '%n' format.
sam@asus:~/unix% stat --format=%n file.txt file.txt sam@asus:~/unix%
Inode number
To view a files inode number you would use the '%i" format.
sam@asus:~/unix% stat --format=%i file.txt 788042 sam@asus:~/unix%
Mount point
To view the mount point of a file you would use the '%m' format
sam@asus:~/unix% stat --format=%m file.txt / sam@asus:~/unix%
User and Group information
User ID
To view the first User ID use the '%u' format
sam@asus:~/unix% stat --format=%u file.txt 1000 sam@asus:~/unix%
Username
To view the files owner username use the '%U' format
sam@asus:~/unix% stat --format=%U file.txt sam sam@asus:~/unix%
Group ID
To view the Group ID of the file use the '%g' format
sam@asus:~/unix% stat --format=%g file.txt 1000 sam@asus:~/unix%
Group Name
To view the files Group Name use the '%G' format
sam@asus:~/unix% stat --format=%G file.txt sam sam@asus:~/unix%
File access and creation
Octal Permissons
To view a files permissons in Octal notation use the '%a' format
sam@asus:~/unix% stat --format=%a file.txt 664 sam@asus:~/unix%
Symbolic Permissons
To view a files permissons in Symbolic notation use the '%A' format
sam@asus:~/unix% stat --format=%A file.txt -rw-rw-r-- sam@asus:~/unix%
Creation Time
To view a files Creation time use the '%w' format. here the '-' means unknown.
sam@asus:~/unix% stat --format=%w file.txt - sam@asus:~/unix%
Last Access Time
To view a files Last Access time use the '%x' format
sam@asus:~/unix% stat --format=%x file.txt 2019-04-03 15:50:49.286143171 -0600 sam@asus:~/unix%
Modified Time
To view a files Last Modified time use the '%y' format
sam@asus:~/unix% stat --format=%y file.txt 2019-04-03 15:51:07.000699885 -0600 sam@asus:~/unix%
Last Status Change
To view a files Last Status Change use the '%z' format
sam@asus:~/unix% stat --format=%z file.txt 2019-04-03 15:51:07.000699885 -0600 sam@asus:~/unix%
No comments:
Post a Comment