Fork me on GitHub

springclean

Reclaim your disk space. Clean up logs and old files safely. Preview changes before running. Written in 100% python.

Download springclean.zip

Sick of remembering arcane find syntax to remove your logfiles? Use springclean, 100% free and (should) run wherever python can!

Features:

  • Select file based on name, age or both
  • Preview changes - confirm before running
  • Find how much disk space has been freed
  • Gzip, move to another directory or remove your files
  • Create an audit trail with syslog

Examples

# List all files that match regex .*.log$ :
springclean -x ".*\.log$"

# Remove all files that match mail.log
springclean -f mail.log --rm

# Gzip all files older than 7 days with confirmation
springclean --gzip --older 7d --confirm

# Move all files newer than 2 weeks to directory /tmp
springclean --newer 2w --mv --destdir /tmp

# List all files newer than 3 days in /tmp directory
springclean --dir /tmp --newer 3d --list

# Move all files older than 2 hours matching "*.log" to /tmp
springclean --mv -f "*.log" --older 2h --destdir /tmp

Usage

springclean.py [options]

Options:

Match options - can choose a file match and time option

-f MATCH, --filematch=MATCH
                      shell-style wildcard to match logfiles to process
-x MATCHRE, --matchre=MATCHRE
                      regex to match logfiles to process
-n MTIME_NEWER, --newer=MTIME_NEWER
                      match files newer than x units (d|h|m|s), eg 3d
-o MTIME_OLDER, --older=MTIME_OLDER
                      match files older than x units (d|h|m|s), eg 3d

Actions - choose one (defaults to list)

--rm                  removed matched files
-l, --list            list matched files (default action)
-g, --gzip            gzip matched files
--mv                  move matched files to --destdir
--destdir=DESTDIR     directory to move files to (with --mv)

Switches - optional

-h, --help            show this help message and exit
--dir=DIR             directory to match from (default $PWD)
-v, --verbose         verbose output
-c, --confirm         confirm each individual operation (rm|gzip|mv)
-s, --syslog          log successful actions to syslog

Other

Note: unless you have disabled shell wildcard expansion (with set -f) you should quote your wildcards.

What springclean does not do:
  • recurse into subdirectories (yet)
  • remove directories

To install:

  • Get the zip file from the link above
  • Unzip and copy springclean to somewhere in your path (eg /usr/local/bin or ~/bin/)

Or get the bleeding edge version from GitHub

Written by James Powell

Built with the assistance of Python, IntelliJ, GNU Emacs & Twitter Bootstrap