-
Clean up by date
Hi,
I have some script running. It places folders with files in /var/tmp
The problem is that the script doesn't clean up properly and I can't predict the names of the folders.
What I'm looking for is a simple bash script I can use to clean up that folder by using a cron-job. Let's say delete everything inside folders which are 5 days or older.
I know that can be a problem since rmdir is for folders and rm for files, but I've installed secure-delete to solve that, because it's capable of removing folders with files in them.
So I need something that puts the right folder names into this command:
Code:
srm -drzvll /var/tmp/[folder name]
Used version: mythbuntu 9.04 (9.10 didn't work, didn't try 10.04 yet).
-
Re: Clean up by date
Hi,
For removing folders with files in, use 'rm -R [folder name]', and to run a command to get the file name, use something like this:
Code:
rm -R /var/tmp/`other command`
Note the backticks, ie ` not '. This runs 'other command', and copies the output into the outer command (rm -R /var/tmp/...).
-
Re: Clean up by date
Thanks, but I don't know the folder names.
Actually, the deleting part was kind of solved, I only need the correct input to select the folders that can be deleted.
-
Re: Clean up by date
-
Re: Clean up by date
Try somethign along the lines of this, but be careful with it:
Code:
find /var/tmp/ -mtime +5 -exec rm -R {} \;
-
Re: Clean up by date
That seems to do the trick.
I had to test it with -mtime +0 since I had manually deleted all the files a few days ago (0 free space left on the drive) and -mtime +5 didn't do anything.
Before I put it in a daily script, I ran this line from the prompt:
Code:
find /var/tmp/ -mtime +0 -exec rm -R -i {} \;
It only processed the folder created before yesterday, so +5 (and without the -i) should be more or less a secure way to tell that the files can really be deleted since the conversion script which create the files/folders takes at most 24 hours to complete the conversion.
I'll mark this thread solved.