2009-02-06

Exclude directories with find in Solaris and Linux

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Under current directory, there is a folder called .snapshot. When we run find command, we don't want to look into the .snapshot folder.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
IN SOLARIS,

Command:
find . -type d -name '.snapshot' -prune -o -print

Explanation:
-type d -name '.snapshot' : matching directory named .snapshot
-prune : Does not examine any directories or files in the directory structure below the pattern
just matched
-o : or (expr1 -or expr1)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
IN LINUX,

Command:
find . -path '\.\/\.snapshot' -prune -o -print

Explanation:
-path '\.\/\.snapshot' : matching directory named .snapshot
-prune : If -depth is not given, true; if the file is a directory, do not descend into it.
If -depth is given, false; no effect.
-o : or

Command:
find . -wholename '\.\/\.snapshot\/*' -prune -o -print

Explanation:
-wholename PATTERN : File name matches shell pattern PATTERN.
-prune : If -depth is not given, true; if the file is a directory, do not descend into it.
If -depth is given, false; no effect.
-o : or

Command: exclude ./.snapshot and ./root-audit
find . -path '\.\/\.snapshot' -prune -o -path '\./root-audit' -prune -o -print
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

No comments: