Somtimes it is required to find out some more details about filsystem objects than provided by well-known tools like ‘ls’ or ‘mc’. Yes, if you are familiar with the feature set of scripting languages, you will be able to write two or three lines of code and voilá, you will receive the desired result.
This article will show you how to utilize standard command line tools to fetch details about files, directories, links and other filesystem objects.
The tool ‘ls’ provides a bunch of command line options. The long listing format should be commonly know. It will be utilized when you do add the parameter ‘-l’ at command line. But ‘ls’ can provide some more details. When you are interested in more details regarding the time of a file you should take a look at the parameter ‘–time-style’.
# the standard long listing format$ ls tmp/fierce/ -ltotal 40-rw-r--r-- 1 mario users 19610 2008-12-13 00:24 fierce.pl-rw-r--r-- 1 mario users 11937 2008-07-28 00:01 hosts.txt-rw-r--r-- 1 mario users 350 2009-10-26 16:23 h.txt-rw-r--r-- 1 mario users 73 2009-10-26 15:39 install.perl-mods.txt # ...the long listing fomrat with more deatiled informtion# (utilize one of the following additional parameters)$ ls tmp/fierce/ -l --time-style=full-iso$ ls tmp/fierce/ -l --full-time-rw-r--r-- 1 mario users 19610 2008-12-13 00:24:17.000000000 +0100 fierce.pl-rw-r--r-- 1 mario users 11937 2008-07-28 00:01:42.000000000 +0200 hosts.txt-rw-r--r-- 1 mario users 350 2009-10-26 16:23:47.000000000 +0100 h.txt-rw-r--r-- 1 mario users 73 2009-10-26 15:39:17.000000000 +0100 install.perl-mods.txt
Sometimes it is required to take a deeper look into file system contents and ‘ls’ might not be sufficient for this task. There is another command tool available that prints out a lot of detailed information regarding single file system objects. Here is an basic example when executing ‘stat’ to examine a simple file.
$ stat out File: `out' Size: 658 Blocks: 8 IO Block: 4096 regular fileDevice: 902h/2306d Inode: 19636232 Links: 2Access: (0644/-rw-r--r--) Uid: ( 1000/ mario) Gid: ( 100/ users)Access: 2010-09-03 19:53:56.000000000 +0200Modify: 2010-09-03 19:51:37.000000000 +0200Change: 2011-02-11 15:52:41.000000000 +0100
As you can see there is provided a lot of information regarding the referenced file. Additionally to the outputs of ‘ls’ you get:
The following output contains details regarding a file (qemu), a directory (out) and some links to these objects.
$ stat qemu qemu-link out out-slink out-hlink File: `qemu' Size: 4096 Blocks: 8 IO Block: 4096 directoryDevice: 902h/2306d Inode: 43884545 Links: 2Access: (0755/drwxr-xr-x) Uid: ( 1000/ mario) Gid: ( 100/ users)Access: 2011-02-11 05:30:05.000000000 +0100Modify: 2010-10-20 14:29:19.000000000 +0200Change: 2010-10-20 14:29:19.000000000 +0200 File: `qemu-link' -> `qemu' Size: 4 Blocks: 0 IO Block: 4096 symbolic linkDevice: 902h/2306d Inode: 43311144 Links: 1Access: (0777/lrwxrwxrwx) Uid: ( 1000/ mario) Gid: ( 100/ users)Access: 2011-02-11 15:52:16.000000000 +0100Modify: 2011-02-11 15:52:16.000000000 +0100Change: 2011-02-11 15:52:16.000000000 +0100 File: `out' Size: 658 Blocks: 8 IO Block: 4096 regular fileDevice: 902h/2306d Inode: 19636232 Links: 2Access: (0644/-rw-r--r--) Uid: ( 1000/ mario) Gid: ( 100/ users)Access: 2010-09-03 19:53:56.000000000 +0200Modify: 2010-09-03 19:51:37.000000000 +0200Change: 2011-02-11 15:52:41.000000000 +0100 File: `out-slink' -> `out' Size: 3 Blocks: 0 IO Block: 4096 symbolic linkDevice: 902h/2306d Inode: 43311147 Links: 1Access: (0777/lrwxrwxrwx) Uid: ( 1000/ mario) Gid: ( 100/ users)Access: 2011-02-11 15:52:35.000000000 +0100Modify: 2011-02-11 15:52:35.000000000 +0100Change: 2011-02-11 15:52:35.000000000 +0100 File: `out-hlink' Size: 658 Blocks: 8 IO Block: 4096 regular fileDevice: 902h/2306d Inode: 19636232 Links: 2Access: (0644/-rw-r--r--) Uid: ( 1000/ mario) Gid: ( 100/ users)Access: 2010-09-03 19:53:56.000000000 +0200Modify: 2010-09-03 19:51:37.000000000 +0200Change: 2011-02-11 15:52:41.000000000 +0100
For customizing outputs and to get an overview of available command line parameters you should take a look into the man pages for ‘ls’ and ‘stat’.
Please note, that a sub-second resolution for timestamds is dependant on the utilized file system type and on the applied configuration parameters.