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

Video: Systemd the Core OS (no coughing)

There has been so much negative stuff about systemd on teh Interwebs lately. It is so sad. Quite a few distros picked systemd because they liked a lot of the features it has. Why do the people who like systemd actually like it? Sure, if you look hard enough, you can find those answers... but I remembered a video where the man himself explains it. Read more

GParted 0.20 Improves Btrfs Support

GParted 0.20.0 is out today with a release that primarily improves Btrfs support. The improved Btrfs support comes via now handling support for resizing Btrfs file-systems that span multiple devices. GParted 0.20 also has GRUB2 restoration steps added to the help manual plus various translation updates. Read more

Ubuntu Touch RTM Update Is Out, Has Better Performance and Beautiful New Indicators

Ubuntu developers had some minor problems in the week before with all sorts of bugs that were popping out. They postponed the release of a new update for the Ubuntu Touch RTM and, at one point, they even got everyone to focus on fixing the problems and nothing else. Now they have a new version out and progress really shows. Users who already have Ubuntu Touch on their phones might have noticed that the number of features added to the system have diminished drastically, but that's the way it should be. The system is getting closer to its final stages and there is little reason to add new options now. The current form of the OS is not very far from the official release, so only fixes remain to be made. Read more

Ubuntu turns 10: A look back at desktop Linux standard bearer

Tech pundits differ, to say the least, on a lot of topics in the world of free and open-source software, but it’s inarguable that Ubuntu has been the most influential Linux desktop distribution of the past decade. On the occasion of its 10th anniversary, here’s a brief look back. Read more