Quiz 4 Flashcards
- Which command was developed to show only the first ten lines in a text file?
a. head
b. top
c. first
d. cat
a. head The head command by default shows the first ten lines in a text file.
- Which command enables you to count the number of words in a text file?
a. count
b. list
c. ls -l
d. wc
- D. The wc command shows the number of lines, words, and characters in a file.
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
d. When using less, the G key brings you to the end of the current file.
- 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. The -d option is used to specify the field delimiter that needs to be used to distinguish different fields in files while using cut.
- 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. 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.
- 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
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.
Quiz Question
7. Which regular expression do you use to make the previous character optional?
a. ?
b. .
c. *
d. &
- 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.
- Which regular expression is used as a wildcard to refer to any single character?
a. ?
b. .
c. *
d. &
Quiz Answer
8. B. The . is used as a regular expression to refer to any single character.
- 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
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.
- 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
- B. Use grep -v to exclude from the results lines containing the regular expression.