Unit 5: Shell Features - Practice Quiz
1 Which wildcard character matches any number of characters (including zero) in a filename?
?
#
@
*
2 Which wildcard matches exactly one single character?
%
*
?
+
3
What does the pattern [abc] match?
abc
a, b, or c
abc
4
Which pattern would list all files that end with .txt?
txt.*
*.txt
?.txt
.txt*
5
What does the range pattern [0-9] match?
0-9
6
Which command would list files named a, b, or c using a character set that expands into a single-character match against existing filenames on disk?
ls abc*
ls ?abc
ls *abc
ls [abc]
7 Wildcard expansion performed by the shell before running a command is commonly called:
8 Which operator redirects a command's standard output to a file, overwriting it?
>
|
>>
<
9 Which operator appends standard output to a file without erasing existing content?
<<
<
>>
>
10 Which operator redirects input to a command from a file?
>
<
|
>>
11
In the command sort < data.txt, where does sort get its input?
data.txt
12 What is the file descriptor number for standard error (stderr)?
0
2
3
1
13
Which command uses redirection to save the output of ls into a file named list.txt, replacing the file's previous contents if it already exists and creating it otherwise?
ls > list.txt
ls >> list.txt
ls < list.txt
ls | list.txt
14 What is the file descriptor number for standard input (stdin)?
1
2
0
4
15 Which symbol is used to create a pipe between two commands?
<
|
&
>
16
What does a pipe (|) do between two commands?
17
In the command ls | wc -l, what does wc -l receive?
ls
18 What is meant by pipe chaining?
19
In the chained command cat file.txt | grep "error" | wc -l, what is the final result?
error
error
20 In a pipe chain, the standard output of one command becomes the __ of the next command that reads it, allowing data to move through the whole sequence without temporary files:
21
In a directory containing the files file1.txt, file2.txt, file10.txt, and fileA.txt, which command lists only the files whose name ends in a single digit followed by .txt?
ls file*.txt
ls file?.txt
ls file[0-9].txt
ls file[!0-9].txt
22
What does the pattern [!aeiou]* match when used with ls?
23
Which wildcard pattern matches files named report, reportA, and reportABC but not report1?
report?
report[a-zA-Z]*
report[0-9]*
report*
24
The * wildcard in the shell matches which of the following?
25
Given files a.c, b.c, a.h, b.h, which command copies all .c and .h files to the backup directory in a single command?
cp *.[ch] backup/
cp *.{c|h} backup/
cp *.c *h backup/
cp *.c.h backup/
26
What happens if you run ls *.log in a directory that contains no files ending in .log (assuming default bash behavior)?
ls silently lists nothing and exits successfully
ls reports *.log not found
27 Which pattern matches three-character filenames where the middle character is a digit?
??[0-9]
[0-9]??
*[0-9]*
?[0-9]?
28
In brace expansion, what files does touch file{1,2,3}.txt create?
file{1,2,3}.txt
file1.txt only
file123.txt
file1.txt, file2.txt, file3.txt
29
What is the difference between command > file and command >> file?
>> redirects errors while > redirects output
> overwrites the file while >> appends to it
> appends to the file while >> overwrites it
30
Which command redirects only the error messages of program into errors.log while letting normal output appear on screen?
program &> errors.log
program 1> errors.log
program 2> errors.log
program > errors.log
31
What does the command sort < data.txt > sorted.txt do?
data.txt to sorted.txt
sorted.txt and writes to data.txt
data.txt and writes sorted output to sorted.txt
32
Which command sends both standard output and standard error of build.sh into all.log?
build.sh 2>&1 > all.log
build.sh > all.log 2>&1
build.sh > all.log 1>&2
build.sh >> all.log 2>>
33
What is the effect of redirecting a command's output to /dev/null, as in command > /dev/null?
34
A here-document is used to feed inline text to a command. Which syntax correctly begins one that passes text to cat until the word END?
cat >& END
cat >> END
cat < END
cat << END
35
Why does cat file1 > file1 typically result in an empty file1?
cat deletes the file after reading it
file1 for output before cat reads it
36
What does the command ls -l | grep "^d" accomplish?
37
In the pipeline cat access.log | grep "404" | wc -l, what value is produced?
404 appears on a single line
access.log containing 404
access.log
404
38 Which pipeline displays the five largest files (by size) in the current long listing?
ls -l | sort | head -5
ls -lr | head -5
ls -lS | head -6
ls -lS | tail -5
39
What does a pipe (|) connect between two commands?
40
You want to view a sorted list of unique usernames from users.txt. Which pipeline is correct?
sort -u users.txt | uniq -c
uniq -d users.txt | sort
uniq users.txt | sort
sort users.txt | uniq
41
In a directory containing files a.txt, ab.txt, abc.txt, and .hidden, what does the pattern ls [a-c]?.txt match?
ab.txt and abc.txt
a.txt, ab.txt, and abc.txt
.hidden
ab.txt only
42
What is the effect of the pattern rm *[!0-9]* in a directory?
43
Assuming no matching files exist and default Bash options, what happens when you run echo *.xyz in an empty-of-matches directory?
*.xyz
44
Which files does the pattern file[[:digit:]][[:alpha:]] match?
file
file3a where a digit is followed by a letter
filea3 where a letter is followed by a digit
file12 with two digits
45
With shopt -s extglob enabled in Bash, what does the pattern !(*.txt|*.log) match?
.txt or .log anywhere
.txt nor .log files
.txt and .log files
46
What is the key difference between command 2>&1 > file and command > file 2>&1?
47
What does the command command > file 2>&1 accomplish, and why is order important?
file, then makes stderr point to the same target as stdout (the file)
file, then stdout to the terminal
48
Given exec 3< data.txt, what has been accomplished?
data.txt is copied to a file named 3
data.txt
data.txt
data.txt
49
What is the difference between cat < file and cat file?
cat file reads from stdin while cat < file reads the argument
cat < file fails if the file does not exist but cat file does not
< file the shell opens the file and connects it to cat's stdin; with cat file the cat program itself opens the file by name
50
What does the here-string command tr 'a-z' 'A-Z' <<< "hello" produce?
<<< requires a file
a-z A-Z
hello
HELLO
51
In Bash, what is the effect of command &> file compared to command 2> file?
&> runs the command in the background and writes to file
&> redirects both stdout and stderr to file; 2> redirects only stderr
&> redirects only stdout; 2> redirects only stderr
52
What is the consequence of running > file (a redirection with no command) in Bash?
53
Why might sort file > file result in an empty or corrupted file?
> operator appends rather than overwrites
sort locks the file, causing a deadlock
sort cannot process files larger than memory
file via > before sort opens it for reading
54
In the pipeline cmd1 | cmd2, from where does cmd2 read its input and where does cmd1 send its output?
cmd1's stdout is connected to cmd2's stdin through a pipe
cmd2's stdout is connected to cmd1's stdin
cmd1's stderr is connected to cmd2's stdin
55
In most shells, in what process context do the commands of a pipeline a | b | c execute?
56
What does grep error log.txt | wc -l count?
log.txt that contain error
log.txt
error appears, including multiple per line
error
57
With set -o pipefail enabled, what is the exit status of the pipeline false | true | true?
false failed and pipefail returns the rightmost non-zero status
true succeeded
58
Why does echo hello | read var; echo "$var" print an empty line in Bash (without lastpipe)?
read cannot accept piped input at all
read runs in a subshell, so var is set only in that subshell and lost afterward
echo does not send a newline, so read gets nothing
read executes
59
What is the purpose of tee in the pipeline make 2>&1 | tee build.log | grep -i warning?
build.log while also passing it downstream to grep
build.log and errors elsewhere
grep requests it
build.log
60
Why does cat file | grep pattern produce the same result as grep pattern file, and what is the common criticism of the first form?
grep, but the first spawns an unnecessary cat process (a "useless use of cat")
cat buffers the file
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →