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.
- Silicon Valley's 19 Coolest Places to Work
- Is Windows 8 Development Worth the Trouble?
- 8 Books Every IT Leader Should Read This Year
- 10 Hot Hadoop Startups to Watch
- Slideshow: 7 security mistakes people make with their mobile device
- iOS vs. Android: Which is more secure?
- 11 sure signs you've been hacked
- Logicalis eBook: SAP HANA: The Need for Speed Without timely business insights, organizations today can suffer logistical, manufacturing, and even financial disaster in a matter of minutes
- Neustar 2014 DDoS Attacks and Impact Report For the third consecutive year, Neustar surveyed hundreds of companies on distributed denial of service (DDoS) attacks. The survey reveals evidence that the...
- Acxiom Case Study This case study, which focuses on Acxiom, explores how the company was able to secure employee data, reduce migration costs and boost productivity...
- Windows® XP Migration: Protect and Secure Critical Data With the end of the Microsoft Windows XP operating system's lifecycle on April 8, 2014, businesses are faced with the decision to migrate...
- Top 4 Digital Signage Fails Join RMG Networks for a look at four of the most common reasons digital signage fails in corporate businesses. Learn about strategies to...
- Building Tomorrow's Infrastructure Listen to this podcast to discover how Crider Foods worked with PC Connection to update their IT infrastructure, while maintaining compliance and control. All Linux and Unix White Papers | Webcasts