Exercises: IO-Redirection, Pipes

  • Use the cat program (without any commandline parameters) to copy /etc/passwd to /tmp/passwd.

  • Use the echo command (call it multiple times in a row) to create a file that contains your name and your address.

  • Output a sorted list of all users in your system. Hint: /etc/passwd contains all users in the first column - fields are separated with the : character.

  • Redirect standard output and standard error of the command find /etc to /tmp/output.txt

  • Why is the (non-empty) file /tmp/output suddenly empty after running the command cat < /tmp/output > /tmp/output?

  • Run the commands

    $ echo Howdy > /tmp/output
    $ cat < /tmp/output >> /tmp/output
    
    1. What do you notice?

    2. Explain!

  • How many subdirectories does your home directory contain? Hint: combine find und wc in a pipeline.

  • Modify the command find /etc | wc, applying redirections, so that it counts the number of lines on standard error, and standard output is sent to /dev/null.

  • Using echo, cat, and mkfifo, send the word “Howdy” in circles such that cat consumes as much CPU time as it can get.