Register
It is currently Fri Aug 01, 2014 4:28 pm

Erase files by date


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Mon Dec 08, 2008 3:14 pm   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
Hi guys..

How do you list files that were created on a certain date.. and then erase them.. or do something with them?


Top
 Profile  
 PostPosted: Tue Dec 09, 2008 2:23 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Hi, I've had this question asked me several times.

There is no direct way of doing it. But there is a way using touch and find :)

Code:
touch -t 200812080000 /tmp/ref1
touch -t 200812090000 /tmp/ref2
find /path/to/search -newer /tmp/ref1 -a ! -newer /tmp/ref2 -iname "search-string" -exec rm {} \;


This will search for files that are newer then 2008-12-08 00:00 but is older then 2008-12-09 00:00 and then execute rm with every itteration (you can ofcourse change this). One important thing is the \; at the end. This will make sure that find understands that it's not supposed to recieve any more commands to execute.

Also you can change this however you want :)

Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Tue Dec 09, 2008 7:20 am   

Joined: Wed Nov 26, 2008 7:43 pm
Posts: 50
Location: Texas
Thank you!! That worked like a charm


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP