Register
It is currently Tue Sep 30, 2014 5:58 pm

delete files older than 30 days script - not working (WHY)


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Tue Jun 05, 2007 9:40 am   

Joined: Wed May 09, 2007 4:07 pm
Posts: 6
OK so heres my script it supposed to delete any files in the directory that are older than 30 days...

I did get it working now its broken -lol


Code:
#!/bin/bash
##
## Only edit the next 2 lines.
#
DIR="/TEST"
DAYSOLD="30"
#
if [ -d $DIR ];then
find "$DIR" -maxdepth 0 -mtime +$DAYSOLD -delete
else
echo "$DIR does not exist or is not a directory."
fi


Top
 Profile  
 PostPosted: Tue Jun 12, 2007 7:49 am   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
it would be best to describe what you mean by "broken". was there an error? if so, what was it? if you can paste the exact error, that would get best results.


Top
 Profile  
 PostPosted: Wed Apr 01, 2009 5:40 am   

Joined: Tue Mar 31, 2009 3:10 pm
Posts: 7
use -maxdepth 1 it will check $DIR but not its subfolders.

find "$DIR" -maxdepth 1 -mtime +$DAYSOLD -exec rm -f {} \;
or
find "$DIR" -maxdepth 1 -mtime +$DAYSOLD | xargs rm
or
find "$DIR" -maxdepth 1 -mtime +$DAYSOLD -delete


Top
 Profile  
 PostPosted: Mon Dec 19, 2011 3:13 am   

Joined: Sun Dec 18, 2011 4:23 am
Posts: 2
I think it will only recurse in directorys which are +$DAYSOLD

Ciao Nobbe


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 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