I like using grep but sometimes I just want to search for the names of files in a directory tree, but don't want grep to open the files and search inside them. Can grep do this?


There are many answers to this question but the most 'correct' traditional unix answer is to use find(1):

find / -type f -name foo\*

will find every file under the current directory with a name that starts with foo

  • Actually, that command will find everything under the root directory. To find everything under the current directory you should use . as the first argument. You can also use any file path as the first argument. – Ladadadada Nov 16 '11 at 16:28

Try a regular expression, like

ls -R |grep ^a

This will list all files and subdirectories and the will filter on names starting with a.

This doesn't include a path though.


There are many ways to find files in linux. Best in my view are two. Find and Locate 'find' is much more powerful then locate. find command's has one limitation, which is, its speed at which it gives you results of your search. This issue is resolved by locate command. which stores a local cached tree of whole directory in it,(which is manually built by running UPDATEDB command) and when you want to search for a file, then simply use "locate filename", and you will get results instantly. when speed is issue, use locate, for anything else , use find command.


also you can use locate command

so first you should update locate Db by issuing updatedb command (note it could take some time for finish)

than run

locate foo*

You'll get full path to the file

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.