Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

What about the following?

find \( -name '*.avi' -o -name '*.mkv' -o -name '*.mp4' -o -name '*.vob' \) -a -not -path './secure*'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top