Skip to content

Instantly share code, notes, and snippets.

@jesusgoku
Created March 10, 2015 19:50
Show Gist options
  • Save jesusgoku/afc0e4a2accc74ea65f4 to your computer and use it in GitHub Desktop.
Save jesusgoku/afc0e4a2accc74ea65f4 to your computer and use it in GitHub Desktop.
Exclude directories with find command
# Use the prune switch, for example if you want to exclude the misc
# directory just add a -path ./misc -prune -o to your find command:
find . -path ./misc -prune -o -name '*.txt' -print
# Here is an example with multiple directories:
find . -type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print
# Here we exclude dir1, dir2 and dir3, since in find expressions it is an action,
# that acts on the criteria -path dir1 -o -path dir2 -o -path dir3
# (if dir1 or dir2 or dir3), ANDed with type -d. Further action is -o print, just print.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment