DEV Community

loading...

Locating a specific file in terminal

haxnet profile image HaxNet Updated on ・1 min read

If you are a CLI enthusiast like myself and always looking for a file but don't know where it is exactly then I got a solution for you

First install mlocate in your system

update: I failed to mention that you need to first update your database before searching anything

put this in your terminal

sudo updatedb
Enter fullscreen mode Exit fullscreen mode

Type

locate keyword

and you will see your results like this. However, if you search for something that is very common you will get hundreds of results and that won't be ideal.
Alt Text

However, if you search for something that is very common you will get hundreds of results and that won't be ideal.

My typical command is the following

locate keyword | grep keyword

grep searches one or more files for lines that matches a regular expression pattern.

Alt Text

Hope this helps whenever you are trying to edit a file that you haven't touched in months.

Discussion (3)

pic
Editor guide
Collapse
nishithsavla profile image
Nishith Savla

Have you tried using whereis ?

Collapse
haxnet profile image
HaxNet Author

yes, but whereis doesn't show as much results as locate

Collapse
nishithsavla profile image
Nishith Savla • Edited

Ohh I see, I found out that whereis searches only in the dirs listed in PATH