prunefiles - A Shell Script to Selectively Delete Files
Characteristics of prunefiles:
- Uses configuration file(s) to specify which files to delete
- Enforces safeguards on configuration file(s): ownership, write permissions, etc.
- Comprehensively logs what it does
- Never outputs to stdout, stderr or prompts for input if it encounters an error
- Handles very large numbers of directories and files
- Uses "directory patterns" instead of directorys or 'glob expansions (/tmp/*)
- Handles directories and files with "special" characters in their names
Some of the reasons to use prunefiles, rather than, say a cron entry like this:
find /var/tmp/application -type f -mtime +31 -name '*.log' -exec rm {} \;
The prunefiles Usage Message
$ prunefiles
usage (version 2.1.0):
prunefiles [optional_arguments] prunefiles_args_pathname [...] # where the options are:
-d delimiter_string - Default: ':::'
-f find_program - Default: /usr/local/bin/findfiles
-h - Display this usage message
-l log_file - Send output to a this log file. Default: '/var/tmp/prunefiles_jc/20250917_094626' (as of now)
-n - Dry run mode - display files/directories to be deleted; do not delete them. Default: off
-v verbosity_level - Default: 3
Download prunefiles from the github repository.
Using Prunefiles with findfiles (the default)
/var/tmp/my_program/logs ::: -f -m 31D -p '\.txt' ::: delete files ending in .txt modified > 31 days ago
/var/tmp/my_program/sent ::: -f -m 1Y -p '\.csv' ::: delete files ending in .csv modified > 1 year ago
Using Prunefiles with find
/var/tmp/my_program/logs ::: -mtime +31 -name '*.txt' ::: delete files ending in .txt modified > 31 days ago
/var/tmp/my_program/sent ::: -mtime +365 -name '*.csv' ::: delete files ending in .csv modified > 365 days ago
prunefiles Examples
$ prunefiles /root/prunefiles_args