Skip to content

Instantly share code, notes, and snippets.

@Loriowar
Last active February 25, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Loriowar/274f5363877413bfdbcf5a4b8a804eba to your computer and use it in GitHub Desktop.
Save Loriowar/274f5363877413bfdbcf5a4b8a804eba to your computer and use it in GitHub Desktop.
Recursively find directories excluded from Time Machine backup
#!/bin/sh
#NOTE pass a path as a first argument, i.e. `./recursive_tmutil.sh ~/`
find $1 -type directory -exec tmutil isexcluded {} + \
| grep -F "[Excluded]" \
| sed -E 's/^\[Excluded\][[:space:]]*//' \
| awk '{ print length, $0 }' \
| sort -n -s \
| cut -d" " -f2- \
| awk ' { if(length(res) == 0) { res[$0] }; mark=0; for(r in res) { if(match($0, r)== 1){ mark=1; break } }; if(mark==0) res[$0] } END { for (i in res) print i } ' \
| sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment