Use I/O redirection to perform the following tasks in the specified order:

  1. Write line containing the word COMPUTER to the text file output.txt. If the current directory already contains a file output.txt, the file must be overwritten.

    Tip

    In Unix, it is standard that each line of a text file ends with a newline. This is also the definition for a line in the POSIX standard1:

    3.206 Line

    A sequence of zero or more non- <newline> characters plus a terminating <newline> character.

    According to this convention, all text files (except empty ones) end with a newline, because there must also be a newline after the last line. Many Unix commands will not work properly for text files that do not follow this convention.

  2. Download the text file reservoir.txt2 using the command wget or the command curl. Make sure that all output generated by the command is immediately discarded. In other words: the output the command generates may never be displayed in the terminal or written to a file.

    Tip

    Try to find out what you can do with the file /dev/null. What kind of file is this?

  3. Append the contents of the text file reservoir.txt3 to the text file output.txt, without the existing content of the file output.txt being overwritten. Any possible error messages must be written to the text file error.txt.

  4. Write the output of the command whoami — along with any possible error messages — to the text file userinfo. What information is generated by this command? What possible applications could this command support?

    Tip

    First try to predict the result of the next three commands and then execute the commands to see if your predictions are correct. We assume that the current directory does not contain a file named xxx. Explain the differences in the output of these commands.

  5. Execute the following command:

    $ sort xxx 2> userinfo
    
  6. Execute the following command:

    $ sort < xxx 2> userinfo
    
  7. Execute the following command:

    $ < xxx 2> userinfo sort