Finding Files with an Index
Linux provides an easy way to create an index of files for fast future searching.
updatedb would have been used in the past, and still can be, but a newer implementation just uses it as an alias to call slocate with a switch. What's slocate? It stands for secure locate and is like the original locate command, which searches through the index for a given file, except that it doesn't list files that one has no permission to view.# slocate -u # update file indexOnce the file index is up to date, one can find any given file quickly using the following command.
$ slocate filename # locate any file with filename in its nameYou may wish to review the man page for
slocate as well because this command supports things like case insensitive search and regular expressions!Finding Files without an Index
But what if we don't have an index of which to search through for the desired files? We can still use the
find command. Here's an example:$ find / -iname filenameHere,
find is instructed to start searching at the root of the file tree for files with the name of filename, while ignoring their case.Binary Files
whereis is a great command for locating binary files that are stored in a standard path. For example, if we want to find where the ls command is:$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gzThis tells us that the
ls command has the path of /bin and the man pages are located in /usr/share/man/man1/ls.1.gz.Finding Commands
There are times when one may wish to find a suitable program for a given task. For example, I may wish to find commands that deal with searching.
$ apropos search
apropos (1) - search the manual page names and descriptions
badblocks (8) - search a device for bad blocks
bzegrep (1) - search possibly bzip2 compressed files for a regular expressionHere
apropos shows us that apropos itself, badblocks, and bzegrep can be used to search for different types of things. Remember, if you install new programs with new man pages, be sure to run mandb to update the list that apropos searches through.

No comments:
Post a Comment