272 CHAPTER 17 COOL SHELL TRICKS Pressing (Make a web site)

272 CHAPTER 17 COOL SHELL TRICKS Pressing Ctrl+R lets you search the command history from the command prompt. This particular tool can be tricky to get used to, however. As soon as you start typing, BASH will autocomplete the command based on matches found in the history file, starting with the last command in the history. What you type appears before the colon, while the autocompletion appears afterwards. Because BASH autocompletes as you type, things can get a little confusing when you re working with the command history, particularly if it initially gets the match wrong. For example, typing cd will show the last instance of the use of cd, as in the example in Figure 17-2. This might not be what you re looking for, so you must keep typing the command you do want until it autocompletes correctly. Figure 17-2. BASH history completion is very useful but can also be confusing. Piping and Directing Output It s not uncommon for a directory listing or output from another command to scroll off the screen. When using a GUI program like GNOME Terminal, you can use the scroll bars to view the output, but what if you are working at the bare command-line prompt? By pressing Shift+Page Up and Shift+Page Down, you can scroll the window up to take a look at some of the old output, but very little is cached in this way, and you won t see more than a few screens. A far better solution is to pipe the output of the directory listing into a text viewer. Another useful technique is to redirect output to a file. Piping the Output of Commands Piping was one of the original innovations provided by Unix. It simply means that you can pass the output of one command to another, which is to say the output of one command can be used as input for another. This is possible because shell commands work like machines. They usually take input from the keyboard (referred to technically as standard input) and, when they ve done their job, usually show their output on the screen (known as standard output). The commands don t need to take input from the keyboard, and they don t need to output to the screen. Piping is the process of diverting the output before it reaches the screen and passing it to another command for further processing.

Leave a Reply