{ "q1": { "type": "blank", "question": "\n

\nWhen a program is executed, it has access to three special files: ____ (1),\n____ (2), and ____ (3). The first is connected to the keyboard, while the second\nand third are attached to the screen or terminal.\n

\n\n

To redirect the contents of a file into a command such as\nmd5sum, we can do:

\n\n
\n$ md5sum ____ file      # (4)\n
\n\n

To redirect the output of a command such as date to a file, we\ncan do:

\n\n
\n$ date ____ file        # (5)\n
\n\n

To append the output of a command such as uname to a file, we\ncan do:

\n\n
\n$ uname -a ____ file    # (6)\n
\n\n

To redirect only the error messages of a command such as find\nto a file, we can do:

\n\n
\n$ find /etc ____ file   # (7)\n
\n\n

To redirect both the output and error messages of a command such as\ndu, we can do:

\n\n
\n$ du /etc ____ file     # (8)\n
\n\n

To redirect the output of a command such as ls to the input of\nanother command such as grep, we can do:

\n\n
\n$ ls /etc ____ grep host # (9)\n
\n" }, "q3": { "type": "blank", "question": "\n

Two useful features in a typical Unix shell are pathname expansion and\nbrace expansion. Given the following output of ls:

\n\n
\n2002-01  2002-07  2003-01  2003-07  2004-01  2004-07  2005-01  2005-07  2006-01  2006-07\n2002-02  2002-08  2003-02  2003-08  2004-02  2004-08  2005-02  2005-08  2006-02  2006-08\n2002-03  2002-09  2003-03  2003-09  2004-03  2004-09  2005-03  2005-09  2006-03  2006-09\n2002-04  2002-10  2003-04  2003-10  2004-04  2004-10  2005-04  2005-10  2006-04  2006-10\n2002-05  2002-11  2003-05  2003-11  2004-05  2004-11  2005-05  2005-11  2006-05  2006-11\n2002-06  2002-12  2003-06  2003-12  2004-06  2004-12  2005-06  2005-12  2006-06  2006-12\n
\n\n

Note: All file names are in the format YEAR-MONTH.

\n\n

Using bash's expansion syntax, complete the following prompts.

\n\n

To list all the files from 2002, we could do:

\n\n
\n$ ls ____ # (1)\n2002-01 2002-02 2002-03 2002-04 2002-05 2002-06 2002-07 2002-08 2002-09 2002-10 2002-11 2002-12\n
\n\n

To list all the files from the month of December, we could do:

\n\n
\n$ ls ____ # (2)\n2002-12 2003-12 2004-12 2005-12 2006-12\n
\n\n\n

To list all the files from the month of January to June, we could do:

\n\n
\n$ ls ____ # (3)\n2002-01  2002-04  2003-01  2003-04  2004-01  2004-04  2005-01  2005-04  2006-01  2006-04\n2002-02  2002-05  2003-02  2003-05  2004-02  2004-05  2005-02  2005-05  2006-02  2006-05\n2002-03  2002-06  2003-03  2003-06  2004-03  2004-06  2005-03  2005-06  2006-03  2006-06\n
\n\n

To list all the files with an even year and odd month, we could do:

\n\n
\n$ ls ____ # (4)\n2002-01  2002-05  2002-09  2004-01  2004-05  2004-09  2006-01  2006-05  2006-09\n2002-03  2002-07  2002-11  2004-03  2004-07  2004-11  2006-03  2006-07  2006-11\n
\n" }, "q2": { "type": "single", "question": "\n

Are the following two pipelines equivalent?

\n\n
\n$ du -h /etc 2> /dev/null | sort -h > output.txt\n
\n\n
\n$ du -h /etc | sort -h > output.txt 2> /dev/null\n
\n", "responses": { "true": "Yes, the pipelines have the same behavior and produce the same output.", "no_error": "No, the first pipeline discards the error messages of the du, while the second pipeline discards the error messages of sort.", "no_store": "No, the first pipeline redirects the output of du to a file and then sorts the file, while the second pipeline pipes the output of du into sort and then stores it into two files.", "no_output": "No, the first pipeline discards the output of du before , while the second pipeline discards the output of the whole pipeline." } }, "q5": { "type": "multiple", "question": "\n

Given the following output of ls -l:

\n\n
\n-rw------- 1 pbui dip 0 Jan 18 07:19 Beastie\n-rwxr-xr-x 1 pbui dip 0 Jan 18 07:18 Huxley\n-rwxr-x--- 1 pbui dip 0 Jan 18 07:18 Tux\n
\n\n

Which files are executable by the owner?

\n", "responses": { "beastie": "Beastie", "tux": "Tux", "huxley": "Huxley" } }, "q4": { "type": "blank", "question": "\n

Two other important features of a typical Unix shell are variables (ie.\nparameter expansion) and command substitution. Using these features,\ncomplete the following prompts:

\n\n

To print all the environment variables in the shell, we could do:

\n\n
\n$ ____          # (1)\n
\n\n

To print the value of the HOME variable, we could do:

\n\n
\n$ echo ____     # (2)\n
\n\n

To set the value of the SHELL variable to\n/bin/bash, we could do:

\n\n
\n$ ____          # (3)\n
\n\n

To compute the md5sum of the ls command\nwhile also looking up its location, we could do:

\n\n
\n$ md5sum ____   # (4)\n
\n" }, "q7": { "type": "multiple", "question": "\n

Given the directory listing in question 5, which files are not writable\nby the world?

\n", "responses": { "beastie": "Beastie", "tux": "Tux", "huxley": "Huxley" } }, "q6": { "type": "multiple", "question": "\n

Given the directory listing in question 5, which files are readable by\nmembers of the dip group?

\n", "responses": { "beastie": "Beastie", "tux": "Tux", "huxley": "Huxley" } }, "q9": { "type": "blank", "question": "

Suppose you run the bc command\n\n

    \n\n
  1. We could suspend the process with the keystroke: CTRL-____.
  2. \n\n
  3. We could resume the suspended process with the command: ____.
  4. \n\n
  5. We could indicate the end of input with the keystroke: CTRL-____.
  6. \n\n
  7. If the bc process was still running, we could terminate\nthe process using the keystroke: CTRL-____.
  8. \n\n
  9. If the bc process was still running, and we knew its PID,\nwe could terminate the process using the command: ____ PID.
  10. \n\n
  11. If the bc process was still running, and we did not know\nits PID, we could terminate the process using the command: ____ bc.
  12. \n" }, "q8": { "type": "blank", "question": "\n

    Given the directory listing in question 5:

    \n\n
      \n\n
    1. What is the octal code for Beastie's permissions? ____
    2. \n
    3. What is the octal code for Huxley's permissions? ____
    4. \n
    5. What is the octal code for Tux's permissions? ____
    6. \n\n
    \n" } }