0

I have a command that looks through all my sub folders for files, however I want it to skip a folder from the search and I'm not sure what is the right way to do this:

find -name '*.avi' -o -name '*.mkv' -o -name '*.mp4' -o -name '*.vob'

I want it to not look into the folder name: secure

I tried:

find -name '*.avi' -o -name '*.mkv' -o -name '*.mp4' -o -name '*.vob' --skip 'secure'

but it does not work.

Thanks for your help in advance.

thevoipman
  • 1,773
  • 2
  • 17
  • 44

2 Answers2

6

There is no --skip argument in GNU find. But you can do what you want using the -path and -prune expressions. The syntax is a little weird: you use -path ./secure -prune as a term which you then OR with the rest of the expression. So in your case:

find . -name '*.avi' -o [...] -o -path ./secure -prune

Note that this will still return the directory ./secure in the results, but nothing inside it.

Andy Ross
  • 11,699
  • 1
  • 34
  • 31
1

What about the following?

find \( -name '*.avi' -o -name '*.mkv' -o -name '*.mp4' -o -name '*.vob' \) -a -not -path './secure*'
juan.facorro
  • 9,791
  • 2
  • 33
  • 41
  • This works, but note that it still traverses the ./secure tree, rejecting all files and directories underneath. I like -prune for that reason. – Andy Ross Aug 09 '12 at 04:48
  • Not only it's more efficient but using `-prune` seems a more cleaner and elegant solution also. – juan.facorro Aug 09 '12 at 04:53