Quiz 4 Flashcards

1
Q
  1. Which command was developed to show only the first ten lines in a text file?
    a. head
    b. top
    c. first
    d. cat
A

a. head The head command by default shows the first ten lines in a text file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. Which command enables you to count the number of words in a text file?
    a. count
    b. list
    c. ls -l
    d. wc
A
  1. D. The wc command shows the number of lines, words, and characters in a file.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Quiz Question
3. Which key on your keyboard do you use in less to go to the last line of the current text file?
a. End
b. Page Down
c. q
d. G

A

d. When using less, the G key brings you to the end of the current file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Which option is missing (…) from the following command, assuming that you want to filter the first field out of the /etc/passwd file and assuming that the character that is used as the field delimiter is a :?
    cut … : -f 1 /etc/passwd
    a. -d
    b. -c
    c. -t
    d. -x
A
  1. A. The -d option is used to specify the field delimiter that needs to be used to distinguish different fields in files while using cut.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. Which option is missing (…) if you want to sort the third column of the output of the command ps aux?
    ps aux | sort …
    a. -k3
    b. -s3
    c. -k f 3
    d. -f 3
A
  1. A. The sort command can sort files or command output based on specific keys. If no specific key is mentioned, sorting happens based on fields. The option -k3 will therefore sort the third field in the output of the ps aux command.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. Which of the following commands would only show lines in the file /etc/passwd that start with the text anna?
    a. grep anna /etc/passwd
    b. grep -v anna /etc/passwd
    c. grep $anna /etc/passwd
    d. grep ^anna /etc/passwd
A

Quiz Answer
6. D. When used in a regular expression, the ^ sign in front of the text you are looking for indicates that the text has to be at the beginning of the line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Quiz Question
7. Which regular expression do you use to make the previous character optional?
a. ?
b. .
c. *
d. &

A
  1. A. The ? regular expression is used to refer to zero or one of the previous characters. This makes the previous character optional, which can be useful. If the regular expression is colou?r, for example, you would get a match on color as well as colour.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. Which regular expression is used as a wildcard to refer to any single character?
    a. ?
    b. .
    c. *
    d. &
A

Quiz Answer
8. B. The . is used as a regular expression to refer to any single character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Which command prints the fourth field of a line in the /etc/passwd file if the text user occurs in that line?
    a. awk ‘/user/ { print $4 }’ /etc/passwd
    b. awk -d : ‘/user/ { print $4 }’ /etc/passwd
    c. awk -F : ‘/user/ $4’ /etc/passwd
    d. awk -F : ‘/user/ { print $4 }’ /etc/passwd
A

D. The awk command first needs to know which field separator should be used. This is specified with the -F : option. Then, it needs to specify a string that it should look for, which is /user/. To indicate that the fourth field of a matching file should be printed, you need to include the { print $4 } command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Which option would you use with grep to show only lines that do not contain the regular expression that was used?
    a. -x
    b. -v
    c. -u
    d. -q
A
  1. B. Use grep -v to exclude from the results lines containing the regular expression.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly