The which, whereis, file, and whatis commands report information about files and directories.
- which: The which command reports the location of a command:
$ which ls
/bin/ls
- We often use commands without knowing the directory where the executable file is stored. Depending on how your PATH variable is defined, you may use a command from /bin, /usr/local/bin, or /opt/PACKAGENAME/bin.
- When we type a command, the terminal looks for the command in a set of directories and executes the first executable file it finds. The directories to search are specified in the PATH environment variable:
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
- We can add directories to be searched and export the new PATH. To add /opt/bin to PATH, use the following command:
$ export PATH=$PATH:/opt/bin
# /opt/bin is added to PATH
- whereis: whereis is similar to the which command. It not only returns the path of the command, but also prints the location of the man page (if available) and the path for the source code of the command (if available):
$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz
- whatis: The whatis command outputs a one-line description of the command given as the argument. It parses information from the man page:
$ whatis ls
ls (1) - list directory contents
The file command reports a file type. Its syntax is as follows:
$ file FILENAME
- The reported file type may comprise a few words or a long description:
$file /etc/passwd
/etc/passwd: ASCII text
$ file /bin/ls
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1
(SYSV), dynamically linked (uses shared libs), for GNU/Linux
2.6.15, stripped
apropos
Sometimes we need to search for a command that is related to the topic. The apropos command will search the man pages for a keyword. Here's the code to do this: Apropos topic
Sometimes we need to search for a command that is related to the topic. The apropos command will search the man pages for a keyword. Here's the code to do this: Apropos topic