Skip to content

Instantly share code, notes, and snippets.

@rw3iss
Created January 25, 2021 11:40
Show Gist options
  • Save rw3iss/1db5d19a85470f2646ee2a1da1cf9fc5 to your computer and use it in GitHub Desktop.
Save rw3iss/1db5d19a85470f2646ee2a1da1cf9fc5 to your computer and use it in GitHub Desktop.
Add .deja-dup-ignore file to all subdirectories matching a pattern
# This will only add it to the first instance/depth of the matching ignoreFolder (ie. it won't add it to the sub-dependencies of any node_modules folder
startPath=/home/rw3iss/Sites
ignoreFolder=node_modules
find $startPath -mindepth 1 -maxdepth 5 -name "$ignoreFolder" -type d -not -regex ".*$ignoreFolder.*$ignoreFolder.*" | while read fname; do
echo "" > "$fname/.deja-dup-ignore"
echo "$fname/.deja-dup-ignore created."
done
@dontfreakout
Copy link

With this at the beginning of the script, you don't need hardcoded paths ;-)
You can then use script like this:

$ addDejaDupIgnoreFiles.sh -s /home/rw3iss/Sites -i node_modules

#!/bin/bash

while getopts s:i: flag
do
    case "${flag}" in
        s) startPath=${OPTARG};;
        i) ignoreFolder=${OPTARG};;
    esac
done

@rw3iss
Copy link
Author

rw3iss commented Jun 1, 2021

Ah cool! I am not a bash expert and only dabble. I also don't use this script anymore - moved from DejaDup to Duplicity so I could manage things more manually. However, you just taught me how to parse options. Thank you! May the benevolent bash gods shine their favor upon you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment