beeing in my home directory, I want to find all files within my current directory excluding these 2 directories:


following this solution: https://unix.stackexchange.com/questions/508054/using-find-to-exclude-multiple-paths-matching-patterns

find . \( -path "/home/achille/.cache/mozilla/*" -o -path "/home/achille/.mozilla/*" \) -prune -o -type f -print | grep mozilla

following this solution: Find files but exclude several directories?

find . -not -path "/home/achille/.cache/mozilla/*" -not -path "/home/achille/.mozilla/*" -type f -print | grep mozilla

following this solution : https://stackoverflow.com/questions/14132210/use-find-command-but-exclude-files-in-two-directories

find . -type f ! -path "/home/achille/.cache/mozilla/*" ! -path "/home/achille/.mozilla/*" -print | grep mozilla

(for each of these attempts, I also tried '/home/achille' instead of '.'. Expecting no output for each command, I have got instead the following:


  • state your OS, for example it's clearly not windows, even though windows has a find command
    – barlop
    Nov 23, 2019 at 14:12
  • Stream-Centos - 4.18.0-147.6.el8.x86_64 #1 SMP Tue Oct 15 15:19:32 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
    – achille
    Nov 23, 2019 at 14:30
  • just tried: find . ! ( -path "/home/achille/.cache/mozilla/*" -o -path "/home/achille/.mozilla/*" ) -print | grep mozilla -> pb remains.
    – achille
    Nov 23, 2019 at 14:35
  • -path does not match paths by their equivalency in the directory tree, it matches them as strings. You specified . as the only starting location, so every path tested starts with .. You provided paths you want to exclude as strings starting with /home/achille/. They cannot match anything that starts with .. Then you said "I also tried /home/achille instead of .", but what you got ("I have got instead the following") starts with .. This doesn't fit. Please verify or/and elaborate. I think I'm on the right track but the incoherence in the question stops me from answering. Nov 23, 2019 at 20:34

1 Answer 1


Another approach.

If you are really want to ignore all '.mozilla' and '.cache/mozilla' files. This basically matches all files, except those matching these two patterns.

find . -not -name ".mozilla" -and -not -wholename ".cache/mozilla" -print


-not       means negate the following command
-name      is the name of the file you are (or not) looking for
-and       means matching first test and the second test must pass
-wholename matches name with a path.
-print     display the results  (also is optional since default is display result)

On the other hand, here is the opposite,find only those files which match the two patterns.

$ find . -name "mozilla" -or -name "*.mozilla"

Example results

 $ find . -name ".mozilla"


 $ find . -name "mozilla"


 $ find . -name "mozilla" -or -name "*.mozilla"


Interesting enough, when '-print' is added at the end of the line. Only one result is returned.

 $ find . -name "mozilla" -or -name "*.mozilla" -print

So need to add parens

 $ find . \( -name "mozilla" -or -name "*.mozilla" \) -print

Or add -print to both sides of the -or statement

 $ find . -name "mozilla" -print -or -name "*.mozilla" -print

You must log in to answer this question.

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