5

How do I use find to list every single file but exclude a handful of directories from the search?

find / -type f -not -path "./foo*" -not -path "/bar*" -print

I've seen examples on other stackexchanges, eg ./, but nothing I've tried seems to work.

This kinda works:

find / -type f -not -path "*foo*" -not -path "*bar*" -print

But not really; it also excludes files named "foo" and "bar" from the search results.

2 Answers 2

3

find / -type f -not -path "*foo*/*" -not -path "*bar*/*" -print seems to do the trick.

1

exclude directories during find

sudo find ~ -iname "*s40*" ! -path "*timeshift*"

this command searches in the Home directory /home/username and finds files (or directories) containing the text s40 but ignores all paths containing the text timeshift

-iname selects files by name, but ignores case (upper/lower) the exclamation mark means NOT, and find also recognises -not -path "timeshift"

the sudo avoids producing a long list of Permission denied

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .