6

I want to exclude all directories from the find command target. I can use this:

find / -not -path /my/path -name name

But this still keep looking at all subdirectories of /my/path. Is there a way to exclude the directory and all its subdirectories from find?

codeforester
  • 39,467
  • 16
  • 112
  • 140
St.Antario
  • 26,175
  • 41
  • 130
  • 318

1 Answers1

15

with -prune

find . -name directory_to_exclude -prune -o ...

to exclude many directories

find . \( -name dir1_to_exclude -o -name dir2 ... \) -prune -o ...
Nahuel Fouilleul
  • 18,726
  • 2
  • 31
  • 36