delete old files in linux Mar
16
1
0

Edited: 4.15.2010 - fixed typo

You can use the [find] command in linux to remove old files through the command line. Pass in [-mmin +/-num] to specify minutes, and [-mtime +/-num] for days. Use [+] to get items older than the specified times, and [-] for younger.  Filter file/directory names through [-name], and run a command through [-exec].

# remove all files older than 7 days
find /path/to/directory* -mtime +7 -exec rm {} \;

# remove all *.py files younger than 30 minutes
find /path/to/directory* -name '*.py' -mmin -30 -exec rm {} \;

This is tested on Ubuntu.

Bookmark and Share
blog comments powered by Disqus