3.3.3.2. Which
A very simple way of looking up files is using the which command, to look in the directories listed in
the user's search path for the required file. Of course, since the
search path contains only paths to directories containing
executable programs, which doesn't work for
ordinary files. The which command is useful
when troubleshooting "Command not Found"
problems. In the example below, user tina can't use the
acroread program, while her colleague has no
troubles whatsoever on the same system. The problem is similar to
the PATH problem in the previous part: Tina's colleague tells her
that he can see the required program in /opt/acroread/bin, but this directory is not in her
path:
tina:~> which acroread
/usr/bin/which: no acroread in (/bin:/usr/bin:/usr/bin/X11)
|
The problem can be solved by giving the full path to the command
to run, or by re-exporting the content of the PATH variable:
tina:~> export PATH=$PATH:/opt/acroread/bin
tina:~> echo $PATH
/bin:/usr/bin:/usr/bin/X11:/opt/acroread/bin
|
Using the which command also checks to
see if a command is an alias for another command:
gerrit:~> which -a ls
ls is aliased to `ls -F --color=auto'
ls is /bin/ls
|