I do not remember where I saved pdf and text files under Linux. I have downloaded files from the Internet a few months ago. How do I find my pdf or text files?
You need to use the 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
-daystart option
The -daystart option is used to measure time from the beginning of the current day instead of 24 hours ago. Find out all perl (*.pl) file modified yesterday, enter:
find /nas/projects/mgmt/scripts/perl -mtime 1 -daystart -iname "*.pl"
You can also list perl files that were modified 8-10 days ago, enter:
To list all of the files in your home directory tree that were modified from two to four days ago, type:
find /nas/projects/mgmt/scripts/perl -mtime 8 -mtime -10 -daystart -iname "*.pl"
-newer option
To find files in the /nas/images directory tree that are newer than the file /tmp/foo file, enter:
find /etc -newer /tmp/fooYou can use the touch command to set date timestamp you would like to search for, and then use -newer option as follows
touch --date "2010-01-05" /tmp/foo # Find files newer than 2010/Jan/05, in /data/images find /data/images -newer /tmp/foo
Read the man page of find command for more information:
man find
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 25 comments… read them below or add one }
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
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
Please use the following command :
mkdir Red
cd Red
Red/>mkdir Hat
cd Hat
Red/Hat>
Please let me know if this is clear
Thanks,
Prashanthini
r
mkdir Red
cd Red
touch Hat
mkdir -p Red/Hat
@sowya: to create a file ./Red/Hat when the directory “Red” doesn’t exist yet, use mkdir and touch:
mkdir Red
touch Red/Hat
Thx for the find examples ! they were very helpfull
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
works nicely, and the mem usage wasn’t bad at all, need eclipse and birt though because of
In aix 5.3 put -name instead -iname
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?
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?
find / -name “*.mp3″ -atime +01 -type f
use this command , it will surely work
@Mike – Replace ” by ‘ and try.
I’ve got this in my delicious bookmarks and use it often, thank you. For some reason on one of my computers I have to leave the word -print off the command or I get a message about paths must precede expression. Still…thank you for the page.
If you need a specific date range many days ago, it would be boring to calculate how many days ago it was exactly. Here is an example looking for files modified between May 9 2008 and May 13 2008, in /home:
touch –date “2008-05-09″ /tmp/after
touch –date “2008-05-13″ /tmp/before
find /home/ -type f -newer /tmp/after -not -newer /tmp/before
very helpful…:) thank you
good one
-rw-rw-rw- 1 qmaster qmaster 294520 Aug 16 00:35 HSTD.191.807
-rw-rw-rw- 1 qmaster qmaster 525118 Aug 17 00:56 HSTD.191.808
-rw-rw-rw- 1 qmaster qmaster 698575 Aug 18 01:42 HSTD.191.809
-rw-rw-rw- 1 qmaster qmaster 829239 Aug 19 01:25 HSTD.191.810
I would like to copy to a directory one of the following files by using today’s date minus one. In other words when I execute my script I want yesterdays file.
any help would be appreciated.
John
This should do the trick -
find . -type f -iname ‘HSTD*’ -daystart -mtime 1 -exec cp {} /path/to new/dir/ \;
Nick
Hi,
How do I list the files of only today’s date and dump them into some output file?
I have a new Linux server. CentOS 5.5. I want to know if their is any way to see exactly what files are added or changed or updated after I install a program. How can I do this?
i want find the files created or modified in particular date
plz tell me command for following :-
find all the files in current folder with modification time (modified in last 6 hrs and not modified in last 4hrs) with their name starting with k and they must be regular files and not directories finally delete them..
How do i find a file based on the date input i give and move that file, a file with date before that and after that to a directory using find.
For Example: I want to find a file “identity_*” last modified on 17th Aug moved to a directory along with one modified on 18th Aug, 19th Aug.
Any inputs are highly appreciated
If a file is moved to trash bin, is its ctime modified ?