Find files by access, modification date under Linux or UNIX

by Vivek Gite · 7 comments

Q. I don't remember where I saved pdf and text files under Linux. I have downloaded files from internet a few months ago. How do I find my pdf files?

A. You need to use find command. Each file has three time stamps, which record the last time that certain operations were performed on the file:
[a] access (read the file's contents) - atime

[b] change the status (modify the file or its attributes) - ctime

[c] modify (change the file's contents) - mtime

You can search for files whose time stamps are within a certain age range, or compare them to other time stamps.

You can use -mtime option. It returns list of file if the file was last accessed N*24 hours ago. For example to find file in last 2 months (60 days) you need to use -mtime +60 option.

  • -mtime +60 means you are looking for a file modified 60 days ago.
  • -mtime -60 means less than 60 days.
  • -mtime 60 If you skip + or - it means exactly 60 days.

So to find text files that were last modified 60 days ago, use
$ find /home/you -iname "*.txt" -mtime -60 -print

Display content of file on screen that were last modified 60 days ago, use
$ find /home/you -iname "*.txt" -mtime -60 -exec cat {} \;

Count total number of files using wc command
$ find /home/you -iname "*.txt" -mtime -60 | wc -l

You can also use access time to find out pdf files. Following command will print the list of all pdf file that were accessed in last 60 days:
$ find /home/you -iname "*.pdf" -atime -60 -type -f

List all mp3s that were accessed exactly 10 days ago:
$ find /home/you -iname "*.mp3" -atime 10 -type -f

There is also an option called -daystart. It measure times from the beginning of today rather than from 24 hours ago. So, to list the all mp3s in your home directory that were accessed yesterday, type the command
$ find /home/you -iname "*.mp3" -daystart -type f -mtime 1

Where,

  • -type f - Only search for files and not directories

Read man page of find command for more information.

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 7 comments… read them below or add one }

1 Alankar 01.29.09 at 5:30 pm

Suppose I want to remove a set of file frm date say 1st Jan 2009 – 20 Jan 2009 in a specific Directory.
Let me know

2 sowmya 04.29.09 at 10:59 am

How to create a directory called Red and under that Red directory i want to create a file called Hat. How please guide me as soon as possible

3 webdesign 06.26.09 at 8:21 am

Thx for the find examples ! they were very helpfull

4 dkalaluhi 07.24.09 at 1:08 pm

Find examples were great…needed to use this to get a report on a shared drive…getting the output was a bit of a pain, until the resident guru came through:

Finds files older than 18months and newer than 24 months, cat’s the output to a CSV in the format:
/some/path/somewhere, size in bytes, Access Time, Modified Time

find /dir/dir -type f -mtime +540 -mtime -720 -printf \”%p\”,\”%s\”,\”%AD\”,|”%TD\”\\n > /dir/dir/output.csv

works nicely, and the mem usage wasn’t bad at all, need eclipse and birt though because of

5 Matabares 10.05.09 at 2:50 pm

In aix 5.3 put -name instead -iname

6 Masonite2009 10.14.09 at 10:50 pm

I would like to display the date modified, the owner of the file, and the file size of the files that I have found using the find command. Is there a way to do that?

7 mike 10.16.09 at 10:02 am

the commands in the examples are not working for me, im trying to get the times a particular word file has been accessed on my computer in the last week so i tried to use the -atime example to see if it was accessed one day ago, i typed this into terminal:

find /home/you -iname “*.mp3″ -atime 01 -type -f

it didnt work, can anyone help me?

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All