How to quickly find a file in the Terminal - Ubuntu Linux
Finding the location of a file may not be an everyday task. But when you do need it, you really need it. For example I wanted to update the libffmpeg.so
from Opera Browser with the one from the Chromium Browser. That meant I needed to find where each were. The 'Files' app does have a search feature. This is not about it. This is how you do it in the terminal.
To help us in the terminal, there is locate
. Locate is a library you can apt install
. It maintains a database of file data enabling us to quickly find files. This is one of the reasons why I like it over the Files
app. In addition there is a powerful utility called find
. It allows us much more control but is usually slow and it deserves its own article.
Installation
Installation is straightforward:
sudo apt update
sudo apt install locate
Usage
The basic usage includes providing part of the name.
locate libffmpeg.so
You can also use regex to files that match a certain regex. For example to find a file like /var/www/jdeen.com/shared/private/uploads/proposals/PR0123 srs.pdf
.
locate -ir '^/var/www/jdeen.com/shared/\([^.][^/]\+/\)\+PR0123[^/]*$'
locate
is a simple command. Its not very powerful. But its very very fast once the indexing is done.
About the Author
Ziyan Junaideen -
Ziyan is an expert Ruby on Rails web developer with 8 years of experience specializing in SaaS applications. He spends his free time he writes blogs, drawing on his iPad, shoots photos.