Unit 5: Shell Features - Practice Quiz

CSE105 — Creative Engineering Workshop 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which wildcard character matches any number of characters (including zero) in a filename?

Pattern Matching using Wildcards Easy
A. ?
B. #
C. @
D. *

2 Which wildcard matches exactly one single character?

Pattern Matching using Wildcards Easy
A. %
B. *
C. ?
D. +

3 What does the pattern [abc] match?

Pattern Matching using Wildcards Easy
A. Files ending in abc
B. Any three characters
C. Any one of the characters a, b, or c
D. The exact string abc

4 Which pattern would list all files that end with .txt?

Pattern Matching using Wildcards Easy
A. txt.*
B. *.txt
C. ?.txt
D. .txt*

5 What does the range pattern [0-9] match?

Pattern Matching using Wildcards Easy
A. The literal text 0-9
B. The numbers 0 and 9 only
C. Any single digit from 0 to 9
D. Any two digits

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?

Pattern Matching using Wildcards Easy
A. ls abc*
B. ls ?abc
C. ls *abc
D. ls [abc]

7 Wildcard expansion performed by the shell before running a command is commonly called:

Pattern Matching using Wildcards Easy
A. Escaping
B. Redirecting
C. Globbing
D. Piping

8 Which operator redirects a command's standard output to a file, overwriting it?

Input/Output Redirection Easy
A. >
B. |
C. >>
D. <

9 Which operator appends standard output to a file without erasing existing content?

Input/Output Redirection Easy
A. <<
B. <
C. >>
D. >

10 Which operator redirects input to a command from a file?

Input/Output Redirection Easy
A. >
B. <
C. |
D. >>

11 In the command sort < data.txt, where does sort get its input?

Input/Output Redirection Easy
A. From the screen
B. From the file data.txt
C. From another command
D. From the keyboard

12 What is the file descriptor number for standard error (stderr)?

Input/Output Redirection Easy
A. 0
B. 2
C. 3
D. 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?

Input/Output Redirection Easy
A. ls > list.txt
B. ls >> list.txt
C. ls < list.txt
D. ls | list.txt

14 What is the file descriptor number for standard input (stdin)?

Input/Output Redirection Easy
A. 1
B. 2
C. 0
D. 4

15 Which symbol is used to create a pipe between two commands?

Pipes and Pipe Chaining Easy
A. <
B. |
C. &
D. >

16 What does a pipe (|) do between two commands?

Pipes and Pipe Chaining Easy
A. Sends the output of the first command as input to the second
B. Runs both commands at the same time independently
C. Combines two files into one
D. Redirects output to a file

17 In the command ls | wc -l, what does wc -l receive?

Pipes and Pipe Chaining Easy
A. The output of ls
B. An error message
C. Input from the keyboard
D. The contents of a file

18 What is meant by pipe chaining?

Pipes and Pipe Chaining Easy
A. Redirecting output to multiple files
B. Connecting multiple commands in a sequence using several pipes
C. Linking two files together
D. Running a single command repeatedly

19 In the chained command cat file.txt | grep "error" | wc -l, what is the final result?

Pipes and Pipe Chaining Easy
A. The first line with error
B. A list of all files
C. The count of lines containing error
D. The full contents of the file

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:

Pipes and Pipe Chaining Easy
A. standard input
B. exit status
C. file descriptor 2
D. standard error

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?

Pattern Matching using Wildcards Medium
A. ls file*.txt
B. ls file?.txt
C. ls file[0-9].txt
D. ls file[!0-9].txt

22 What does the pattern [!aeiou]* match when used with ls?

Pattern Matching using Wildcards Medium
A. Files ending in a vowel character
B. Files whose name starts with a vowel
C. Files whose name contains no vowels at all
D. Files whose name starts with a character that is not a vowel

23 Which wildcard pattern matches files named report, reportA, and reportABC but not report1?

Pattern Matching using Wildcards Medium
A. report?
B. report[a-zA-Z]*
C. report[0-9]*
D. report*

24 The * wildcard in the shell matches which of the following?

Pattern Matching using Wildcards Medium
A. Any string of zero or more characters
B. Exactly one arbitrary character
C. One character from a given set
D. One or more characters, but at least one

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?

Pattern Matching using Wildcards Medium
A. cp *.[ch] backup/
B. cp *.{c|h} backup/
C. cp *.c *h backup/
D. 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)?

