In this tutorial we will learn about linux command to find last modified and access date of a file/dir and filesystem.The command is very useful for troubleshooting purpose.

Here we will use the stat command which display file or file system status.

To find the last modified and access date of a file/dir/filesystem in linux,we use the command called stat.The command will show you many information but we are looking for the three value called Access,modify and change.

To get the status of file or directory

To get the status of file/dir use the given below syntax

stat /path/of/file-dir

Below given is the example from my system

[root@nymachine ~]# ls -ld test
drwxr-xr-x 3 root root 4096 Sep 29 07:18 test
[root@mymachine ~]# 
[root@mymachine ~]# stat test
  File: `test'
  Size: 4096      	Blocks: 8          IO Block: 4096   directory
Device: fd00h/64768d	Inode: 1048642     Links: 3
Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2013-12-29 17:08:18.560003308 +0000
Modify: 2013-09-29 07:18:55.564999916 +0000
Change: 2013-09-29 07:18:55.564999916 +0000
[root@mysites ~]# 

To find the modified and access date of a filesystem

For getting status of filesystem, use the given below syntax

stat /path/filesystem/

for eg.

[root@CentOS-Server ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/vda               20G  5.6G   14G  30% /
none                  246M     0  246M   0% /dev/shm
[root@CentOS-Server ~]# 
[root@CentOS-Server ~]# stat /dev/vda 
  File: `/dev/vda'
  Size: 0         	Blocks: 0          IO Block: 4096   block special file
Device: 5h/5d	Inode: 5685        Links: 1     Device type: fd,0
Access: (0660/brw-rw----)  Uid: (    0/    root)   Gid: (    6/    disk)
Access: 2013-11-25 05:53:15.763999928 +0000
Modify: 2013-11-25 05:53:15.761999928 +0000
Change: 2013-11-25 05:53:15.761999928 +0000
[root@CentOS-Server ~]# 

note: If you use -f option for file system,it will only show details of filesystem but modified/access date will not be shown.
In below output, you will get other useful information about blocks,inode,ID etc. information

For eg.

[root@CentOS-Server ~]# stat -f /dev/vda 
  File: "/dev/vda"
    ID: 0        Namelen: 255     Type: tmpfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 60872      Free: 60836      Available: 60836
Inodes: Total: 60872      Free: 60330
[root@CentOS-Server ~]# 

To know about more option,check the man page and help section

man stat
stat --help

Read Some More Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.