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 recursivelyage: minimum age in days before a file may be deletedextension: optional file extension to match (for example.txt)delete_if_backed_up_to: optional backup folder that must contain the same relative pathdelete_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 isINFO; repeating-vraises the level toDEBUGso 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
-vflag increases logging detail untilDEBUGis 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file deletion_policy_tool-0.1.2.tar.gz.
File metadata
- Download URL: deletion_policy_tool-0.1.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7de33131f824817a267c9e53eea654eb18a7d6917e0714bb4136aa2615607431
|
|
| MD5 |
32357d802245ad12d116202c8005af2b
|
|
| BLAKE2b-256 |
6308baa86134f2776f1086954eb4c3dd576ffee1cf7ba4a3b1d6f67951046eef
|
Provenance
The following attestation bundles were made for deletion_policy_tool-0.1.2.tar.gz:
Publisher:
publish.yml on mshafer1/deletion_policy_tool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deletion_policy_tool-0.1.2.tar.gz -
Subject digest:
7de33131f824817a267c9e53eea654eb18a7d6917e0714bb4136aa2615607431 - Sigstore transparency entry: 2641078874
- Sigstore integration time:
-
Permalink:
mshafer1/deletion_policy_tool@694a8eabae9388f2d4f4e2c1743f009ac74bb0a9 -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/mshafer1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@694a8eabae9388f2d4f4e2c1743f009ac74bb0a9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file deletion_policy_tool-0.1.2-py3-none-any.whl.
File metadata
- Download URL: deletion_policy_tool-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94da6ed3e83abfdc7e183bd5e64c6f63542525993b4a9ebac76dc5b6f4df0c7c
|
|
| MD5 |
766de346545a34a51e5f9247163a8d98
|
|
| BLAKE2b-256 |
0184dfafaf8f184ba3be54ee47ec20e715c237fe8ec32f0732739bf259057ec1
|
Provenance
The following attestation bundles were made for deletion_policy_tool-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on mshafer1/deletion_policy_tool
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deletion_policy_tool-0.1.2-py3-none-any.whl -
Subject digest:
94da6ed3e83abfdc7e183bd5e64c6f63542525993b4a9ebac76dc5b6f4df0c7c - Sigstore transparency entry: 2641079529
- Sigstore integration time:
-
Permalink:
mshafer1/deletion_policy_tool@694a8eabae9388f2d4f4e2c1743f009ac74bb0a9 -
Branch / Tag:
refs/tags/0.1.2 - Owner: https://github.com/mshafer1
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@694a8eabae9388f2d4f4e2c1743f009ac74bb0a9 -
Trigger Event:
release
-
Statement type: