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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux