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 commandcat < /tmp/output > /tmp/output
?Run the commands
$ echo Howdy > /tmp/output $ cat < /tmp/output >> /tmp/output
What do you notice?
Explain!
How many subdirectories does your home directory contain? Hint: combine
find
undwc
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
, andmkfifo
, send the word “Howdy” in circles such thatcat
consumes as much CPU time as it can get.