delete a file after xx mins
I would like to be able to delete a file after 30mins, what would the could be for that to check to make sure it 30mins and older ?
Regards,
Garry
3 Replies
0/30 * * * * rm file
If it's a regular file, try
find filename -cmin +30 -print | xargs rm
find will only output the filename if it was created at least 30 minutes ago (technically, if its ctime is more than 30 minutes ago), so if the file is newer, its filename doesn't get piped to xargs.
@smerritt:
find filename -cmin +30 -print | xargs rm
A minor gotcha with this; if you can't trust the filenames (eg someone else could have put them in) then use "-print0" and "xargs -0" because filenames with spaces, embedded returns or other funny characters could cause problems.