M README.md => README.md +23 -9
@@ 6,16 6,30 @@ Bash script to automate deleting old files in a specified directory
cd Janitor
./install.sh
-The install script creates a symlink in your home directory to `janitor.sh` and
-appends an entry to the current user's `crontab` (use `crontab -l` to view your active cron jobs)
+By default, Janitor will monitor `$HOME/Downloads` and move any file older than
+30 days to your Trash folder (`$HOME/.Trash`). These settings can be changed using
+the installation script (see below).
## Options
-Open the `janitor.sh` file to change options
+**Target directory**
-| Option | Description |
-|:----------------:| ---------------------------------------------------------------------------------------------------------------- |
-| **TARGET_DIR** | Define which folder to clean out |
-| **DAYS_TO_KEEP** | How long should a file be able to live in the folder? |
-| **TRASH_DIR** | Where to move deleted files. Delete this if you want to permanently delete files instead of moving them to Trash |
-| **LOG_DIR** | Location to store log files, relative to the Janitor directory |
+ Specify which directory to monitor
+
+ -d <directory>
+
+**Trash directory**
+
+ Specify where to move files after deletion (if `-x` option is not set)
+
+ -t <directory>
+
+**Number of days to keep files**
+
+ -n <integer>
+
+**Hard delete files**
+
+ Flag indicating to not move files to another directory, but rather permanently delete them
+
+ -x
M bin/janitor => bin/janitor +8 -3
@@ 1,17 1,22 @@
#!/usr/bin/env bash
# Define which folder to clean out (default: ~/Downloads)
-export TARGET_DIR=${1:-$HOME/Downloads}
+export TARGET_DIR=$1
# How many days should a file be able to live in the folder? (default: 30)
-export DAYS_TO_KEEP=${2:-30}
+export DAYS_TO_KEEP=$2
# Trash folder to move deleted files to (default: ~/.Trash)
-export TRASH_DIR=${3:-$HOME/.Trash/}
+export TRASH_DIR=$3
# Location to store log files, relative to the Janitor directory (default: logs)
export LOG_DIR=logs
+if [ -z "$TARGET_DIR" -o -z "$DAYS_TO_KEEP" ]; then
+ echo "Minimum 2 arguments required"
+ exit 1
+fi
+
function clean() {
if [ $# -eq 0 ]; then
exit 1
M install.sh => install.sh +16 -3
@@ 1,10 1,15 @@
#!/usr/bin/env bash
+# Set defaults
TARGET_DIR=$HOME/Downloads
NUM_DAYS=30
TRASH_DIR=$HOME/.Trash
-while getopts "d:t:n:" opt; do
+function print_usage() {
+ echo "Usage: ./install.sh [-x] [-d <target directory>] [-t <trash directory>] [-n <integer>]"
+}
+
+while getopts "xd:t:n:" opt; do
case $opt in
d)
TARGET_DIR="$OPTARG"
@@ 12,18 17,26 @@ while getopts "d:t:n:" opt; do
t)
TRASH_DIR="$OPTARG"
;;
+ x)
+ TRASH_DIR=
+ ;;
n)
NUM_DAYS="$OPTARG"
;;
\?)
- echo "Invalid option: -$OPTARG" >&2
+ print_usage
+ exit 1
;;
esac
done
echo "Target directory is $TARGET_DIR"
echo "Deleting files older than $NUM_DAYS"
-echo "Trash direcotry is $TRASH_DIR"
+if [ -z "$TRASH_DIR" ]; then
+ echo "Hard deleting files - not using a Trash directory"
+else
+ echo "Trash direcotry is $TRASH_DIR"
+fi
function create_crontab() {
echo " "