Skip to main content

deletion-policy-tool

Warning: This tool is intentionally built for developers and system administrators who understand that it follows the classic Linux philosophy: "If you want to shoot yourself in the foot, it is this tool's job to do that as efficiently as possible." Use it only with carefully reviewed policies, backups, and explicit operational intent.

This project comes with no warranty. See the LICENSE file for the legal text and warranty disclaimer.

This project provides a small command-line tool for cleaning up files according to configurable deletion policies.

What it does

The tool scans one or more folders for files that match a policy, deletes them when they are old enough, and only removes them when any extra safety conditions are satisfied.

Each policy can require that a file:

  • is older than a specified number of days,
  • has the expected file extension,
  • has a backup copy in a designated backup folder, and/or
  • has a related copy with a different suffix in the same folder.

This makes it useful for retention workflows where files should be removed only after they have been preserved elsewhere.

How it works

The CLI reads a YAML configuration file from the environment variable DELETION_POLICY_CONFIG_FILE.

Each entry in the YAML file is a policy with the following fields:

  • folder: the directory to scan recursively
  • age: minimum age in days before a file may be deleted
  • extension: optional file extension to match (for example .txt)
  • delete_if_backed_up_to: optional backup folder that must contain the same relative path
  • delete_if_copy_exists: optional pair of extensions such as ['.txt', '.new_suffix'] meaning a file with the first extension must have a sibling with the second extension before deletion

Files are processed recursively under the configured folder. Only regular files are considered.

Example configuration

- folder: /path/to/source
  age: 30
  extension: .txt
  delete_if_backed_up_to: /path/to/backup

# deletes .log files if .bak file with same name exists next to it
- folder: /path/to/source
  age: 14
  extension: .log
  delete_if_copy_exists: [.log, .bak]

Installation

pipx

pipx install deletion_policy_tool

global pip install (not recommended)

python -m pip install deletion_policy_tool

uv

uv tool install deletion_policy_tool

from source

git clone https://github.com/mshafer1/deletion_policy_tool.git
cd deletion_policy_tool
poetry install

Usage

Set the configuration path and run the CLI:

export DELETION_POLICY_CONFIG_FILE=/path/to/deletion_policy.yml
run-deletion-policy
# use default policy (in ~/.config/deletion_policy.yml)
# also remove directories that are empty after files are deleted
run-deletion-policy --remove-empty-folders
# preview deletions without removing anything
run-deletion-policy --dry-run
# ask for confirmation before deleting each matching file or folder
run-deletion-policy --confirm-each-delete
# see all options
run-deletion-policy --help

Optional flags

  • --dry-run: logs the files and folders that would be deleted without making any changes.
  • --confirm-each-delete: prompts the user before each deletion so you can review the action individually.
  • --remove-empty-folders: removes directories that are empty after file deletions.
  • -v: increases log verbosity. The default logging level is INFO; repeating -v raises the level to DEBUG so more detail is shown while policies are evaluated.

Logging behavior

The CLI sets up logging as soon as it starts. Messages are emitted to the console and also written to a rotating log file at ~/logs/deletion_policy_tool.log.

  • Console logging follows the configured verbosity level.
  • The default level is INFO.
  • Each additional -v flag increases logging detail until DEBUG is reached.
  • The file log uses a rotating handler with a 10 MiB limit and keeps the last 5 log files.

This makes it easier to troubleshoot policy matching and file-skipping decisions while still keeping a persistent history of runs.

If you are using the package entry point installed by Poetry, the command can also be run as:

poetry run deletion-policy-tool

Notes

  • The tool deletes files only after all applicable conditions pass.
  • If a policy specifies a backup location, the backup file must exist at the same relative path under that backup folder.
  • If a policy specifies a copy relationship, the corresponding file with the destination extension must exist.
  • The tool is intentionally conservative: files are skipped unless the policy requirements are met.

Download files

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

Source Distribution

deletion_policy_tool-0.1.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deletion_policy_tool-0.1.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file deletion_policy_tool-0.1.1.tar.gz.

File metadata

  • Download URL: deletion_policy_tool-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for deletion_policy_tool-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cf6ef1593832cb37ce21ef268697a5f5c735e56f417257910733602b9cf1171f
MD5 6353e3ae4acf3c1e70c48caff5dd1a54
BLAKE2b-256 f715a9252cf9bdcdf88efbe57b6f4537ad0c810b89ab31aa19ccefa949a21b33

See more details on using hashes here.

Provenance

The following attestation bundles were made for deletion_policy_tool-0.1.1.tar.gz:

Publisher: publish.yml on mshafer1/deletion_policy_tool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deletion_policy_tool-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for deletion_policy_tool-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a76fc910a3e98f7c1b477b2fb7475d984ca20bcdbd5b7b69b76c04708fe5c858
MD5 44c63c6c0a2be48321f7175debacb911
BLAKE2b-256 9283504dc48f35f0de66485b0513ff750946963fd83c39eac4622f1bec18d7ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for deletion_policy_tool-0.1.1-py3-none-any.whl:

Publisher: publish.yml on mshafer1/deletion_policy_tool

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.3

2 files

0.1.2

2 files

This release

0.1.1 This release

2 files

0.1.0

2 files

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