4.4.3. Pipes

It is also possible to send the output of a command to another command, where it is used as input. A much used example is to send the output of a command to less if it gives more then one screen of output:

% ls -l /usr/bin | less

Here less uses the output of the command ls -l /usr/bin as input, instead of using a file as we have seen before.

In the next chapter we will use this quite often.




Exercises


  1. If you want to monitor the size of a file during the execution of a program, this exercise provides a first step.

    • Set the file to monitor in a variable

    • Display the size of the file and redirect the output to a file.

    • In case the file does not exist yet (for example it is only created later in the execution of the program), redirect the error message to another file.

    Later we will see how to put this command in a loop so that we can monitor the file during some time.

  2. If we don’t know before what the filename will be that we want to monitor, how can we follow the size of the biggest file during the execution of a program ?