[OT]: Ho wto find files created on a specific date

Craig White craigwhite at azapple.com
Wed Apr 2 14:40:53 UTC 2008


On Wed, 2008-04-02 at 15:05 +0100, Dan Track wrote:
> Hi
> 
> I need to delete files in my /opt/html/ directory that were
> created/modified ON the 20th of March this year? Is there a way for me
> to do this?
----
first - make a backup of the entire directory because this type of thing
is destructive and there is no 'undo' option

Then you should probably be aware of the man page for find which has
some examples that does things similar to this but you will want to test
the 'find' command before you add the part to 'rm'

The next problem is that the 'created' time isn't retained but the
modified time is...

find /opt/html -mtime +12

sounds about right to me...this should give you all files modified since
March 20th...

then you could output this to file...
find /opt/html -mtime +12 > /tmp/modified-since-march-20.txt
then if you wanted to exclude stuff modified since march-21st (so as not
to delete them)
find /opt/html -mtime +11 > /tmp/modified-since-march-21.txt

then you could 'diff' the difference to get a file list of those for
March 12th

Here's an example...
# find . -ctime +5 > /tmp/files1.txt
# find . -ctime +1 > /tmp/files2.txt
# diff /tmp/files1.txt /tmp/files2.txt

and then to clean up the diff, I add some other things...
# diff /tmp/files1.txt /tmp/files2.txt |grep '/' | sed 's/> //g'

and if I output this to a file, I could use that for deleting
purposes...

# diff /tmp/files1.txt /tmp/files2.txt |grep '/' | sed 's/> //g' \
> /tmp/file-deletion-list.txt

and finally, my command to delete...

for file in `cat /tmp/file-deletion-list.txt`; do rm $file; done
# note, those are backticks and not single quotes

Mostly though, adjust as you go along and test this as your mileage will
definitely vary.

Craig




More information about the fedora-list mailing list