11959435-Ubuntu-Kung-Fu

Page 35

S OFTWARE

INSTALLATION AND MANAGEMENT

the two following commands add their output to the end of it. The output of one command can also be piped into another, which is to say, the output of one command can form the input of another. The pipe symbol (|) is used to do this. The most basic example is to pipe the output of the ls command into less, the text viewer: $ ls | less

In other words, rather than sending the file listing to the screen, it’s piped into the less command, so is then displayed on-screen for leisurely scroll-through reading. This can be very useful when you’re working at a virtual console, which lacks those handy scroll bars that GUI programs have. Couldn’t we just redirect the output into less—something like ls > less? No. Redirecting is about sending data into (or from) files. With piping the output is simply transferred from one command to another without the creation of a file. The ls > less command would create a new file called less which contains the file listing. Piping is often used with the grep command, which is able to search through a file for text. For example, say you want to make a list of all the files belonging to a particular project you’re working on. The files are in your Documents folder, along with hundreds of others (for the purposes of this demonstration you aren’t very well organized). One thing is true of all the project files—they have the word “project” in their filename, but that could be at the end, or in the middle, or at the front. If you were an idiot you could type ls and the scroll through the list of results looking for relevant files. However, a better way is to get grep to search for you. We can do this by piping the output of ls straight into it: $ ls | grep -i "project"

What you’ll see, as seen in Figure 2.6, on the next page, is the output of grep which has filtered the output of ls to show only the lines that contain the word “project“ (the -i command option tells grep to ignore upper and lower case letters when searching).

2.4 Software installation and management There’s a lot of software available for Ubuntu, in addition to that which comes installed out of the box, and most of it is not only free but also easily accessible. Because of this it’s possible to suggest that, as far as

Prepared exclusively for J.S. Ash

Report erratum this copy is (B2.0 printing, July 15, 2008)

35


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.