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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Anyone have a script to remove old files ? 2

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
0
0
CH
Does anyone have a script that will remove old files?
I want to go thru various directories and remove files older than 1 day.
ALSO - Anyone know of any good Shell script freeware sights ?

Thanks
 
You could create on yourself using as a reference the date of a given file.

Use the find command similar to this:

find {starting directory} -newer {reference filename} -exec {command};

You will have to look at the man pages for the find command to determine the exact format of the exec option but it works very very well.

Good luck.
 
using the find command take a look at the mtime/ctime parameters which allow files older or newer that a certain number of days to be located. Then use the exec parameter to remove the required files.

Stu
 
Hello, you can use
[tt]
find /starting/direc -newer reference_file -exec rm {} \;
[/tt]
or
[tt]
find /starting/direc -mtime +number -exec rm {} \;
[/tt]

The first form compares the files with your reference file and then executes a rm in the files newer than... you can use [tt]-n -newer file[/tt] to remove files older than your reference. Or you can use [tt]-ok[/tt] instead of [tt]-exec[/tt] to receive a propmt for every and each file found.

The second form selects files with a modification time greater than the number of days selected (+number)...

I hope it works...
 
Hi Tison,

Try the command skulker ---it cleans up filesystems and remove unwanted files. Candidate files include: those in /tmp directory;files older than a certain age ;a.out file;core files. Skulker is normally invoked daily by the cron command as part of the root's crontab file.

You can modify the skulker shell scripts to suit local need for the removal of files.

dabit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top