Pattern Matching using Wildcards Medium
A. The shell lists every file in the directory
B. ls silently lists nothing and exits successfully
C. The shell throws a syntax error
D. The pattern is passed literally and ls reports *.log not found

27 Which pattern matches three-character filenames where the middle character is a digit?

Pattern Matching using Wildcards Medium
A. ??[0-9]
B. [0-9]??
C. *[0-9]*
D. ?[0-9]?

28 In brace expansion, what files does touch file{1,2,3}.txt create?

Pattern Matching using Wildcards Medium
A. A single file named file{1,2,3}.txt
B. file1.txt only
C. file123.txt
D. file1.txt, file2.txt, file3.txt

29 What is the difference between command > file and command >> file?

Input/Output Redirection Medium
A. >> redirects errors while > redirects output
B. > overwrites the file while >> appends to it
C. > appends to the file while >> overwrites it
D. Both overwrite the file identically

30 Which command redirects only the error messages of program into errors.log while letting normal output appear on screen?

Input/Output Redirection Medium
A. program &> errors.log
B. program 1> errors.log
C. program 2> errors.log
D. program > errors.log

31 What does the command sort < data.txt > sorted.txt do?

Input/Output Redirection Medium
A. Appends the sorted content of data.txt to sorted.txt
B. Sorts both files and merges them together
C. Reads from sorted.txt and writes to data.txt
D. Reads input from 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?

Input/Output Redirection Medium
A. build.sh 2>&1 > all.log
B. build.sh > all.log 2>&1
C. build.sh > all.log 1>&2
D. build.sh >> all.log 2>>

33 What is the effect of redirecting a command's output to /dev/null, as in command > /dev/null?

Input/Output Redirection Medium
A. The output is printed twice
B. The command's input is cleared
C. The output is saved to a temporary file
D. The standard output is discarded entirely

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?

Input/Output Redirection Medium
A. cat >& END
B. cat >> END
C. cat < END
D. cat << END

35 Why does cat file1 > file1 typically result in an empty file1?

Input/Output Redirection Medium
A. Redirection copies the file to itself and doubles it
B. cat deletes the file after reading it
C. The shell truncates file1 for output before cat reads it
D. The command fails and removes the file

36 What does the command ls -l | grep "^d" accomplish?

Pipes and Pipe Chaining Medium
A. Sorts entries alphabetically
B. Counts the number of files
C. Lists only regular files
D. Lists only directory entries from the long listing

37 In the pipeline cat access.log | grep "404" | wc -l, what value is produced?

Pipes and Pipe Chaining Medium
A. The number of times 404 appears on a single line
B. The number of lines in access.log containing 404
C. The total number of lines in access.log
D. The first line containing 404

38 Which pipeline displays the five largest files (by size) in the current long listing?

Pipes and Pipe Chaining Medium
A. ls -l | sort | head -5
B. ls -lr | head -5
C. ls -lS | head -6
D. ls -lS | tail -5

39 What does a pipe (|) connect between two commands?

Pipes and Pipe Chaining Medium
A. The standard error of the left command to the input of the right command
B. The standard output of the left command to the standard input of the right command
C. The output files of both commands into one
D. The exit codes of the two commands

40 You want to view a sorted list of unique usernames from users.txt. Which pipeline is correct?

Pipes and Pipe Chaining Medium
A. sort -u users.txt | uniq -c
B. uniq -d users.txt | sort
C. uniq users.txt | sort
D. 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?

Pattern Matching using Wildcards Hard
A. ab.txt and abc.txt
B. a.txt, ab.txt, and abc.txt
C. All four files including .hidden
D. ab.txt only

42 What is the effect of the pattern rm *[!0-9]* in a directory?

Pattern Matching using Wildcards Hard
A. Removes files that end with a non-digit character
B. Removes files containing at least one non-digit character somewhere in their name
C. Removes all files regardless of name
D. Removes files whose names consist entirely of digits

43 Assuming no matching files exist and default Bash options, what happens when you run echo *.xyz in an empty-of-matches directory?

Pattern Matching using Wildcards Hard
A. It prints nothing (an empty line)
B. It prints the literal string *.xyz
C. It expands to all files in the directory
D. It raises a "no match" error and aborts

44 Which files does the pattern file[[:digit:]][[:alpha:]] match?

Pattern Matching using Wildcards Hard
A. Any file starting with file
B. Names like file3a where a digit is followed by a letter
C. Names like filea3 where a letter is followed by a digit
D. Names like file12 with two digits

