Linux Essentials The Power of the Command Line: 197 practice questions
12 of the 197 The Power of the Command Line questions in the Certsqill Linux Essentials bank, shown in full below. Each one carries an explanation for every option, not just the correct one — the wrong answers are where the marks go.
Preparing for Linux Essentials? Take the free 5-min readiness check →
1. tar -cf training.tar report.txt notes.txt: Which GNU tar command creates `training.tar` containing both files?
- tar -czf report.txt notes.txt training.tarThis treats `report.txt` as the archive filename and does not specify the requested output archive correctly.
- tar -cf training.tar report.txt notes.txt ✓The `-c` option creates an archive, and `-f` supplies its filename before the listed input files.
- tar -xvf training.tar report.txt notes.txtThe `-x` operation extracts from an archive rather than creating a new archive.
- tar -tf training.tar report.txt notes.txtThe `-t` operation lists archive members and does not bundle the supplied files.
Use tar create mode with `-c` and provide the archive filename using `-f`.
2. 2: What standard output results from `grep -v '^#' names.txt | wc -l` when exactly one line begins with `#`?
- 0Two nonmatching lines remain, so the pipeline does not produce an empty input.
- 3That would count all original lines, including the line removed by `grep -v`.
- 1That would count the excluded comment line rather than the lines passed through the pipeline.
- 2 ✓`grep -v` removes the matching comment line, and `wc -l` counts the two remaining newline characters.
Inverted grep passes two lines, and `wc -l` counts their newline characters.
3. 3: What is the standard output?
- 12The loop performs arithmetic addition, not string concatenation or direct joining of its values.
- 3 ✓Bash adds one and two to the initial zero, then printf outputs the resulting total.
- 1The first iteration adds one, but the second iteration also adds two.
- 0The loop updates total twice, so its initial value is not the final result.
The loop computes zero plus one plus two, so the exact output is 3.
4. tar -tf backup.tar: Which command performs that inspection without extracting files?
- tar -tf backup.tar ✓GNU tar uses `-t` to list archive members and `-f` to identify the archive file.
- tar -cf backup.tarThe `-c` option creates an archive and does not list the contents of an existing archive.
- tar -xf backup.tarThe `-x` option extracts archive members, which violates the requirement to inspect without extraction.
- gzip -t backup.tar`gzip -t` tests compressed-stream integrity and does not list tar archive member names.
Use tar list mode, `-t`, with `-f backup.tar` to inspect members without extraction.
5. generate_report 2> errors.log: Which command does that?
- generate_reportThis leaves both output streams connected to the terminal instead of saving diagnostics separately.
- generate_report > errors.log 2>&1This sends both standard output and standard error into errors.log, not just diagnostics.
- generate_report > errors.logThis redirects standard output, while standard error still appears on the terminal.
- generate_report 2> errors.log ✓File descriptor 2 is standard error, so only diagnostics go into errors.log.
Use `2>` to redirect standard error while leaving standard output unchanged.
6. `gzip -c report.txt > report.txt.gz`: Which is the least disruptive valid command?
- `cp report.txt report.txt.gz``cp` creates a second uncompressed copy; changing the filename does not create gzip data.
- `tar -czf report.txt.gz report.txt`This creates a gzip-compressed tar archive, not a gzip-compressed copy of the file itself.
- `gzip -c report.txt > report.txt.gz` ✓`gzip -c` writes compressed data to standard output, and redirection saves it as a new file while retaining the source.
- `gzip report.txt`Ordinary gzip compression normally replaces `report.txt` with `report.txt.gz`, so the original is not retained.
Use `gzip -c` and redirect its output.
7. `>> notes.txt` appends standard output to the existing: Select TWO true statements about these redirections.
Select two. More than one option is correct — every correct one is ticked below.
- `>> notes.txt` appends standard output to the existing file. ✓The `>>` operator writes standard output after the existing contents without truncating them.
- `> notes.txt` preserves existing contents and adds output afterward.The single `>` operator truncates the destination before writing standard output; appending requires `>>`.
- Both operators redirect standard error unless descriptor 1 is explicitly mentioned.Both operators redirect standard output by default. Standard error uses descriptor 2, such as `2>`.
- `cat notes.txt > notes.txt` preserves the file while displaying its contents.The shell truncates `notes.txt` before `cat` reads it, so this does not preserve the existing contents.
- `> notes.txt` truncates the file before writing standard output. ✓The `>` operator opens the destination for output and discards its previous contents first.
`>>` appends; `>` truncates before writing standard output.
8. `notes.txt.bz2` appears and the original is normally: Which result is expected?
- `notes.txt` remains and `notes.txt.gz` appears.The `.gz` suffix identifies gzip output, not the bzip2 format produced here.
- `notes.txt` remains and `notes.txt.zip` appears.bzip2 does not produce ZIP-format output; ZIP uses a different format and utility.
- `notes.txt.bz2` appears and the original is normally removed. ✓bzip2 normally creates the `.bz2` file and removes the uncompressed source after successful compression.
- A tar archive named `notes.txt.bz2` contains the uncompressed file.bzip2 compresses the file stream directly and does not create a tar archive.
bzip2 normally creates `notes.txt.bz2` and removes the source.
9. The dot is a regular-expression wildcard: What is the correct diagnosis and fix?
- The pattern is a shell glob; quote it with double quotes.grep interprets its quoted argument as a regular expression, not as a shell filename glob.
- grep cannot search punctuation, so remove the dot from the pattern.grep can search punctuation; the issue is wildcard interpretation rather than unsupported characters.
- The dot is a regular-expression wildcard; use `grep -F 'c.t' data.txt`. ✓In a basic regular expression, dot matches any character; `-F` requests literal fixed-string matching.
- Use `grep -E 'c.t' data.txt` because extended regex makes the dot literal.Extended regular expressions still treat dot as a wildcard, so `-E` does not make it literal.
Use `grep -F` for a literal fixed-string search; plain grep treats dot as a wildcard.
10. `xz ./source.txt`: Which command is valid?
- `xz ./source.txt` ✓xz compresses the file and normally creates `source.txt.xz` while removing the uncompressed source.
- `tar -Jcf source.txt.xz source.txt`This creates an xz-compressed tar archive, not the normal direct xz compression of the file.
- `cat source.txt`This reads the file but does not create xz-compressed output.
- `rm source.txt`This removes the source without producing xz-compressed output.
`xz ./source.txt` performs direct xz compression.
11. grep -i 'error' log.txt: Select TWO commands that search for error case-insensitively and print matching lines
Select two. More than one option is correct — every correct one is ticked below.
- grep -i 'error' log.txt ✓The `-i` option ignores letter case, so both Error and error match and print.
- grep -v -i 'error' log.txtThe `-v` option inverts selection, printing the nonmatching NOTICE line instead.
- grep -F 'Error' log.txtFixed-string matching does not ignore case, so it selects only the capitalized Error line.
- grep 'error' log.txtWithout `-i`, only the lowercase error line matches the case-sensitive pattern.
- grep -i -n 'error' log.txt ✓This also ignores case and prints both matching lines, adding their line numbers.
Select both commands using `-i`; `-n` may additionally display line numbers.
12. `./worker.sh "$@"`: Exhibit:
Exhibit:# inside research.sh
Select two. More than one option is correct — every correct one is ticked below.
- `./worker.sh $@`Unquoted `$@` permits word splitting and pathname expansion, which can alter arguments containing spaces or wildcard characters.
- `./worker.sh "$1 $2" "$3"`This combines the first two arguments and omits arguments after the third, so it does not forward every argument.
- `./worker.sh "$@"` ✓Quoted `"$@"` expands to one word per positional argument, preserving each argument boundary.
- `bash worker.sh "$@"` ✓Bash runs `worker.sh`, and quoted `"$@"` passes every positional argument separately.
- `./worker.sh "$*"`Quoted `"$*"` combines all positional arguments into one word, losing their original boundaries.
Forward arbitrary arguments with quoted `"$@"`.
185 more The Power of the Command Line questions
The remaining 185 questions in this domain are part of the full Linux Essentials bank — 885 questions, every option explained. Start with the free five-minute check and see your score per domain.
Test your Linux Essentials readiness — freeOther Linux Essentials domains
- Finding Your Way on a Linux System — 199 questions →
- The Linux Operating System — 178 questions →
- Security and File Permissions — 156 questions →
- The Linux Community and a Career in Open Source — 155 questions →
- All 885 Linux Essentials questions →
- Linux Essentials certification: requirements, cost and exam format →