Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

while loop to delete old files

Status
Not open for further replies.

jalge2

Technical User
Feb 5, 2003
105
US
A little help would be great. I'm creating a script to delete old history log files. I'm in a directory and here is my code so far. I have no clue how to write a while loop with this information. Thanks for the help. ###VARIABLES###
+3 date1=`date +%Y%m%d`
+4 date2=`expr $date1`
+5 less=$(($date2 - 7 ))
+6 less1=$(($less - 1))

I have my variables set, but I need this

to keep running $less1 until it erases every file, 7 days or older. If you don't follow, please let me know. Thanks a lot.

Jason Alge


 

You can do it much easier with 'find' or 'skulker'.

# find /tmp -atime +7 -type d -exec rm {} \;

or look at the man page for skulker.

Cheers Henrik Morsing
Certified AIX 4.3 Systems Administration
& p690 Technical Support
 

Oops, typo: That should have been '-type f'.

Cheers Henrik Morsing
Certified AIX 4.3 Systems Administration
& p690 Technical Support
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top