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

Android essentials: 13 apps I can't live without

We spend a lot of time talking about Lollipop and OS-level issues with Android -- but you know what's just as important as the operating system on your phone or tablet? The apps that surround it. The right apps can make your device easier and more enjoyable to use. They can give it powers you didn't know were possible. They can make it feel like your own custom-tailored gadget -- whether you've been using it for two minutes or for two years. Read more

GHOST, a critical Linux security hole, is revealed

Researchers at cloud security company Qualys have discovered a major security hole, GHOST (CVE-2015-0235), in the Linux GNU C Library (glbibc). This vulnerability enables hackers to remotely take control of systems without even knowing any system IDs or passwords. Qualys alerted the major Linux distributors about the security hole quickly and most have now released patches for it. Josh Bressers, manager of the Red Hat product security team said in an interview that, "Red Hat got word of this about a week ago. Updates to fix GHOST on Red Hat Enterprise Linux (RHEL) 5, 6, and 7 are now available via the Red Hat Network." This hole exists in any Linux system that was built with glibc-2.2, which was released on November 10, 2000. Qualys found that the bug had actually been patched with a minor bug fix released on May 21, 2013 between the releases of glibc-2.17 and glibc-2.18. Read more

4MLinux Allinone Edition 11.0 Is a Complete OS

4MLinux Allinone Edition, a Linux distro that encompasses multiple tools for Maintenance (system rescue Live CD), Multimedia (e.g. playing video DVDs), Miniserver (using the inetd daemon), and Mystery (Linux games), is finally out of the Beta stages and has reached version 11.0. Read more

White House CTO calls for open source APIs, visibility for women

While Smith’s characterization of Washington as “incredibly entrepreneurial” may be a tad optimistic, she did appear sincere in her support for promoting the use of open source development, and introducing a culture of “APIs, not RFPs.” Echoing a mantra of executives at Google X, Smith also expressed a desire to find ways for the government to exhibit the sort of technological prowess that normally occurs only in wartime. She also emphasized that she and her deputy, former Twitter lawyer Alex Macgillivray, want to reduce the sort of regulatory morass that can inhibit innovation. Read more