Monday, June 11, 2012

Find file by arbitrary date in Linux

To find all files that are newer than an arbitrary date you can use the example below. To make this work, we have to use a little trick. First we create an empty file with last modified date that matches the date we are interested in using in our search. We write it to our user directory since we should have write permissions to it in most cases. Next we use the find command to find all files (starting in the current directory) newer than the file we created. When we are done, all we have to do is delete the file we created (or leave it if you want to use it later). It seems more difficult that it should be, but it does appear to work.

touch -d "06/11/12 13:37" ~/date_marker

find . –newer ~/date_marker

rm ~/date_marker

No comments: