5

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
  • 34,080
  • 14
  • 96
  • 122
St.Antario
  • 24,791
  • 31
  • 112
  • 278

1 Answers1

12

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
  • 17,834
  • 1
  • 28
  • 34