45 With shopt -s extglob enabled in Bash, what does the pattern !(*.txt|*.log) match?

Pattern Matching using Wildcards Hard
A. Files containing .txt or .log anywhere
B. Files that are neither .txt nor .log files
C. Nothing, because it is invalid syntax
D. Only .txt and .log files

46 What is the key difference between command 2>&1 > file and command > file 2>&1?

Input/Output Redirection Hard
A. The first sends both to the file; the second sends stderr to the terminal
B. Both send stdout and stderr to the file identically
C. Both send only stderr to the file
D. The first sends stderr to the terminal and stdout to the file; the second sends both to the file

47 What does the command command > file 2>&1 accomplish, and why is order important?

Input/Output Redirection Hard
A. Redirects stdout to file, then makes stderr point to the same target as stdout (the file)
B. Redirects stderr to file, then stdout to the terminal
C. Redirects stdout and stderr to two separate files
D. Merges stderr into stdout before stdout is redirected, sending both to the terminal

48 Given exec 3< data.txt, what has been accomplished?

Input/Output Redirection Hard
A. data.txt is copied to a file named 3
B. Standard input is permanently replaced by data.txt
C. File descriptor 3 is opened for writing to data.txt
D. File descriptor 3 is opened for reading from data.txt

49 What is the difference between cat < file and cat file?

Input/Output Redirection Hard
A. There is no functional difference and both behave identically in every respect
B. cat file reads from stdin while cat < file reads the argument
C. cat < file fails if the file does not exist but cat file does not
D. With < 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?

Input/Output Redirection Hard
A. An error, since <<< requires a file
B. a-z A-Z
C. hello
D. HELLO

51 In Bash, what is the effect of command &> file compared to command 2> file?

Input/Output Redirection Hard
A. Both redirect both streams identically
B. &> runs the command in the background and writes to file
C. &> redirects both stdout and stderr to file; 2> redirects only stderr
D. &> redirects only stdout; 2> redirects only stderr

52 What is the consequence of running > file (a redirection with no command) in Bash?

Input/Output Redirection Hard
A. The file's contents are printed to the terminal
B. Nothing happens; the file is left unchanged
C. The file is created if absent or truncated to zero length if it exists
D. A syntax error is raised because no command is present

53 Why might sort file > file result in an empty or corrupted file?

Input/Output Redirection Hard
A. The > operator appends rather than overwrites
B. sort locks the file, causing a deadlock
C. sort cannot process files larger than memory
D. The shell truncates 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?

Pipes and Pipe Chaining Hard
A. Both commands share the same stdout
B. cmd1's stdout is connected to cmd2's stdin through a pipe
C. cmd2's stdout is connected to cmd1's stdin
D. 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?

Pipes and Pipe Chaining Hard
A. Only the last command runs as a subprocess
B. Each command runs in its own separate subprocess, concurrently
C. They run sequentially, one finishing before the next starts
D. All three run in the parent shell process

56 What does grep error log.txt | wc -l count?

Pipes and Pipe Chaining Hard
A. The number of lines in log.txt that contain error
B. The number of files named log.txt
C. The number of times error appears, including multiple per line
D. The total number of characters matching error

57 With set -o pipefail enabled, what is the exit status of the pipeline false | true | true?

Pipes and Pipe Chaining Hard
A. Non-zero always, regardless of any command
B. Zero, because pipefail ignores intermediate failures
C. Non-zero, because false failed and pipefail returns the rightmost non-zero status
D. Zero, because the last command true succeeded

58 Why does echo hello | read var; echo "$var" print an empty line in Bash (without lastpipe)?

Pipes and Pipe Chaining Hard
A. read cannot accept piped input at all
B. read runs in a subshell, so var is set only in that subshell and lost afterward
C. echo does not send a newline, so read gets nothing
D. The semicolon terminates the pipeline before read executes

59 What is the purpose of tee in the pipeline make 2>&1 | tee build.log | grep -i warning?

Pipes and Pipe Chaining Hard
A. It writes the full combined output to build.log while also passing it downstream to grep
B. It splits the output so warnings go to build.log and errors elsewhere
C. It buffers the output until grep requests it
D. It counts the lines and writes only the total to 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?

Pipes and Pipe Chaining Hard
A. Both feed the file's contents to grep, but the first spawns an unnecessary cat process (a "useless use of cat")
B. They differ: only the first handles multiple files
C. The first reads stderr while the second reads stdin
D. The first form is faster because cat buffers the file