0
PROJECTS
   |___ SITE1
   |      |____files (to exclude)
   |      |____img
   |      |____js
   |
   |___ SITE2
   |      |____files (to exclude)
   |      |____img
   |      |____js
   |
   |___ SITE3
          |____files (to exclude)
          |____img
          |____js

Hello, I’d like to search into SITEx folders excluding content of files folders.

I try this but it display me permissions errors for files into files folders (so seem to not exclude them) :

find . ! -path "*/files/*" -type f -name 'foo'

It display (I’m in PROJECTS directory):

./SITE1/img/foo.png
./SITE1/js/foo.js
find: `./SITE1/files/201501': Permission denied
find: `./SITE1/files/201412': Permission denied
find: `./SITE1/files/201501': Permission denied
... (the two firsts matches are pretty good, but I break the execution after, it print too many indesirble matches)

I was inspired by this response on askubuntu.

I also try the -prune option like in this example without finding a solution…


I’d like to have the equivalent of this search with egrep but for filenames

egrep -Rns --exclude-dir=files 'foo' *

Thanks for your help !

7
  • We need way more information. I have no idea what you are asking. You have no direct question. Try writing again so there is a specific question you are asking.
    – Eric F
    Jan 13, 2015 at 17:08
  • 1
    Unless I'm mistaken, which is possible, an exclusion causes the "hits" to be not displayed, but does not stop the directories from being looked into. The documentation (the --help output, the man page or something other) for the find command should indicate how find behaves. Did you look into this documentation?
    – killermist
    Jan 13, 2015 at 17:18
  • This is actually disturbingly easy to do in Windows 8... are you stuck with find on Linux or are you able to use Windows for this?
    – Mokubai
    Jan 13, 2015 at 18:11
  • Try the -prune directive of find. I suggest that you search for examples (there are a few good ones right here at Super User), because the man page by itself is not very illuminating on the subject of how to use -prune. Jan 13, 2015 at 18:44
  • 1
    @BroSlow On Windows 8 all you do is click inside the search box and type -"files" -directory and it does exactly what is asked without having to first open a new terminal window, cd'ing to the directory, then figuring out the syntax of the find command. The *nix seems a lot like the "long" way. But I'm not here to evangelise, I was just wanting to see if other options were available or if another method would help.
    – Mokubai
    Jan 17, 2015 at 10:23

1 Answer 1

0

Ok done !

I didn’t know how to use prune argument. This respond to my demand

find * -path "*/files/*" -prune -o -name 'foo' -type f -print

More explication here


On the other hand I should be curious if there is a syntax with the ! (NOT) argument like in this example on AskUbuntu if someone have an idea.

1
  • Yes, but the AskUbuntu example you linked doesn't stop find from continuing to traverse those directories, so you would still get the errors. Your syntax is not worse in any way, and is at worst never slower (almost always faster). Although, note that by using *, instead of ., you are likely omitting dotfiles in your top level directory
    – user281208
    Jan 17, 2015 at 9:36

You must log in to answer this question.

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