Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to perform a search for "foo" and return all the filenames/ directories with this name (e.g. foo.php, foo.txt etc ). It should run through the whole filesystem and find even hidden files . I've tried find / -name 'foo' but doesn't seem to work .

share|improve this question
up vote 4 down vote accepted

find's -name operator uses shell-style wildcards, so

find / -name 'foo.*' -o -name '.foo.*'

would find foo.php foo.txt or hidden files like .foo.php etc. -o means "Or", without it a file would have to have both names. Use -iname if you want case insensitive matching.

share|improve this answer
    
cept that isn't going to find hidden files – Mike Jan 15 '13 at 13:58
    
ohh stupid me ... it was so easy – user154523 Jan 15 '13 at 14:00

use -regex option which is applied to the full path of each file / dir / socket etc tested

find / -regex '.*foo\.(php|txt|iso)'

should work for hidden files too.

share|improve this answer

Your Answer

 
discard

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.