You can use prune option of find command to exclude a directory in find command.
1 2 3 4 5 6 7 8 9 10 11 12 |
## Create some files and directories mkdir -p mydir/mydir1 mydir/mydir2 echo "hello" > mydir/mydir1/file1.txt echo "world" > mydir/mydir2/file2.txt ## Search using find excluding some directory ## find /some/path -path some/path/to_exclude -prune -o -name "somename" -print find mydir -path mydir/mydir1 -prune -o -name "*.txt" -print ## Returns mydir/mydir2/file2.txt ## Remove the directory rm -r mydir |