How to Find Files in Linux Terminal Using Locate
On Linux, you can use Terminal to search for a file.
Searching for files using Terminal will be more effective in terms of speed compared to using tools file search using GUI, because there is no need to load graphical interfaces which will take up more resources.
Not only that, under certain conditions you cannot search for files using the GUI, for example in server Linux that only uses command line interface.
Previously we have written about how to find files using Terminal on Linux using the command find.
Apart from using the command find You can also do a file search using command line interface on Linux by using a tools another named locate.
File search process using locate can be faster than using the command find.
This is because of the command locate does not search for files by browsing the storage media directly one by one, but instead searches through the file data stored in the file database in the “mlocate.db” file.
To use locate To do a file search, open Terminal on your Linux by pressing the keyboard combination (CTRL+ALT+T) or open Terminal via the application menu.
To perform a search, you can do so by entering order locate and followed by the name of the file you want to search on interface Terminal, as follows:
locate ubuntu.png
Then locate will perform a search and display a search result file that has the name “ubuntu.png” as shown below:
Replace the word “ubuntu.png” in the command with the name of the file you want to find. Then locate will perform a file search by keywords it with the names of the files in the databases.
Performing a Case Insensitive Search Using Locate
by defaults, file search process using the command locate sensitive to case from keywords. That way, if you do a quest with keywords which is all lowercase, you can only find files that use all lowercase.
You won’t be able to find files where one (or more) characters are capitalized, even if the files have the same name.
To work around this, you can use the parameter “-i” so that locate not case sensitive, such as the following:
locate -i ubuntu.png
So locate will perform a search for files that are not sensitive to caseas the following image can find files that use uppercase letters in one of the characters of their filenames:
Counting Number of Search Results Using Locate
If keywords what you are looking for has a lot of search results, you can add parameter “-c” to calculate how many search results match keywords that you enter, as follows:
locate -c ubuntu.png
So locate will calculate how many files there are search results as shown below:
Because of orders locate perform a filename search by databasethen the search results of the file being searched for are not entirely accurate, the command locate can find old files that have actually been deleted, however the database there still is.
To solve this, you can update database path on your Linux by using the command updated as follows:
sudo updated
Although it can perform file searches more quickly, using the command locate will be a little difficult for novice users because locate perform a file search by database.
If you feel you can and effectively perform a file search using the command locate In this case, you can use it to search for files on your Linux.
But if you have difficulty with the process and search results of locateyou can do a file search via Terminal by using the command find which is much easier to use for novice users.