Showing posts with label Find file based on access/modification time. Show all posts
Showing posts with label Find file based on access/modification time. Show all posts

Sunday, 20 December 2015

Find file based on access/modification time


We can find files based on following three file time attribute.

Access time of the file: Access time gets updated when the file accessed.
Modification time of the file: Modification time gets updated when the file content modified.
Change time of the file: Change time gets updated when the inode data changes

###Find files whose content got updated within last 1 hour###

[root@stelar_test oracle]# find /home/oracle -mmin -60
/home/oracle
/home/oracle/SaidRasel.c
[root@stelar_test oracle]#

-mmin n File’s data was last modified n minutes ago.
-mtime n File’s data was last modified n*24 hours ago.

[root@stelar_test oracle]# find /home/oracle -mtime -1
/home/oracle
/home/oracle/SaidRasel.c
[root@stelar_test oracle]#

###Find files which got accessed before 1 hour###

-amin n File was last accessed n minutes ago-atime n File was last accessed n*24 hours ago

Finds all the files (under /home/oracle) that got accessed within the last 24 hours (1 day).

[root@stelar_test oracle]# find /home/oracle -atime -1
/home/oracle/.ssh
/home/oracle/.oracle
/home/oracle/.oracle/logs
/home/oracle/.local
/home/oracle/.local/share
/home/oracle/.local/share/applications
/home/oracle/.local/share/gvfs-metadata
/home/oracle/.thumbnails
/home/oracle/.thumbnails/normal
/home/oracle/Downloads
/home/oracle/.gvfs
/home/oracle/.spice-vdagent
/home/oracle/.bash_profile
/home/oracle/.cache
/home/oracle/Templates
/home/oracle/tomcat jdk
/home/oracle/.dbus
/home/oracle/.dbus/session-bus

Finds all the files (under /root/test/backup) that got accessed within the last 24 hours (1 day).


[root@stelar_test oracle]# find /root/test/backup/ -atime -1
/root/test/backup/
/root/test/backup/Program.c
/root/test/backup/mycprogram.c
/root/test/backup/MyCProgram.c
/root/test/backup/saidrasel.c
/root/test/backup/MybashProgram.sh
[root@stelar_test oracle]#

Find files in the current directory and sub-directories, which got accessed within last 1 hour (60 minutes)

[root@stelar_test oracle]#  find -amin -60
.
./SaidRasel.c
./.bash_history
[root@stelar_test oracle]#

Find files in the current directory and sub-directories, which got accessed within last 1 hour (60 minutes)

[root@stelar_test oracle]#  find /home/oracle/ -amin -60
/home/oracle/
/home/oracle/SaidRasel.c
/home/oracle/.bash_history
[root@stelar_test oracle]#
-amin n File was last accessed n minutes ago
-atime n File was last accessed n*24 hours ago

###Find files which got changed before 1 hour###

-cmin n File’s status was last changed n minutes ago.
-ctime n File’s status was last changed n*24 hours ago.

find files in the current directory and sub-directories, which changed within last 1 hour (60 minutes)

[root@stelar_test oracle]#  find /home/oracle/ -cmin -60
/home/oracle/
/home/oracle/SaidRasel.c
/home/oracle/.bash_history
[root@stelar_test oracle]#  find . -cmin -60
.
./SaidRasel.c
./.bash_history
[root@stelar_test oracle]#

finds all the files (under /root/test/backup/) that got changed within the last 24 hours (1 day).

[root@stelar_test oracle]# find /root/test/backup/ -ctime -1
/root/test/backup/
/root/test/backup/Program.c
/root/test/backup/mycprogram.c
/root/test/backup/MyCProgram.c
/root/test/backup/saidrasel.c
/root/test/backup/MybashProgram.sh
[root@stelar_test oracle]#



Reference :
http://www.thegeekstuff.com/2009/06/15-practical-unix-linux-find-command-examples-part-2/