Deleting old files in Linux
Monday, 27 February 2006
While the Linux find command has a number of uses, the most obvious being looking for files matching full or partial names, the one often underused option is to use it to locate old files. To show all files in /tmp/ivan/ older than 7 days:
find /tmp/ivan/* -mtime +7 -print
An even more powerful option is to use the -exec switch which allows you to delete old files. To delete all files in /tmp/ivan/ older than 7 days:
find /tmp/ivan/* -mtime +7 -exec /bin/rm -rf {} \; 2>/dev/null 1>&2
See this man page for details.
|