The failure in finding the easiest and yet more practical means of looking up files is one of the most disagreeable experiences faced by new users of the Linux OS in their systems.
Linux uses certain mechanisms to answer search questions for its users.
Two of the most popular file searching utilities available to users are called Find and Locate.
The following are the ten simple locate commands to set you up in becoming more productive with your Linux OS
1. Utilizing locate Command
Firing the locate command to scan for a file is pretty clear and candid. Type you need to do:
$ locate LAMP-Setup.odt
/home/softech/LAMP-Setup.odt
/home/softech/SofTech.com/LAMP-Setup.odt
2. Limit Search Requests to a Specific Number
You can set your search results to a limited number to avoid repetition with your quest results applying the -n command.
If you require 20 results from your queries, have to type the below command:
$ locate "*.html" -n 20
/home/softech/.config/google-chrome/Default/Extensions/aapocclcgogkmnckokdopfmhonfmgoek/0.9_0/main.html
/home/softech/.config/google-chrome/Default/Extensions/aohghmighlieiainnegkcijnfilokake/0.9_0/main.html
/home/softech/.config/google-chrome/Default/Extensions/felcaaldnbdncclmgdcncolpebgiejap/1.1_0/main.html
/home/softech/.config/google-chrome/Default/Extensions/kbfnbcaeplbcioakkpcpgfkobkghlhen/14.752.848_0/forge.html
/home/softech/.config/google-chrome/Default/Extensions/kbfnbcaeplbcioakkpcpgfkobkghlhen/14.752.848_0/src/popup.html
/home/softech/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/additional-feature.html
/home/softech/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/background.html
/home/softech/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/edit.html
/home/softech/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/help.html
/home/softech/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/options.html
/home/softech/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/popup.html
/home/softech/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/purchase.html
/home/softech/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/upload.html
/home/softech/.config/google-chrome/Default/Extensions/nlipoenfbbikpbjkfpfillcgkoblgpmj/3.9.16_0/oauth2/oauth2.html
/home/softech/.config/google-chrome/Default/Extensions/nmmhkkegccagdldgiimedpiccmgmieda/1.0.0.2_0/html/craw_window.html
/home/softech/.config/google-chrome/Default/Extensions/pkedcjkdefgpdelpbcmbmeomcjbeemfm/5516.1005.0.3_0/cast_route_details.html
/home/softech/.config/google-chrome/Default/Extensions/pkedcjkdefgpdelpbcmbmeomcjbeemfm/5516.1005.0.3_0/feedback.html
/home/softech/.config/google-chrome/Default/Extensions/pkedcjkdefgpdelpbcmbmeomcjbeemfm/5516.1005.0.3_0/cast_setup/devices.html
/home/softech/.config/google-chrome/Default/Extensions/pkedcjkdefgpdelpbcmbmeomcjbeemfm/5516.1005.0.3_0/cast_setup/index.html
/home/softech/.config/google-chrome/Default/Extensions/pkedcjkdefgpdelpbcmbmeomcjbeemfm/5516.1005.0.3_0/cast_setup/offers.html
Then you can get 20 files end with .html
3.Reveal The Number of Suiting Entries
If you want to get the number of matching entries of file "softech", then use the locate -c command.
$ locate -c [softech]*
900
4. Neglect Case Sensitive Locate Outputs
As the locate is configured to treat queries in a case-sensitive manner you may get another result(for example, got TEXT.TXT instead of text.txt).
To have locate command overlook case-sensitivity and present results for both uppercase and lowercase queries, input commands with the -i option.
$ locate -i *text.txt*
/home/softech/TEXT.txt
/home/softech/text.txt
5. Renew mlocate Database
As locate command relies on a database called mlocate.
mlocate database wants to be refreshed regularly for the command utility to run efficiently.
Have to use the utility upatedb to update mlocate database.
It should be noted that you will require superuser rights for this to work well, it wants to be performed as root or sudo privileges.
$ sudo updatedb
6. Present Only Files Being in Your System
locate command may deliver results of files thats physical copies are deleted from your system when you updated mlocate command.
Have to use the locate-e command to avoid arise of files not being in your system at the time of punching in the command.
The process examines your system to confirm the presence of the file you’re looking for even if it is present in your mlocate.db.
$ locate -i -e *text.txt*
/home/softech/text.txt
7. Separate Output Entries Without New Line
locate command’s default separator is the newline (\\n) character.
If you favor to use a different separator like the ASCII NUL, you can do so applying the -0 command-line choice.
$ locate -i -0 *text.txt*
/home/softech/TEXT.txt/home/softech/text.txt
8.Analyze Your Locate Database
If you’re in doubt as to the current status of your mlocate.db, you can see the locate database statistics by using the -S command.
$ locate -S
Database /var/lib/mlocate/mlocate.db:
32,246 directories
4,18,850 files
2,92,36,692 bytes in file names
1,13,64,319 bytes used to store database
9. Defeat Error Messages in Locate
When you continually trying to access your locate database, it may result in an error message showing that you have no required rights to access the mlocate.db, which means you are not a superuser.
To completely do away with this message, use the -q command.
$ locate "\.dat" -q
10. Keep a Different mlocate Location
If you’re entering queries looking for results not being in the default mlocate database and desire answers from a different mlocate.db located someplace else in your system, you can point the locate command to a different mlocate database at a different part of your system with the -d command.
$ locate -d <new db path> <filename>
locate command might appear like one of those services that does everything you requested it to do without much of a hustle for the process to keep its efficiency, the mlocate.db needs to be filled with information now and then.
Failure to do so might perform the program a bit useless.