Almost all Linux utilities that require input and (Web site template)
Almost all Linux utilities that require input and output have been plumbed withthe following common interfaces: stdin(standard input), stdout(standardoutput), and stderr(standard error). By having a common method to feedinput to a program or read data from the output of a program, you can glueutilities together into sophisticated solutions. Redirecting command outputI discuss redirecting command output here because it s by far the mostcommon form of information detouring. One example of output redirectioninvolves telling a command to send its results to a file rather than to thescreen, as you probably have been used to seeing. Start in some familiar terri- tory by typing ls -la ~and then pressing Enter, to produce something likethe following: total 20drwx—— 2 sue users 4096 Oct 30 07:48 . drwxr-xr-x 5 root root 4096 Oct 30 11:57 .. -rw-r—– 1 sue users 24 Oct 30 06:50 .bash_logout-rw-r—– 1 sue users 230 Oct 30 06:50 .bash_profile-rw-r—– 1 sue users 124 Oct 30 06:50 .bashrc-rw-rw-r– 1 sue users 0 Jan 2 07:48 wishlistWant to send this information to a file instead? You can use the >redirectionoperator to tell bashto send the data into a file instead of onto your screen. Enter the following command to send the information to a file named listing: ls -la ~ > listingNotice that nothing displays on the screen, as you normally would expect. That s because the shell has rerouted the output to a file named listing. To verify that the directory listing is there, enter the following command: cat listingThe cat(and more) is explained Chapter 16. Note that if you type ls -la ~ > listingagain, the data is overwritten, meaning that the file s contents are wiped out and replaced with the newoutput. You can avoid this situation by using >>as your redirection operator, which tells bashto add the command s output to the end of the specified file. If you type ls -la ~ >> listingin the same directory after making nochanges, the contents of listingare as follows: 289Chapter 14: Working without the GUI20_