Language Selection

English French German Italian Portuguese Spanish

CLI Magic: locate, slocate, and rlocate

Filed under
Linux

Slocate and locate both do essentially the same thing: search a database containing the file names and locations on the system for a match and report all that are found. Both count on another program -- updatedb -- to do the heavy lifting by creating/maintaining the database to be searched. Slocate provides greater security by storing the permissions and ownership of each file, and then only showing the files that the user running the slocate request has permission to access.

The format of the locate/slocate is simple: locate options pattern. It's a good idea to be as specific as possible with the search pattern, because locate will list every file name it finds that contains a match. If I use locate to search my SUSE 9.3 desktop system for mono, like this:

locate mono

It responds with over 400 lines of output. But if I search for libmono instead of simply mono, locate returns only 3 matches.

If you're only interested in how many times the pattern is found, you can specify the -c option in your search, like this:

locate -c mono

File names in Linux are -- sometimes infuriatingly so users who are new to Unix -- case sensitive. Trying to remember if a file name is whereami, WhereamI, or WhereAmI before searching for it can add frustration to the task. Tell locate that you are an insensitive lout who is totally case insensitive by adding the -i option to the search, like this:

locate -i whereami

Updating the database

Since updatedb normally runs just once a day, sometimes you need to find a file that has been created since the last update. When that's the case, just enter the command updatedb as root and let it run. It may take several minutes to complete, or even longer if you have a large number of files to be accounted for.

Full Article.

More in Tux Machines

Tanglu 3.0 Alpha Out Now Based on Debian 8 Jessie, Offers GNOME 3.16 and KDE Plasma 5

Matthias Klumpp announced today, April 18, the immediate availability for download and testing of the first Alpha version of the upcoming Tanglu 3 Linux operating system. Read more

EXT4 In Linux 4.1 Adds File-System Level Encryption

The EXT4 file-system updates for the Linux 4.1 kernel have been sent in and it features the file-system-level encryption support. Earlier this month we wrote about the newly-published patches for EXT4 encryption support coming out of Google and intended to land in the next major release of Android. Those patches for file-system-level encryption will now be landing upstream with the Linux 4.1 kernel update. Besides this native encryption support for EXT4, the rest of the updates for this merge window pull request equate to mainly fixes. More details via the pull request itself. Read more

Manjaro Linux 0.8.13 Pre1 Released for Testing with KDE Plasma 5.2.2 and Xfce 4.12

The Manjaro development team announced that the first Preview release of the upcoming Manjaro Linux 0.8.13 operating system is now available for download in Xfce and KDE Live CD flavors. Read more