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

1 Answer 1


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, 2013 at 4:58
  • 2
    Where are you adding -type f? I'd put it between -o and -print.
    – jw013
    Jan 17, 2013 at 5:14
  • Thanks @jw013 , that was just about the only place I didn't try. Jan 17, 2013 at 5:30
  • On more complex expressions you'll need to use parenteses for grouping...
    – vonbrand
    Jan 21, 2013 at 19:31

You must log in to answer this question.

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