Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Question 1 of 60 · Pattern Matching using Wildcards · Easy
Which wildcard character matches any number of characters (including zero) in a filename?
Not quite. Try another option.
Answer: *
The asterisk * matches zero or more characters, so file* matches file, file1, filename, etc.
Question 2 of 60 · Pattern Matching using Wildcards · Easy
Which wildcard matches exactly one single character?
Not quite. Try another option.
Answer: ?
The question mark ? matches any single character. For example, file? matches file1 or fileA but not file or file12.
Question 3 of 60 · Pattern Matching using Wildcards · Easy
What does the pattern [abc] match?
Not quite. Try another option.
Answer: Any one of the characters a, b, or c
Square brackets define a character set. [abc] matches a single character that is either a, b, or c.
Question 4 of 60 · Pattern Matching using Wildcards · Easy
Which pattern would list all files that end with.txt?
Not quite. Try another option.
Answer: *.txt
*.txt matches any filename (any characters) followed by the .txt extension.
Question 5 of 60 · Pattern Matching using Wildcards · Easy
What does the range pattern [0-9] match?
Not quite. Try another option.
Answer: Any single digit from 0 to 9
A range inside brackets like [0-9] matches any single character within that range — here, any one digit.
Question 6 of 60 · Pattern Matching using Wildcards · Easy
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?
Not quite. Try another option.
Answer: ls [abc]
[abc] matches one character that is a, b, or c, so it lists files with those single-character names.
Question 7 of 60 · Pattern Matching using Wildcards · Easy
Wildcard expansion performed by the shell before running a command is commonly called:
Not quite. Try another option.
Answer: Globbing
The process where the shell expands wildcard patterns like * and ? into matching filenames is known as globbing.
Question 8 of 60 · Input/Output Redirection · Easy
Which operator redirects a command's standard output to a file, overwriting it?
Not quite. Try another option.
Answer: >
The > operator sends standard output to a file, replacing any existing contents of that file.
Question 9 of 60 · Input/Output Redirection · Easy
Which operator appends standard output to a file without erasing existing content?
Not quite. Try another option.
Answer: >>
The >> operator appends output to the end of a file, preserving whatever was already there.
Question 10 of 60 · Input/Output Redirection · Easy
Which operator redirects input to a command from a file?
Not quite. Try another option.
Answer: <
The < operator takes standard input for a command from the specified file instead of the keyboard.
Question 11 of 60 · Input/Output Redirection · Easy
In the command sort < data.txt, where does sort get its input?
Not quite. Try another option.
Answer: From the file data.txt
The < operator redirects input, so sort reads its data from data.txt rather than from the keyboard.
Question 12 of 60 · Input/Output Redirection · Easy
What is the file descriptor number for standard error (stderr)?
Not quite. Try another option.
Answer: 2
Standard input is 0, standard output is 1, and standard error is file descriptor 2.
Question 13 of 60 · Input/Output Redirection · Easy
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?
Not quite. Try another option.
Answer: ls > list.txt
ls > list.txt redirects the output of ls into list.txt, overwriting existing content or creating the file.
Question 14 of 60 · Input/Output Redirection · Easy
What is the file descriptor number for standard input (stdin)?
Not quite. Try another option.
Answer: 0
Standard input is assigned file descriptor 0 by default in the shell.
Question 15 of 60 · Pipes and Pipe Chaining · Easy
Which symbol is used to create a pipe between two commands?
Not quite. Try another option.
Answer: |
The vertical bar | is the pipe operator, connecting one command's output to the next command's input.
Question 16 of 60 · Pipes and Pipe Chaining · Easy
What does a pipe (|) do between two commands?
Not quite. Try another option.
Answer: Sends the output of the first command as input to the second
A pipe connects stdout of the left command to stdin of the right command, allowing data to flow between them.
Question 17 of 60 · Pipes and Pipe Chaining · Easy
In the command ls | wc -l, what does wc -l receive?
Not quite. Try another option.
Answer: The output of ls
The pipe passes the listing produced by ls to wc -l, which then counts the number of lines.
Question 18 of 60 · Pipes and Pipe Chaining · Easy
What is meant by pipe chaining?
Not quite. Try another option.
Answer: Connecting multiple commands in a sequence using several pipes
Pipe chaining uses more than one | to pass data through a series of commands, e.g., cmd1 | cmd2 | cmd3.
Question 19 of 60 · Pipes and Pipe Chaining · Easy
In the chained command cat file.txt | grep "error" | wc -l, what is the final result?
Not quite. Try another option.
Answer: The count of lines containing error
cat outputs the file, grep filters lines with error, and wc -l counts those matching lines.
Question 20 of 60 · Pipes and Pipe Chaining · Easy
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:
Not quite. Try another option.
Answer: standard input
In a pipe, the stdout of the previous command is fed as the stdin of the next command in the chain.
Question 21 of 60 · Pattern Matching using Wildcards · Medium
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?
Not quite. Try another option.
Answer: ls file[0-9].txt
The character class [0-9] matches exactly one digit, so file[0-9].txt matches file1.txt and file2.txt but not file10.txt (two digits) or fileA.txt (letter).
Question 22 of 60 · Pattern Matching using Wildcards · Medium
What does the pattern [!aeiou]* match when used with ls?
Not quite. Try another option.
Answer: Files whose name starts with a character that is not a vowel
Inside [ ], a leading ! (or ^) negates the set. So [!aeiou] matches any single character that is not one of those vowels, and * matches the rest of the name.
Question 23 of 60 · Pattern Matching using Wildcards · Medium
Which wildcard pattern matches files named report, reportA, and reportABC but notreport1?
Not quite. Try another option.
Answer: report[a-zA-Z]*
report[a-zA-Z]* requires the character after report to be a letter; however report alone (no trailing char) would not match this pattern. Among the options it is the only one that excludes report1 while still matching letter-suffixed names, since [a-zA-Z] rejects the digit 1.
Question 24 of 60 · Pattern Matching using Wildcards · Medium
The * wildcard in the shell matches which of the following?
Not quite. Try another option.
Answer: Any string of zero or more characters
The asterisk * matches any sequence of characters including the empty string (zero characters), which is why file* also matches a file named exactly file.
Question 25 of 60 · Pattern Matching using Wildcards · Medium
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?
Not quite. Try another option.
Answer: cp *.[ch] backup/
The class [ch] matches a single character that is either c or h, so *.[ch] expands to all .c and .h files.
Question 26 of 60 · Pattern Matching using Wildcards · Medium
What happens if you run ls *.log in a directory that contains no files ending in .log (assuming default bash behavior)?
Not quite. Try another option.
Answer: The pattern is passed literally and ls reports *.log not found
By default (with nullglob off), an unmatched wildcard is left unchanged, so ls receives the literal string *.log and reports that no such file exists.
Question 27 of 60 · Pattern Matching using Wildcards · Medium
Which pattern matches three-character filenames where the middle character is a digit?
Not quite. Try another option.
Answer: ?[0-9]?
Each ? matches exactly one character, and [0-9] matches one digit. So ?[0-9]? matches names of exactly three characters whose middle character is a digit.
Question 28 of 60 · Pattern Matching using Wildcards · Medium
In brace expansion, what files does touch file{1,2,3}.txt create?
Not quite. Try another option.
Answer: file1.txt, file2.txt, file3.txt
Brace expansion generates a separate string for each comma-separated item, so file{1,2,3}.txt expands to three names that touch then creates. Note brace expansion is not glob matching—it works even when no files exist yet.
Question 29 of 60 · Input/Output Redirection · Medium
What is the difference between command > file and command >> file?
Not quite. Try another option.
Answer: > overwrites the file while >> appends to it
A single > truncates the target file and writes fresh output, whereas >> preserves existing content and adds new output to the end.
Question 30 of 60 · Input/Output Redirection · Medium
Which command redirects only the error messages of program into errors.log while letting normal output appear on screen?
Not quite. Try another option.
Answer: program 2> errors.log
File descriptor 2 is standard error. 2> errors.log redirects stderr to the file, leaving stdout (descriptor 1) untouched on the terminal.
Question 31 of 60 · Input/Output Redirection · Medium
What does the command sort < data.txt > sorted.txt do?
Not quite. Try another option.
Answer: Reads input from data.txt and writes sorted output to sorted.txt
< data.txt supplies sort its standard input, and > sorted.txt captures its standard output, so the sorted result is written to sorted.txt.
Question 32 of 60 · Input/Output Redirection · Medium
Which command sends both standard output and standard error of build.sh into all.log?
Not quite. Try another option.
Answer: build.sh > all.log 2>&1
First > all.log points stdout to the file, then 2>&1 makes stderr point to wherever stdout currently points. Order matters—reversing them would send stderr to the terminal instead.
Question 33 of 60 · Input/Output Redirection · Medium
What is the effect of redirecting a command's output to /dev/null, as in command > /dev/null?
Not quite. Try another option.
Answer: The standard output is discarded entirely
/dev/null is a special device that discards everything written to it, so redirecting to it silences the command's standard output.
Question 34 of 60 · Input/Output Redirection · Medium
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?
Not quite. Try another option.
Answer: cat << END
The << operator starts a here-document; the shell feeds all following lines as standard input until it reaches a line containing only the delimiter word (END).
Question 35 of 60 · Input/Output Redirection · Medium
Why does cat file1 > file1 typically result in an empty file1?
Not quite. Try another option.
Answer: The shell truncates file1 for output before cat reads it
The shell opens and truncates the redirection target (> file1) before cat starts executing, so by the time cat opens file1 for reading it is already empty.
Question 36 of 60 · Pipes and Pipe Chaining · Medium
What does the command ls -l | grep "^d" accomplish?
Not quite. Try another option.
Answer: Lists only directory entries from the long listing
In ls -l output, directory lines begin with d. Piping to grep "^d" keeps only lines starting with d, i.e. directories.
Question 37 of 60 · Pipes and Pipe Chaining · Medium
In the pipeline cat access.log | grep "404" | wc -l, what value is produced?
Not quite. Try another option.
Answer: The number of lines in access.log containing 404
grep "404" filters lines containing 404, and wc -l counts those lines, giving the count of matching lines.
Question 38 of 60 · Pipes and Pipe Chaining · Medium
Which pipeline displays the five largest files (by size) in the current long listing?
Not quite. Try another option.
Answer: ls -lS | head -6
ls -lS sorts entries by size, largest first. head -6 shows the top lines; the extra line accounts for the total header, leaving the five largest files.
Question 39 of 60 · Pipes and Pipe Chaining · Medium
What does a pipe (|) connect between two commands?
Not quite. Try another option.
Answer: The standard output of the left command to the standard input of the right command
A pipe redirects the stdout of the command on its left into the stdin of the command on its right, allowing data to flow through the chain. By default it does not carry stderr.
Question 40 of 60 · Pipes and Pipe Chaining · Medium
You want to view a sorted list of unique usernames from users.txt. Which pipeline is correct?
Not quite. Try another option.
Answer: sort users.txt | uniq
uniq only removes adjacent duplicate lines, so the data must be sorted first. sort users.txt | uniq sorts the names and then collapses duplicates.
Question 41 of 60 · Pattern Matching using Wildcards · Hard
In a directory containing files a.txt, ab.txt, abc.txt, and .hidden, what does the pattern ls [a-c]?.txt match?
Not quite. Try another option.
Answer: ab.txt only
[a-c] matches exactly one character in range a–c, and ? matches exactly one more character, requiring a two-character name before .txt. Only ab.txt fits: a matches [a-c] and b matches ?. a.txt is too short and abc.txt is too long.
Question 42 of 60 · Pattern Matching using Wildcards · Hard
What is the effect of the pattern rm *[!0-9]* in a directory?
Not quite. Try another option.
Answer: Removes files containing at least one non-digit character somewhere in their name
[!0-9] is a negated bracket that matches any single character that is NOT a digit. Surrounded by * on both sides, the pattern matches any filename that contains at least one non-digit character anywhere within it.
Question 43 of 60 · Pattern Matching using Wildcards · Hard
Assuming no matching files exist and default Bash options, what happens when you run echo *.xyz in an empty-of-matches directory?
Not quite. Try another option.
Answer: It prints the literal string *.xyz
By default (without nullglob or failglob set), when a glob pattern matches no files, Bash leaves the pattern unchanged and passes the literal text to the command. So echo prints *.xyz verbatim.
Question 44 of 60 · Pattern Matching using Wildcards · Hard
Which files does the pattern file[[:digit:]][[:alpha:]] match?
Not quite. Try another option.
Answer: Names like file3a where a digit is followed by a letter
POSIX character classes [[:digit:]] and [[:alpha:]] each match exactly one character of the respective type in that order. So the name must be file followed by one digit then one alphabetic character, e.g., file3a.
Question 45 of 60 · Pattern Matching using Wildcards · Hard
With shopt -s extglob enabled in Bash, what does the pattern !(*.txt|*.log) match?
Not quite. Try another option.
Answer: Files that are neither .txt nor .log files
In extended globbing, !(pattern-list) matches anything except one of the given patterns. So !(*.txt|*.log) matches all names that do not end in .txt or .log.
Question 46 of 60 · Input/Output Redirection · Hard
What is the key difference between command 2>&1 > file and command > file 2>&1?
Not quite. Try another option.
Answer: The first sends stderr to the terminal and stdout to the file; the second sends both to the file
Redirections apply left to right. In 2>&1 > file, stderr is first pointed at stdout's current target (the terminal), then stdout is redirected to the file — so stderr still goes to the terminal. In > file 2>&1, stdout goes to the file first, then stderr is pointed to that same file.
Question 47 of 60 · Input/Output Redirection · Hard
What does the command command > file 2>&1 accomplish, and why is order important?
Not quite. Try another option.
Answer: Redirects stdout to file, then makes stderr point to the same target as stdout (the file)
First > file sets stdout to the file. Then 2>&1 duplicates stderr onto whatever stdout currently references, which is now the file. Both streams end up in file.
Question 48 of 60 · Input/Output Redirection · Hard
Given exec 3< data.txt, what has been accomplished?
Not quite. Try another option.
Answer: File descriptor 3 is opened for reading from data.txt
exec 3< data.txt opens data.txt for reading and assigns it to file descriptor 3 for the current shell. Subsequent commands can read from FD 3 (e.g., read -u 3) until it is closed with exec 3<&-.
Question 49 of 60 · Input/Output Redirection · Hard
What is the difference between cat < file and cat file?
Not quite. Try another option.
Answer: 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
In cat < file, the shell performs the redirection and hands an open descriptor to cat as stdin. In cat file, cat receives the filename as an argument and opens it itself. The output is the same, but the mechanism (and error reporting) differs.
Question 50 of 60 · Input/Output Redirection · Hard
What does the here-string command tr 'a-z' 'A-Z' <<< "hello" produce?
Not quite. Try another option.
Answer: HELLO
<<< is a here-string that feeds the string hello (plus a trailing newline) to the command's stdin. tr 'a-z' 'A-Z' translates lowercase to uppercase, yielding HELLO.
Question 51 of 60 · Input/Output Redirection · Hard
In Bash, what is the effect of command &> file compared to command 2> file?
Not quite. Try another option.
Answer: &> redirects both stdout and stderr to file; 2> redirects only stderr
&> is a Bash shorthand that redirects both standard output and standard error to file. 2> redirects only file descriptor 2 (stderr), leaving stdout going to its default destination.
Question 52 of 60 · Input/Output Redirection · Hard
What is the consequence of running > file (a redirection with no command) in Bash?
Not quite. Try another option.
Answer: The file is created if absent or truncated to zero length if it exists
The shell processes redirections even when no command is given. Opening file for output with > truncates it (or creates it empty). This is a common idiom to empty a file.
Question 53 of 60 · Input/Output Redirection · Hard
Why might sort file > file result in an empty or corrupted file?
Not quite. Try another option.
Answer: The shell truncates file via > before sort opens it for reading
The shell sets up output redirection first, truncating file to zero length, before sort even begins reading it. As a result sort reads an empty file. Use sort file -o file or a temp file instead.
Question 54 of 60 · Pipes and Pipe Chaining · Hard
In the pipeline cmd1 | cmd2, from where does cmd2 read its input and where does cmd1 send its output?
Not quite. Try another option.
Answer: cmd1's stdout is connected to cmd2's stdin through a pipe
A pipe | connects the standard output of the left command to the standard input of the right command. By default, stderr of cmd1 is NOT sent through the pipe and still goes to the terminal.
Question 55 of 60 · Pipes and Pipe Chaining · Hard
In most shells, in what process context do the commands of a pipeline a | b | c execute?
Not quite. Try another option.
Answer: Each command runs in its own separate subprocess, concurrently
Pipeline stages run concurrently in separate processes, with data flowing through pipes as it is produced. This is why a variable assigned inside a piped while loop in Bash may not persist — that stage runs in a subshell.
Question 56 of 60 · Pipes and Pipe Chaining · Hard
What does grep error log.txt | wc -l count?
Not quite. Try another option.
Answer: The number of lines in log.txt that contain error
grep error log.txt outputs each matching line once, and wc -l counts lines. So the result is the count of lines containing error, not the count of occurrences (a line with two errors counts once).
Question 57 of 60 · Pipes and Pipe Chaining · Hard
With set -o pipefail enabled, what is the exit status of the pipeline false | true | true?
Not quite. Try another option.
Answer: Non-zero, because false failed and pipefail returns the rightmost non-zero status
Normally a pipeline's exit status is that of the last command. With pipefail, the status is that of the last (rightmost) command that exited non-zero, or zero if all succeed. Since false fails, the pipeline returns non-zero.
Question 58 of 60 · Pipes and Pipe Chaining · Hard
Why does echo hello | read var; echo "$var" print an empty line in Bash (without lastpipe)?
Not quite. Try another option.
Answer: read runs in a subshell, so var is set only in that subshell and lost afterward
In Bash by default, each pipeline stage runs in its own subshell. read assigns var in that subshell, which exits when the pipeline finishes, so the parent shell's var is unaffected. Enabling shopt -s lastpipe (in non-interactive shells) changes this.
Question 59 of 60 · Pipes and Pipe Chaining · Hard
What is the purpose of tee in the pipeline make 2>&1 | tee build.log | grep -i warning?
Not quite. Try another option.
Answer: It writes the full combined output to build.log while also passing it downstream to grep
tee duplicates its stdin: it writes a full copy to the named file(s) and also forwards stdin to its stdout. Here the complete merged output is saved to build.log while grep filters the stream for warnings.
Question 60 of 60 · Pipes and Pipe Chaining · Hard
Why does cat file | grep pattern produce the same result as grep pattern file, and what is the common criticism of the first form?
Not quite. Try another option.
Answer: Both feed the file's contents to grep, but the first spawns an unnecessary cat process (a "useless use of cat")
grep can open files directly, so piping through cat adds an extra process and a pipe for no benefit. This is the classic "Useless Use of Cat" — grep pattern file is more efficient.
That's unit 5
Answer a few questions and your score shows up here.
Nearly through. Did unit 5 of CSE105 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 5 of CSE105 save you a night before the exam?
Then you can help keep it free for the next batch. 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.