{ "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\nTo redirect the contents of a file into a command such as\nmd5sum
, we can do:
\n$ md5sum ____ file # (4)\n\n\n
To redirect the output of a command such as date
to a file, we\ncan do:
\n$ date ____ file # (5)\n\n\n
To append the output of a command such as uname
to a file, we\ncan do:
\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$ 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$ 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$ 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
:
\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
.
Using bash
's expansion syntax, complete the following prompts.
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 Given the following output of ls -l
:
\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": "\nTwo other important features of a typical Unix shell are variables (ie.\nparameter expansion) and command substitution. Using these features,\ncomplete the following prompts:
\n\nTo 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$ echo ____ # (2)\n\n\n
To set the value of the SHELL
variable to\n/bin/bash
, we could do:
\n$ ____ # (3)\n\n\n
To compute the md5sum
of the ls
command\nwhile also looking up its location, we could do:
\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": "\nGiven the directory listing in question 5, which files are readable by\nmembers of the dip
group?
Suppose you run the bc
command\n\n
bc
process was still running, we could terminate\nthe process using the keystroke: CTRL-____.bc
process was still running, and we knew its PID,\nwe could terminate the process using the command: ____ PID.bc
process was still running, and we did not know\nits PID, we could terminate the process using the command: ____ bc.Given the directory listing in question 5:
\n\nBeastie
's permissions? ____Huxley
's permissions? ____Tux
's permissions? ____