I am wanting to search recursively through a directory and find all files that are not hidden files themselves and are not in a hidden dir. I tried using find . -type f -not -name '.*' which excludes any base name hidden files, but it still recurses into hidden directories.


I would want the output to be:


however, I get:


EDIT: I would like to list only files, i.e., -type f


You'll have to "prune" the directories you don't want to recurse into:

find dir -name '.*' -prune -o -print

Usually -prune is used with -o because it returns true, so when combined with short-circuit OR, it has the effect of skipping the -print on hidden files / directories, which is exactly what you want.

  • Is there anyway to only display the results of type file with this method? I forgot to mention that and adding -type f seems to break this. Jan 17 '13 at 4:58
  • 2
    Where are you adding -type f? I'd put it between -o and -print.
    – jw013
    Jan 17 '13 at 5:14
  • Thanks @jw013 , that was just about the only place I didn't try. Jan 17 '13 at 5:30
  • On more complex expressions you'll need to use parenteses for grouping...
    – vonbrand
    Jan 21 '13 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.