This section provides you with some tips for getting help on the command line. The commands --help and man are the two most important tools at the command line.
Virtually all commands understand the -h (or --help) option, which produces a short usage description of the command and its options, then exits back to the command prompt. Try man -h or man --help to see this in action.
Every command and nearly every application in Linux has a man (manual) file, so finding such a file is as simple as typing man command to bring up a longer manual entry for the specified command. For example, man mv brings up the mv (move) manual.
Some helpful tips for using the man command include the following.
- Arrow keys: Move up and down the man file by using the arrow keys.
- q: Quit back to the command prompt by typing q.
- man man: man man brings up the manual entry for the man command, which is a good place to start!
- man intro: man intro is especially useful. It displays the Introduction to User Commands, which is a well-written, fairly brief introduction to the Linux command line.
There are also info pages, which are generally more in-depth than man pages. Try info info for the introduction to info pages.
Searching for Man Files
If you aren't sure which command or application you need to use, you can try searching the man files.
- man -k foo: This searches the man files for "foo". Try man -k nautilus to see how this works.
Note: man -k foo is the same as the apropos command.
- man -f foo: This searches only the titles of your system's man files. Try man -f gnome, for example.
Note: man -f foo is the same as the whatis command.
Sometimes you need to look at or use multiple files at the same time. For instance, you might want to delete all .rar files or move all .odt files to another directory. Thankfully, you can use a series of wildcards to accomplish such tasks.
- * matches any number of characters. For example, *.rar matches any file with the ending .rar.
- ? matches any single character. For example, ?.rar matches a.rar but not ab.rar.
- [characters] matches any of the characters within the brackets. For example, [ab].rar matches a.rar and b.rar but not c.rar.
- [!characters] matches any characters that are not listed. For example, [!ab].rar matches c.rar but not a.rar or b.rar.
Executing Multiple Commands
Often you may want to execute several commands together, either by running one after another or by passing output from one to another.
If you need to execute multiple commands in sequence but don't need to pass output between them, there are two options based on whether or not you want the subsequent commands to run only if the previous commands succeed or not. If you want the commands to run one after the other regardless of whether or not preceding commands succeed, place a ; between the commands. For example, if you want to get information about your hardware, you could run lspci ; lsusb, which would output information on your PCI buses and USB devices in sequence.
However, if you need to conditionally run the commands based on whether the previous command has succeeded, insert && between commands. An example of this is building a program from source, which is traditionally done with ./configure, make, and make install. The commands make and make install require that the previous commands have completed successfully, so you would use ./configure && make && make install.
The Linux Command Line
If you need to pass the output of one command so that it goes to the input of the next, after the character used between the commands, you need something called a pipe, which looks like a vertical bar or pipe (|).
To use the pipe, insert the | between each command. For example, using the | in the command ls | less allows you to view the contents of the ls more easily.
Moving to More Advanced Uses of the Command Line
There are a great number of good books out there for working the command line. In addition, because most of the command line has not changed in many years, a large body of information is available on the Internet. If you need help with something, often simply searching for the command will turn up what you need.
To get you started, here are some recommendations.
- A Practical Guide to Linux Commands, Editors and Shell Programming by Mark G. Sobell (Prentice Hall, 2005) is a good book for any user of the shell in Linux to have on his or her bookshelf.
- LinuxCommand.org is an excellent Web site designed to help people new to using the command line.
- The Linux Documentation Project is an excellent and free resource for many things Linux.
This content was excerpted from the new second edition of The Official Ubuntu Book, authored by Benjamin Mako Hill and Jono Bacon, with Ivan Krstic, David Murphy, Jonathan Jesse, Peter Savage and Corey Burger, published by Prentice Hall Professional, July 2007. Copyright 2007 Canonical Ltd., all rights reserved.
- Enable secure remote access to 3D data without sacrificing visual perfomance Design and manufacturing companies must adapt quickly to the demands of an increasingly global and competitive economy. To speed time to market for...
- The Truth About Virtual Computing for CAD If you're a user of graphics-intensive software such as 3D modeling, simulation and analysis, and visualization, you might be skeptical about moving to...
- Virtually Delivered High Performance 3D Graphics "A picture is worth a thousand words." That old phrase is as true today as it ever was. Pictures (i.e., those with heavy...
- Simplifying Product Design In A Complex World Product design engineering has moved far beyond the confines of ever-more powerful workstations. Companies can't afford to restrict projects to using only local...
- What should I look for in a Next Generation Firewall? SANS Provides Guidance With so many vendors claiming to have a Next Generation Firewall (NGFW), it can be difficult to tell what makes each one different....
- Why Are Customers Really Deploying an NGFW? It seems every IT Security expert is talking about the NGFW, but what are people really doing? This webcast covers 5 real-world customer... All Linux and Unix White Papers | Webcasts