Simplify your business
Thursday, 24 July 2008 4:22 am

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.

Posted in Linux by Ivan
Blinklist icon Del.iocio.us icon Furl icon Reddit icon Technorati icon Yahoo! icon

Got something to say?

To protect your privacy, your email address will not be displayed.





Some basic rules for commenting:

  • Watch your language.
  • Keep comments on-topic and relevant.
  • You can use basic XHTML tags for formatting and linking but not bbcode.
  • Comments are moderated, so don't double post if your comment doesn't appear immediately.
  • Please proof-read your comments for spelling and grammar mistakes.
  • Watch your language.