Learning Linux Commands
If you are a complete newbie to Linux, or if you “know enough to be dangerous,” then here are some pointers that may help.
One of the great things about Linux is that, even though the operating system is extensible through the addition of arbitrary commands, there are standards for documenting such commands. Because of these standards, not only is it easy to find out what a command does and how it works, but it’s easy to find out that these commands exist in the first place, even if you don’t know their names.
Commands About Commands:
- man — Display the manual for a command
- whatis — Display a summary of a command (rather than the entire manual)
- apropos — Display a list of commands that pertain to (are apropos to) a keyword
- whereis — Display information about the location of a command: the executable, the source code (if any), and the man pages.
- which — Display which version of a command will execute (for when there are two, or more, commands with the same name installed on the system). See also the type command.
- type — Display how a name would be interpreted if used as a command. In other words, what type of resource is it? (Actually does a more thorough job of distinguishing between multiple resources with the same name than the “which” command.)
MAN — In previous tips, we mentioned the MAN command. MAN stands for manual. It is the main resource for displaying the documentation (a.k.a. “man pages”) for any particular command. For example, to find out how the LS command works, you would enter
The man command brings up the first page of the manual, and then waits for navigation keystrokes. The most commonly used navigation controls are PageUp, PageDown, Home, End and the letter q (quit). Of course, man has its own man pages.
WHATIS — The whatis command is actually an alias for using the man command with the -f switch (and -f is shorthand for –whatis). So, all of the following are equivalent.
whatis ls man -f ls man --whatis ls
APROPOS — The man pages for any given command usually includes a section of relevant keywords. The apropos command searches through all of the keywords listed in all of the man pages, and reports on any hits.
The apropos command is actually an alias for using the man command with the -k switch (and -k is shorthand for –apropos). So, all of the following are equivalent. (I find that it’s easier to remember “man -k” (where K stands for keyword), than it is to remember the word “apropos”.)
apropos ls man -k ls man --apropos ls
WHEREIS — The whereis command is immensely helpful for working with extended commands, i.e. commands that were not part of the original distribution (”distro”). The whereis command can tell you if, indeed, the command is installed on your system, and if so, where (so that you know how to invoke it). It shows you the location of any command executable, source code, and/or man pages that match the name given. Note: If you only care about searching for the command executables, then add “-b” to tell it to only search for binaries.
WHICH and TYPE — On the occasion that there happens to be two different versions of a command (that is, two different command executables with the same name), the which command tells you which version will actually be executed if you were to enter the command name alone (without specifying its exact location). For example, my installation of CygWin (a Linux emulator for Microsoft Windows), has two different “grep” commands installed.
Even better is the “type” command. Whereas the which command only looks for binary executables of the specified name, the type command considers that the specified name might also be a command alias or a function that would take precedence. Using type without any options returns a detailed answer (i.e. for the question, “what type of resource is this?”)
$ type grep grep is /usr/bin/grep $ type type type is a shell builtin
Using type with an option of -t returns a terse answer, one of these five words: alias, keyword, function, builtin, or file.
$ type -t grep file $ type -t type builtin
(The -t option is useful for checking a resource type within a shell script.)
Note: “man type” displays a combined man page for all bash builtin commands, listed alphabetically. So, use PageDown (or End and PageUp) to get to the description of the type command.
As an aside, I was about to mention what the grep command does. Instead, I think I’ll leave finding that out as an exercise to the reader.
- Use Linux Commands and Shell Scripts directly in Windows
- Quick Tip: Searching for Files in Linux (or Windows)
Read more: Linux