Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Starting from (notice the wildcards before and after "some text")

find . -type f -name '*some text*'

how can one exclude/ignore all hidden files and directories?

I've already been googling for far too long, came across some -prune and ! (exclamation mark) parameters, but no fitting (and parsimonious) example which just worked.

Piping | to grep would be an option and I'd also welcome examples of that; but primarily I'm interested in a brief one-liner (or a couple of stand-alone one-liners, illustrating different ways of achieving the same command-line goal) just using find.

ps: Find files in linux and exclude specific directories seems closely related, but a) is not accepted yet and b) is related-but-different-and-distinct, but c) may provide inspiration and help pinpoint the confusion!


find . \( ! -regex '.*/\..*' \) -type f -name "whatever", works, but I don't know why or how. (I realize find uses (by default) the EMACS regex syntax.) Could anyone explain?

share|improve this question
Doesn't help with what you asked in your edit but take a look at my question and its answer here: unix.stackexchange.com/q/69164/15760 and also the link in the answer. –  user25656 Mar 26 '13 at 6:25
add comment

3 Answers

This prints all files that are descendants of your directory, skipping hidden files and directories:

find . -not -path '*/\.*'

So if you're looking for a file with some text in its name, and you want to skip hidden files and directories, run:

find . -not -path '*/\.*' -type f -name '*some text*'


The -path option runs checks a pattern against the entire path string. * is a wildcard, / is a directory separator, \. is a dot (it has to be escaped to avoid special meaning), and * is another wildcard. -not means don't select files that match this test.

I don't think that find is smart enough to avoid recursively searching hidden directories in the previous command, so if you need speed, use -prune instead, like this:

 find . -type d -path '*/\.*' -prune -o -not -name '.*' -type f -name '*some text*' -print
share|improve this answer
add comment

Some time ago I had a similiar question. Some googling around I found this Site

Exclude hidden files when searching with Unix/Linux find?

Changing it to your needs and it should work.

Hope this helps.

Greez W.

share|improve this answer
Thanks! looks promising; I'll check it out. –  nutty about natty Mar 11 '13 at 11:38
find . \( ! -regex '.*/\..*' \) -type f -name "whatever" anyone care to explain the regex-syntax? Note that by default find uses EMACS. –  nutty about natty Mar 11 '13 at 12:41
Sorry, I'm in a hurry, so just a another link: emacswiki.org/emacs/RegularExpression. Trying to look later on it. –  Wolf F. Mar 11 '13 at 13:35
Glanced through that one already, didn't help; there's no rush, but I feel I'm no regex guru and need some help; thanks! –  nutty about natty Mar 11 '13 at 13:44
add comment
find $DIR -not -path '*/\.*' -type f \( ! -iname ".*" \)

Excludes all hidden directories, and hidden files under $DIR

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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