The which, whereis and whatis commands on a Linux system provide information about commands. They provide related but not identical information. In this post, we\u2019ll check out the differences and provide a script for getting information that\u2019s available from all three commands. We\u2019ll also explore some sample commands for looking at secondary (i.e., not section 1) man pages.\nwhich\nThe which command will show you the file-system location for a command\u2019s executable. This is the file that is read and run whenever you type the command name.\n$ which date\n\/usr\/bin\/date\n$ which shutdown\n\/usr\/sbin\/shutdown\n\n\nThe which command will also report on your aliases and show you the commands they invoke.\n$ which recent\nalias recent=\u2019ls -ltr | tail -10\u2019\n \/usr\/bin\/ls\n \/usr\/bin\/tail\n\nwhereis\nLike which, the whereis command will show you the file=system location for the executable associated with a command, but it will also tell you where the man (manual) pages are located.\nIn the example below, there are two or three man pages for each of the commands.\n$ whereis date\ndate: \/usr\/bin\/date \/usr\/share\/man\/man1\/date.1.gz \/usr\/share\/man\/man1p\/date.1p.gz\n$ whereis shutdown\nshutdown: \/usr\/sbin\/shutdown \/usr\/share\/man\/man2\/shutdown.2.gz \/usr\/share\/man\/man3p\/shutdown.3p.gz \/usr\/share\/man\/man8\/shutdown.8.gz\n\nwhatis\nThe whatis command provides brief descriptions of commands. Each description is associated with one of the man pages for that command as shown in the example below.\n$ whatis date\ndate (1) - print or set the system date and time\ndate (1p) - write the date and time\n$ whatis shutdown\nshutdown (2) - shut down part of a full-duplex connection\nshutdown (3p) - shut down socket send and receive operations\nshutdown (8) - Halt, power-off or reboot the machine\n\nTo view the primary man page for any command, just type \u201cman\u201d plus the name of the command, for example, \u201cman date\u201d. Add the man page section (e.g., \u201cman 3p shutdown\u201d) for a different man page section. Note that at the top of the man page you will see a confirmation of the command and the particular man page section:\n$ man 3p shutdown\n\nSHUTDOWN(3P) POSIX Programmer\u2019s Manual SHUTDOWN(3P)\n\nPROLOG\n This manual page is part of the POSIX Programmer\u2019s Manual. The Linux\n implementation of this interface may differ (consult the corresponding\n Linux manual page for details of Linux behavior), or the interface may\n not be implemented on Linux.\n\nNAME\n shutdown\u2014shut down socket send and receive operations\n\nSYNOPSIS\n #include \n\n int shutdown(int socket, int how);\n\u2026\n\n(The output above has been truncated.)\nMan pages are organized into as many as 9 sections:\n1 Executable programs or shell commands\n2 System calls (functions provided by the kernel)\n3 Library calls (functions within program libraries)\n4 Special files (usually found in \/dev)\n5 File formats and conventions, e.g. \/etc\/passwd\n6 Games\n7 Miscellaneous (including macro packages and conventions), e.g.\n man(7), groff(7)\n8 System administration commands (usually only for root)\n9 Kernel routines [Non standard]\n\nYour search path matters\nYou can run all three of the which, whereis and whatis commands any time you want to know a little more about the commands you\u2019re running and where they are stored on your system. If you run a command and get an unexpected response, checking out what executable you\u2019re dealing with can be important.\n$ date\nNo thanks. I\u2019m not into dating.\n$ which date\n~\/bin\/date\n\nHmm! Something\u2019s just a little off in that example. While you\u2019re very unlikely to get a response like that shown, it is possible to have two executables on a system with the same name. In this case, which one you end up running will at least in part depend on your search path. Your personal bin directory should probably not be sitting in the first position in your $PATH variable nor should \u201c.\u201d (current position) because of the risk of running a command other than what you intended.\n$ echo $PATH\n~\/bin:\/usr\/bin:\/usr\/local\/sbin:\/usr\/sbin\n\nUsing all three commands\nThe script below will run all three commands and display the output in a useful format. In fact, it can accept a list of commands and display the command output for looking into each of them.\n#!\/bin\/bash\n\nclear\n\nif [ $# == 0 ]; then # if no arguments provided, prompt user\n echo -n \u201cWhat command(s) are you asking about?> \u201c\n read args\nelse\n args=$*\nfi\n\nfor cmd in `echo $args` # for each command entered\ndo\n echo \u201c$cmd\u201d\n echo -n \u201cexecutable: \u201c\n which $cmd\n echo -n \u201call files: \u201c\n whereis $cmd | sed \u201cs\/$cmd: \/\/\u201c\n echo \u201cfunction(s):\u201d\n whatis $cmd\n echo \u201c====================================================================\u201d\ndone\n\nHere\u2019s an example of running the script for two commands:\n$ about date shutdown\ndate\nexecutable: ~\/bin\/date\nall files: \/usr\/bin\/date \/home\/shs\/bin\/date \/usr\/share\/man\/man1\/date.1.gz \/usr\/share\/man\/man1p\/date.1p.gz\nfunction(s):\ndate (1) - print or set the system date and time\ndate (1p) - write the date and time\n====================================================================\nshutdown\nexecutable: \/usr\/sbin\/shutdown\nall files: \/usr\/sbin\/shutdown \/usr\/share\/man\/man2\/shutdown.2.gz \/usr\/share\/man\/man3p\/shutdown.3p.gz \/usr\/share\/man\/man8\/shutdown.8.gz\nfunction(s):\nshutdown (2) - shut down part of a full-duplex connection\nshutdown (3p) - shut down socket send and receive operations\nshutdown (8) - Halt, power-off or reboot the machine\n====================================================================\n\nWrap-Up\nThe where, whereis and whatis commands provide useful summaries of commands, showing where the executables are located and pointing to the relevant man pages. The which command can also verify which executable you are using when you type a command name.\nConsult the man pages to learn about all the options available and get a more complete explanation of how these commands work.