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.
- Maintain Less. Create More. Spend less on maintenance and spend more time creating with Red Hat Enterprise Linux. Read on to learn how Red Hat can help...
- Flying High on the Use of Red Hat Enterprise Linux Flybe was one of the 21 companies that were interviewed for quantitative results on their operations as part of an IDC ROI analysis....
- SANS: Next-Generation Datacenters = Next-Generation Security This whitepaper takes a look at some new technology that may allow security teams to implement more flexible and capable protection models in...
- SANS: Protecting Virtual Endpoints with McAfee Server Security Suite Essentials SANS review of McAfees Server Security Suite Essentials that address some of the emerging challenges of securing virtual platforms and cloud environments.
- Is SQL Server AlwaysOn really as powerful? Tips and Tricks from the field With the introduction of AlwaysOn, Windows Clustering Services is now more critical than ever.
- What Does it Take to Deliver a Superior Customer Experience? The Two Top-Rated Online Retailers, B&H Photo and Crutchfield Electronics, Share Their Secrets Discuss practical CX tools and service methods such as contact center agents and the use of realtime speech analytics to help contact center... All Linux and Unix White Papers | Webcasts