Drive Janitor is a file detection and deletion tool, highly configurable via a config.yaml file.
It can detect files based on MIME type, age, filename (with regex support), or YARA rules, recursively starting from one or more source directories.
Runs on Windows, Linux, and macOS.
Suggested use case: -> Detect and delete PDF files older than 30 days in the Trash.
On macOS, in order to scan the Trash directory, you must grant Full Disk Access to drive-janitor.
You can download precompiled binairies in the Releases tab.
On macOS, simply run the .pkg installer. It will install:
- The binary to:
~/.local/bin/drivejanitor - The default config file to:
~/.config/drivejanitor/config.yaml
➡️ Make sure ~/.local/bin is in your PATH. If not, you can add it by appending this line to your shell profile (~/.zshrc, ~/.bash_profile, etc.):
export PATH="$HOME/.local/bin:$PATH"
Download the binary matching your platform and place it anywhere in your PATH.
- Configure your settings in
config.yaml. - Run the janitor:
Windows
./drivejanitor-windows-amd64.exe -config config.yaml
Linux
./drivejanitor-linux-amd64 -config config.yaml
MacOS
drivejanitor -config config.yaml
Edit config.yaml to specify:
-
Detections:
Define which files to match in thedetectionssection. Each detection rule uses a unique rulename, and a detection parameters :mimetype(e.g.,"image/png") to filter files by MIME type.max_age(in days) to filter files by age. Settingmax_ageto-1, or leaving it unspecified disable age filtering.yara_rules_dirto specify a folder where yara rules files are located. Files matching those rules are detected. Only one directory can be specified.
-
Recursions:
Specify which directories to scan in therecursionssection. Each recursion includes a rulename, a startpath(e.g.,"./samples"), amax_depthfor how deep to scan, and an optionalpath_to_ignorelist to exclude subdirectories. -
Logs:
Configure where logs are stored in thelogssection by setting a rulename, alog_format(text, json or csv) and alog_repositorypath (e.g.,"./var/.log"). -
Actions:
Define what happens to matched files in theactionssection. Each action has a rulename, adeleteflag (e.g.,falseto only log), and alogreference. -
Rules:
Connect detections, recursions, and actions in therulessection. Each rule specifies which detections, recursion, and action to use for processing files.
⚡ All paths in the configuration supports $trash, $download or $home
Example:
name: TestMain
version: 1.0.0
detections:
- name: "detection_webp_elephant"
mimetype: "image/webp"
filename: "(?i).*elephant.*"
- name: "detection_pdf_older_than_30_days"
mimetype: "application/pdf"
max_age: 30
- name: "detection_yara"
yara_rules_dir: "./detection/checkyara/yararules"
recursions:
- name: "recursion1"
path: "../"
max_depth: 10
path_to_ignore: ["./samples/ignore"]
logs:
- name: "logging1"
log_format: "json"
log_repository: "./.log"
actions:
- name: "action1"
delete: false
log: "logging1"
rules:
- name: "FINALRULE1"
action: "action1"
detection: ["detection_webp_elephant", "detection_pdf_older_than_30_days", "detection_yara"]
recursion: "recursion1"Pull requests are welcome!
Happy cleaning! 🧹