Skip to content

Instantly share code, notes, and snippets.

@ChengLong
Last active August 29, 2015 13:56
Show Gist options
  • Save ChengLong/9043833 to your computer and use it in GitHub Desktop.
Save ChengLong/9043833 to your computer and use it in GitHub Desktop.
Delete old log files

Often, you find that log files are taking too much disk space. You want to delete them efficiently

find /path/to/log/directory -type f -mtime +180 | xargs rm

This command will delete all files older than 180 days in /path/to/log/directory. If you know your log files' name pattern, it's better to specify that pattern in the find command.

You probably don't want to do this manually everytime. So add it to cronjob

0 0 1 * * find /path/to/log/directory -type f -mtime +180 | xargs rm > /dev/null 2>&1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment