Remove files older then 30 mins of certain size with certain xtension?
How could I run a job that removes files from /tmp dir that have the following conditions:
older then 30 mins gz or zip extension larger then 1mb This is on FreeBSD. THanks |
Use the find command in your job.
/usr/bin/find /tmp -type f -cmin +30 \( -iname "*.gz" -o iname "*.zip" \) -execdir rm '{}' \; I'm not at my home computer & can't test it. I'm not absolutely certain about the -o part. I think that the filename tests need to be grouped so that the prior tests still hold. Otherwise, -iname "*.zip" will be enough for a match even if 100K or just 5 minutes old. You may want to be careful with your script. Are you certain you aren't including some files that you don't want to delete. Maybe you want to include an owner test such as "-not -user root" to only delete temporary files by regular users. Another potential problem is if a file is a zip or gz or bzip2 file but doesn't have an extension. A web browser may do that. In Linux, I might use the find command to locate large files older than 30 minutes, and pipe the output to "xargs -0 file". Does FreeBSD have the file command? |
Either a Bash script using find or a Perl script using File::Find should do the job nicely. (If you're more comfortable with a different scripting language (Python, Ruby, whatever), that should work just fine too.)
|
Yup - "find" is your guy!
(Try doing *that* under Windows ;-)) |
Quote:
You do realise cygwin works under windows? and that windows has commands? |
the command -stat- might be helpful, check its man page.
|
All times are GMT -5. The time now is 11:08 PM. |