- Starting Up the Terminal
- Getting Started
- Building Pipelines
- Running Commands as the Superuser
- Finding Help
- Moving Around the Filesystem
- Manipulating Files and Folders
- System Information Commands
- Searching and Editing Text Files
- Dealing with Users and Groups
- Getting Help on the Command Line
- Searching for Man Files
- Using Wildcards
- Executing Multiple Commands
- Moving to More Advanced Uses of the Command Line
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.
Running Sequentially
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.
Using Byobu to Manage Your Terminal
One of the challenges of using the terminal is the difficulty of managing multiple screens. If you are in a desktop environment, you can launch another terminal window or use GNOME terminal's tabbed terminals, but that doesn't work everywhere.
Thankfully, such a tool to help you does exist: byobu. Japanese for screen, byobu is a set of default configurations for the GNU screen command. Essentially, screen is a window manager for the command line. Since 9.10, this great tool has been installed by default, so all you need to do is launch the byobu command in a terminal.
After it is started, you will notice you are back at a terminal prompt, but with a few differences. At the bottom are two lines of information. The bottom line shows you the version of Ubuntu you are currently running, how long you have logged in, the system load, the CPU speed, the current memory usage, and the current time. The upper bar shows the current logged-in user and, on the right, the list of open windows (Figure A-2).
Figure A-2 Byobu in GNOME terminal
You can now use your terminal exactly as you normally would, just with a few added pieces of information. Advanced usage of byobu (and screen) is a topic too large for this appendix, but following are a few commands to get you started:
F2: |
Open new terminal window. |
F3/F4: |
Move backward/forward through the list of windows. |
F6: |
Detach from current byobu session. To reattach, use byobu -x. |
F7: |
Scroll back through the output. Hit Esc to exit this mode and return to the command prompt. |
F9: |
menu. |
Using Byobu by Default in GNOME Terminal
To have GNOME terminal launch byobu by default when it starts, you need to edit the preferences, which can be found at Edit > Profile Preferences under the Title and Command tab. Tick the box "Run a custom command instead of my shell," and enter byobu in the line below. Now when you launch GNOME terminal, byobu will launch with it, and closing byobu will close GNOME terminal as well.