Skip to main content

Simple tool to delete old files using a set of contraints.

If --include if used, only files matching the provided glob pattern are considered. This option can be used multiple times. By default, all files are considered.

Usage

$ purge-old-files -h
usage: purge-old-files [-h] [--debug | --quiet] [--syslog] [--dry-run]
                       [--include PATTERN] [--exclude PATTERN]
                       MIN_AGE DIRECTORY

positional arguments:
  MIN_AGE               Minimum age of files
  DIRECTORY             Directory to be scanned

optional arguments:
  -h, --help            show this help message and exit
  --debug, -D           Show debug messages
  --quiet, -q           Only show warning messages
  --syslog, -s          Send log messages to /dev/log instead of stdout
  --dry-run, -d         Show which files should be deleted
  --include PATTERN, -i PATTERN
                        Include only files matching pattern
  --exclude PATTERN, -e PATTERN
                        Exclude files matching pattern

# Purge *.log files in /logs when they are older than 3 days
$ purge-old-files --include '*.log' 3d /logs

# Delete files from /backup when they are older than 1 week
$ purge-old-files 1w /backup

# Show which files from /backup are older than 3 months
$ purge-old-files --dry-run 3M /backup

File minimum age

Supported units:

  • s: seconds

  • m: minutes

  • h: hours

  • d: days

  • w: weeks

  • M: months (30 days)

  • y: years (365 days)

Installation

$ pip install purge-old-files

Requirements

  • Python 3.x

FAQ

  • Do you know you can do this with a simple shell script using find?

    Yep. I wrote those for years. They are also painful to maintain. And error prone. Feel free to use a shell script. :)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

purge-old-files-1.2.1.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file purge-old-files-1.2.1.tar.gz.

File metadata

File hashes

Hashes for purge-old-files-1.2.1.tar.gz
Algorithm Hash digest
SHA256 0c7a30d9b27e34f54d586e59c5c353bc50f4fe47de448189894565291c0645ff
MD5 86b5eb69f37c45c209c5367826aeaf98
BLAKE2b-256 95c08ff625a2171b68e8deff50b6a621e59251e330d0e8d4b16ca6a2e58ccfcd

See more details on using hashes here.

Release history Release notifications | RSS feed

1.3.0

1 file

This release

1.2.1 This release

1 file

1.0.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page