-->
Page 47
you'll see
/usr/bin
Although there's a man page for the pwd command, chances are that when you use pwd, you're using a pwd built into your shell. How do you tell? If you try calling pwd with the following command, you should see only the current working directory printed:
# pwd --help
Instead, try calling pwd with
# /bin/pwd --help
You'll see a short help file for the pwd command, and not the current directory.
The find command is a powerful searching utility you can use to find files on your hard drive. You can search your hard drive for files easily with a simple find command line. For example, to search for the spell command under the /usr directory, you would use
# find /usr -name spell -print
You can also use the find command to find files by date; you can also specify a range of times. For example, to find programs in the /usr/bin directory that you have not used in the last one hundred days, you can try:
# find /usr/bin -type f -atime +100 -print
To find any files, either new or modified, that are one or fewer days old in the /usr/bin directory, you can use
# find /usr/bin -type f -mtime -1 -print
The find command will also accept wildcards, which you'll learn about in Hour 5, "Manipulation and Searching Commands." As a simple example, you can use find to show you all the PostScript files (which you'll learn about in "Understanding Graphics Formats" in Hour 16, "Graphics Tools") in your /usr directory with
# find /usr -name `*.ps' -print
You should also know about one of the find command's handy options, -xdev. The examples so far show searches limited to the /usr directory. But what if you want to search starting at the root or / directory? Without using -xdev, which limits searches to the current filesystem (in this case, Linux), find will merrily continue its search through any mounted CD-ROMs, or your DOS or Windows partition, possibly finding files you're not interested in, slowing down the search, and cluttering up the search printout.
Page 48
The find command has many different options and uses. For more details about find, see its manual page. Although find will rapidly search your hard drive (and any other filesystems), there are other ways of quickly finding files, especially programs. Read on to find out more!
The whereis command can quickly find files, and it also shows you where the file's binary, source, and manual pages reside. For example, the following command shows that the find command is in the /usr/bin directory, and its man page is in the /usr/man/man1 directory:
# whereis find find: /usr/bin/find /usr/man/man1/find.1
You can also use whereis to find only the binary version of the program with
# whereis -b find find: /usr/bin/find
If whereis cannot find your request, you'll get an empty return string, for example:
# whereis foo foo:
Part of the problem could also be that the file is not in any of the directories the whereis command searches. The directories whereis looks in are hard-coded into the program. Although this may seem like a drawback, limiting searches to known directories such as /usr/man, /usr/bin, or /usr/sbin can speed up the task of finding files.
Although whereis is faster than using find to locate programs or manual pages, there's an even faster search utility you can use, called locate, discussed in the next section.
One way to speed up searches for files is not to search your file directories! You can do this by using a program like locate, which uses a single database of filenames and locations, and which saves time by looking in a single file instead of traversing your hard drive. Finding a file using locate is much faster than the find command because locate will go directly to the database file, find any matching filenames, and print its results.
Locate is easy to use. For example, to find all the PostScript files on your system, you can enter
# locate *.ps
Almost instantly, the files are printed to your screen. You may even find the locate command line a little easier to use than the find command. However, there is a catch: find will work "right out of the box," whereas with locate, you need to first build a database of all the files on your system. But don't worry, because the procedure is almost automatic.
Page 49
After you install Linux, locate can't show any search results because it can't locate its database. To create this database, you'll need to use the updatedb command. Make sure you're logged in as the root operator (or use the su command; see Hour 20, "Basic System Administration"). At the prompt, enter
# updatedb
It may take a minute or so for the updatedb command to finish its work, but when it's done, locate's database, locatedb (about 300,000 characters in size for 400MB worth of files), will reside in the /var/lib directory. The only downside to using the locate command is that after time, its database could become out of date as you add or delete files to your system. However, you can have its database updated automatically; see the command reference section at the end of this hour.
As you first explore your Linux system, you may come across programs whose function is not clear. Many Linux programs are designed to give at least a little help with a ? or -help option on the command line, but you generally shouldn't run a program without knowing what it does.
The whatis command may be able to help you quickly find out what a program is with a summary line derived from the program's manual page. For example, to find out what is whereis (not whereis whatis!), you can enter
# whatis whereis whereis (1)- locate the binary, source, and manual page files for a command
However, as with the locate command, you must first build a database of the command summaries with the makewhatis command, found under the /usr/sbin directory. To do this, make sure you're logged in as root, and enter
# makewhatis
The makewhatis command, like the updatedb command, will take a few minutes to build the whatis database, which, unlike locate's, is called whatis and is found under the /usr/man/man1 directory. The makewhatis command has several options, but it does not have a manual page. To see a quick summary, use
# makewhatis -?
Also, as with locate's database, you'll need to periodically update the whatis database to keep track of any newly installed programs.
So far, you've seen how whereis and whatis can help you find programs or figure out what they