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?
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):
will find every file under the current directory with a name that starts with
foo
Try a regular expression, like
This will list all files and subdirectories and the will filter on names starting with a.
This doesn't include a path though.
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
You'll get full path to the file
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.