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] exchange the status (modify the file or its attributes) – ctime
[c] modify (exchange the file’s contents) – mtime
You can search for files whose time stamps are within a certain age range, or equate them to other time stamps.
You can use -mtime option. It income 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
Show make pleased of file on screen that were last modified 60 days ago, use
$ find /home/you -iname "*.txt" -mtime -60 -exec cat {} \;
Count whole number of files by 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 commencement of now 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 commencement of the current day instead of 24 hours ago. Find out all perl (*.pl) file modified yesterday, enter:
<span style="color: rgb(194, 12, 185); font-weight: bold;">find</span> /nas/projects/mgmt/scripts/<span style="color: rgb(194, 12, 185); font-weight: bold;">perl</span> -mtime <span style="color: rgb(0, 0, 0);">1</span> -daystart -iname <span style="color: rgb(255, 0, 0);">"*.pl"</span>
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:
<span style="color: rgb(194, 12, 185); font-weight: bold;">find</span> /nas/projects/mgmt/scripts/<span style="color: rgb(194, 12, 185); font-weight: bold;">perl</span> -mtime <span style="color: rgb(0, 0, 0);">8</span> -mtime <span style="color: rgb(0, 0, 0);">-10</span> -daystart -iname <span style="color: rgb(255, 0, 0);">"*.pl"</span>
-newer option
To find files in the /nas/images directory tree that are newer than the file /tmp/foo file, enter:
<span style="color: rgb(194, 12, 185); font-weight: bold;">find</span> /etc -newer /tmp/foo
You can use the touch command to set date timestamp you want to search for, and then use -newer option as follows
<span style="color: rgb(194, 12, 185); font-weight: bold;">touch</span> --<span style="color: rgb(194, 12, 185); font-weight: bold;">date</span> <span style="color: rgb(255, 0, 0);">"2010-01-05"</span> /tmp/foo<br /><span style="color: rgb(128, 128, 128); font-style: italic;"># Find files newer than <span style="color: rgb(0, 0, 0);">2010</span>/Jan/<span style="color: rgb(0, 0, 0);">05</span>, <span style="color: rgb(0, 0, 0); font-weight: bold;">in</span> /data/images</span><br /><span style="color: rgb(194, 12, 185); font-weight: bold;">find</span> /data/images -newer /tmp/foo<br />Â
Read the man page of find command for more information:
man find
REFERENCES
http://www.cyberciti.biz/faq/howto-result-files-by-date/
Answers Rating