Chapter 1: Pathnames
This chapter contains information on locating files that reside at some location in the file system.
Using “whence”
There are two main methods of finding files, assuming you know the name of the file you're looking for.
The first method is to use the Korn-shell command whence, which tells you where commands reside (if
you're not using the Korn shell, you can use the system command whereis):
$ whence mknod
/etc/mknod
The above approach, while satisfactory in many cases, has two limitations:
• First, the directory in which the command resides must be one of the entries in the PATH
variable; if it is not, it won't be found. So in a sense, whence and whereis can only find things if
you tell them where to look. They are still valuable, though: you may not remember which, of
the dozens of directories that may be in your PATH variable, is where a particular command
resides. Also, if you have two commands of the same name in two different directories, whence
and whereis will tell you which one will be found first, and thus executed.
• Secondly, both whence and whereis only find executable files; that is, commands (both compiled
programs and shell scripts). If you want to find a file that is not executable, an include file, for
instance, whence and whereis will not find it, even if the include file's directory is in your PATH.
To find non-executable files, you can use find, discussed below.
Using “find”
The find command will find any file in your file system, executable or not. For example, to locate the
include file we couldn't locate above, you could say:
$ find / -name '<file_name>'
where <file_name> is the name of the file you're looking for. In the above example, the "/" is the root
directory, and everything is under that, so assuming you specified the correct file name, and it is
somewhere in the file system, the above command is guaranteed to find what you're looking for, though
it might take a while. You can shorten the search time by giving a subdirectory here, if you know it; for
example, "find /opt ...". Also, you can specify just a partial filename; find will locate all files containing
a specified substring in their names. The find command has many other options for refining a search; see
the reference page for details.
Graphics Administration Guide for HP-UX 10.20
Page 10