Coding How to Linux

How to find the last Modified file on Linux

How to find the last Modified file on Linux September 19, 2015Leave a comment
cara mencari file yang mengandung teks tertentu di linux, tutorial desain web

There are many method how to find the last modified files on linux. In This artcle, we will introduce find command in Linux command line Environment…

Find File and Sort by Modified date

To Find file, displaying them on the screen, and sort by Modified date, you can do trough the ls command like this:

# ls -ltr

But ls command just show directory content,not displaying another file in sub directory. To Displaying file in the entire direcory and sub directory, you should use find command like this:

find /etc -type f -printf '%TY-%Tm-%Td %TT %p\n' | sort -r 

Result: (May be diffrent in your PC):

2012-09-14 22:25:14.0000000000 /etc/shadow
2012-08-17 00:56:36.0000000000 /etc/resolv.conf
2012-08-16 23:22:57.0000000000 /etc/
2012-08-16 23:22:29.0000000000 /etc/mtab
2012-08-16 23:22:04.0000000000 /etc/network/run/ifstate
2012-07-10 01:19:24.0000000000 /etc/papersize

How to show the last 60 minute modified file

To show file that has been modified in the last 60 minutes, you can use -mmin option like this:

find /target_directory -type f -mmin -60

to show the last 3 hours modified file, you should change 60 to be 180 (3 hours = 180 minutes)

How to find that has been modified in the last 24 hours?

To do This, use -mtime option followed by n parameter like this:

find /target_directory -type f -mtime -n 

For the example, you need to find file that has been modified in the last 5 Days:

find /target_directory -type f -mtime -5 

to find just the last modified file in 5 and 4 days without displaying modified file in 3 days, use this command:

find /target_directory -type f -mtime -5 ! -mtime -3

Leave a Reply

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