Skip to content

By Administrator in All, Linux administration

When working on the command line in Linux or Unix, it could be very useful to be able to search for files that have been last modified on a specific date.

Strangely enough, the almighty find command does not offer a single option that would allow you to find all files modified on let’s say May 31, 2011. Of course, you could use the -mtime option but it would require you to calculate the exact number of days that have passed since the target date, which is not always a straight-forward task.

The better solution would be to use the -newer option which makes find look for files by comparing their modification dates to these of specific supplied files. For that purpose, you would also need to create two files with modification dates set per the needs of the specific search.

To find all files that were last modified on May 31, 2011, the following set of commands could be used:

[email protected]:~$ touch -t 201105310000 begin.tmp
[email protected]:~$ touch -t 201106010000 end.tmp
[email protected]:~$ find ./ -newer begin.tmp ! -newer end.tmp -print

The above lines create two help files and instruct find to locate all files whose modification timestamps are between those of the help files.

Tags: , , ,

Comment Feed

No Responses (yet)



Some HTML is OK

or, reply to this post via trackback.