HOWTO: cleanup old files under Linux

Sometimes you want to separate old files (for example older than 30 days) into separate subdirectory to make navigation easier. Using Linux tools it's pretty easy task:

mkdir -p OLD; find . -maxdepth 1 -mtime +30 -exec mv \{\} OLD \;


  • mkdir -p OLD: create OLD subdirectory if not exists
  • -maxdepth 1: search only one level under current working directory
  • -mtime +30: find only files that are older than 30 days
  • -exec …. \;: for every file/directory found execute the following command
  • \{\}: will be replaced by filename

Above command will move all old files/subdirectories into OLD subdirectory.

This entry was posted in en and tagged , . Bookmark the permalink.