This document describes three commands for searching for files/directories. For additional information about these commands, log onto an EECS machine and type man command.
This section describes two commands to search for files in specific directories – one for Unix and Linux, and the other specifically for Linux.
The find command searches for files in specific directories. The basic syntax for find is:
find path expression
The path argument is the starting directory from which find will search. The expression argument describes the type of file to find. Here are some examples:
||Finds all files in the
||Finds all files in your home area (
||Finds all directories (denoted by
You can also use wildcards to search for filenames containing a certain pattern:
||Finds all files in your home area with a name containing the phrase homework.|
There are many more options for find; consult the manual page for more information.
Under Linux, the locate command is similar to the find command. Here is an example:
prompt> locate xpdf
By default locate finds any files containing the given search string, whereas wildcards must be used with find (e.g., find *
The which command is similar to find, except which only searches for binaries (i.e., executables) that are located in your shell's command path. The which command is useful for determining which version of an executable you are using. Here is an example:
prompt> echo $PATH
prompt> ls -la /usr/local/gnu/bin/ls /usr/bin/ls
-r-xr-xr-x 1 root bin 18844 Jan 5 2000 /usr/bin/ls
lrwxrwxrwx 1 root root 25 Jan 2 11:36 /usr/local/gnu/bin/ls
prompt> which ls
The first command displays the shell's command path. The second command shows that there are two binaries named ls – one in
/usr/bin and the other in /usr/local/gnu/bin. (Note that both of these directories are in the command path.) The third command shows that the ls command corresponds to
/usr/local/gnu/bin is listed before /usr/bin in the command path, when ls is typed the
/usr/local/gnu/bin/ls is used.
Knoxville, Tennessee 37996 | 865-974-1000
The flagship campus of the University of Tennessee System