Linux Essentials Power of the Command practice questions
7-day money-back guarantee — full refund within 7 days of purchase if you've completed under 20% of the questions. See pricing →
Certifications Tools Flashcards Career Paths Exam Guides Blog Pricing For Teams About

Linux Essentials The Power of the Command Line: 197 practice questions

Linux Essentials 197 questions 12 shown free

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?

Hard
On a shared training server, the current directory contains `report.txt` and `notes.txt`. Which GNU tar command creates `training.tar` containing both files?
  1. tar -czf report.txt notes.txt training.tar
    This treats `report.txt` as the archive filename and does not specify the requested output archive correctly.
  2. tar -cf training.tar report.txt notes.txt ✓
    The `-c` option creates an archive, and `-f` supplies its filename before the listed input files.
  3. tar -xvf training.tar report.txt notes.txt
    The `-x` operation extracts from an archive rather than creating a new archive.
  4. tar -tf training.tar report.txt notes.txt
    The `-t` operation lists archive members and does not bundle the supplied files.
The trap
Listing mode only inspects archive contents. The archive filename follows `-f` and must be training.tar. Extraction mode cannot create the requested archive.

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 `#`?

Easy
On a remote Linux guest, the file `names.txt` contains exactly three newline-terminated lines. What standard output results from `grep -v '^#' names.txt | wc -l` when exactly one line begins with `#`?
  1. 0
    Two nonmatching lines remain, so the pipeline does not produce an empty input.
  2. 3
    That would count all original lines, including the line removed by `grep -v`.
  3. 1
    That would count the excluded comment line rather than the lines passed through the pipeline.
  4. 2 ✓
    `grep -v` removes the matching comment line, and `wc -l` counts the two remaining newline characters.
The trap
The matching line does not reach `wc`. Inversion excludes matching lines from downstream input. Nonmatching lines are retained by inverted matching.

Inverted grep passes two lines, and `wc -l` counts their newline characters.

3. 3: What is the standard output?

Easy
Run this complete snippet in Bash with no startup files. Show standard output excluding the final newline.total=0 for value in 1 2; do total=$((total + value)); done printf '%s\n' "$total"What is the standard output?
  1. 12
    The loop performs arithmetic addition, not string concatenation or direct joining of its values.
  2. 3 ✓
    Bash adds one and two to the initial zero, then printf outputs the resulting total.
  3. 1
    The first iteration adds one, but the second iteration also adds two.
  4. 0
    The loop updates total twice, so its initial value is not the final result.
The trap
Both listed loop values are processed. Arithmetic expansion adds numeric values instead. The loop performs two arithmetic additions.

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?

Easy
On a development laptop, `backup.tar` exists, and you must inspect its member names before extracting anything. Which command performs that inspection without extracting files?
  1. tar -tf backup.tar ✓
    GNU tar uses `-t` to list archive members and `-f` to identify the archive file.
  2. tar -cf backup.tar
    The `-c` option creates an archive and does not list the contents of an existing archive.
  3. tar -xf backup.tar
    The `-x` option extracts archive members, which violates the requirement to inspect without extraction.
  4. gzip -t backup.tar
    `gzip -t` tests compressed-stream integrity and does not list tar archive member names.
The trap
Create mode is not archive inspection. Extraction changes the filesystem rather than only listing. Integrity testing is different from listing archive entries.

Use tar list mode, `-t`, with `-f backup.tar` to inspect members without extraction.

5. generate_report 2> errors.log: Which command does that?

Medium
In Bash, working in /home/student, the command `generate_report` writes normal output to standard output and diagnostics to standard error. You want normal output on the terminal and diagnostics in errors.log. Which command does that?
  1. generate_report
    This leaves both output streams connected to the terminal instead of saving diagnostics separately.
  2. generate_report > errors.log 2>&1
    This sends both standard output and standard error into errors.log, not just diagnostics.
  3. generate_report > errors.log
    This redirects standard output, while standard error still appears on the terminal.
  4. generate_report 2> errors.log ✓
    File descriptor 2 is standard error, so only diagnostics go into errors.log.
The trap
Overlooks redirection ordering and combined streams. Confuses standard output with standard error. Confuses displaying output with redirecting only standard error.

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?

Easy
In Bash, `report.txt` is one existing regular file. You have read permission for it and write permission in its directory. You want a gzip-compressed copy while keeping the original. Which is the least disruptive valid command?
  1. `cp report.txt report.txt.gz`
    `cp` creates a second uncompressed copy; changing the filename does not create gzip data.
  2. `tar -czf report.txt.gz report.txt`
    This creates a gzip-compressed tar archive, not a gzip-compressed copy of the file itself.
  3. `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.
  4. `gzip report.txt`
    Ordinary gzip compression normally replaces `report.txt` with `report.txt.gz`, so the original is not retained.
The trap
Forgets gzip's normal source-file behavior. Confuses copying with compression. Confuses archiving with direct file compression.

Use `gzip -c` and redirect its output.

7. `>> notes.txt` appends standard output to the existing: Select TWO true statements about these redirections.

Medium
In Bash, `notes.txt` exists and contains important text. Select TWO true statements about these redirections.

Select two. More than one option is correct — every correct one is ticked below.

  1. `>> notes.txt` appends standard output to the existing file. ✓
    The `>>` operator writes standard output after the existing contents without truncating them.
  2. `> notes.txt` preserves existing contents and adds output afterward.
    The single `>` operator truncates the destination before writing standard output; appending requires `>>`.
  3. 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>`.
  4. `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.
  5. `> notes.txt` truncates the file before writing standard output. ✓
    The `>` operator opens the destination for output and discards its previous contents first.
The trap
Confuses truncation with appending. Confuses standard output with standard error. Overlooks that redirection is set up before the command runs.

`>>` appends; `>` truncates before writing standard output.

8. `notes.txt.bz2` appears and the original is normally: Which result is expected?

Medium
On a GNU/Linux training server, the current directory is writable, `notes.txt` is one existing readable regular file, and no archive is involved. You run:bzip2 notes.txtWhich result is expected?
  1. `notes.txt` remains and `notes.txt.gz` appears.
    The `.gz` suffix identifies gzip output, not the bzip2 format produced here.
  2. `notes.txt` remains and `notes.txt.zip` appears.
    bzip2 does not produce ZIP-format output; ZIP uses a different format and utility.
  3. `notes.txt.bz2` appears and the original is normally removed. ✓
    bzip2 normally creates the `.bz2` file and removes the uncompressed source after successful compression.
  4. A tar archive named `notes.txt.bz2` contains the uncompressed file.
    bzip2 compresses the file stream directly and does not create a tar archive.
The trap
Confuses bzip2 with zip. Confuses compression with archiving. Confuses bzip2 with gzip.

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?

Medium
In Bash, `data.txt` contains the lines `cat`, `c.t`, and `cot`. A learner expects `grep 'c.t' data.txt` to find only the literal `c.t`. What is the correct diagnosis and fix?
  1. 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.
  2. grep cannot search punctuation, so remove the dot from the pattern.
    grep can search punctuation; the issue is wildcard interpretation rather than unsupported characters.
  3. 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.
  4. 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.
The trap
Assumes punctuation is unsearchable. Confuses shell globbing with grep pattern matching. Misunderstands extended regular-expression syntax.

Use `grep -F` for a literal fixed-string search; plain grep treats dot as a wildcard.

10. `xz ./source.txt`: Which command is valid?

Easy
On a development laptop, `source.txt` is one existing regular file in the current directory. You have read permission for it and write permission in that directory. You want xz compression and accept xz's normal source-file behavior. Which command is valid?
  1. `xz ./source.txt` ✓
    xz compresses the file and normally creates `source.txt.xz` while removing the uncompressed source.
  2. `tar -Jcf source.txt.xz source.txt`
    This creates an xz-compressed tar archive, not the normal direct xz compression of the file.
  3. `cat source.txt`
    This reads the file but does not create xz-compressed output.
  4. `rm source.txt`
    This removes the source without producing xz-compressed output.
The trap
Chooses deletion instead of compression. Confuses displaying data with compressing it. Confuses archive creation with direct compression.

`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

Hard
In GNU Bash, `log.txt` contains exactly these lines: `Error`, `error`, and `NOTICE`. 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.

  1. grep -i 'error' log.txt ✓
    The `-i` option ignores letter case, so both Error and error match and print.
  2. grep -v -i 'error' log.txt
    The `-v` option inverts selection, printing the nonmatching NOTICE line instead.
  3. grep -F 'Error' log.txt
    Fixed-string matching does not ignore case, so it selects only the capitalized Error line.
  4. grep 'error' log.txt
    Without `-i`, only the lowercase error line matches the case-sensitive pattern.
  5. grep -i -n 'error' log.txt ✓
    This also ignores case and prints both matching lines, adding their line numbers.
The trap
Omits the case-insensitive option. Confuses fixed strings with case insensitivity. Inverts matches instead of selecting them.

Select both commands using `-i`; `-n` may additionally display line numbers.

12. `./worker.sh "$@"`: Exhibit:

Easy
In Bash, a research script must forward every argument to `worker.sh`, including arguments containing spaces or wildcard characters. `worker.sh` is a Bash script in the current directory and has execute permission. Select TWO valid commands.

Exhibit:# inside research.sh

Select two. More than one option is correct — every correct one is ticked below.

  1. `./worker.sh $@`
    Unquoted `$@` permits word splitting and pathname expansion, which can alter arguments containing spaces or wildcard characters.
  2. `./worker.sh "$1 $2" "$3"`
    This combines the first two arguments and omits arguments after the third, so it does not forward every argument.
  3. `./worker.sh "$@"` ✓
    Quoted `"$@"` expands to one word per positional argument, preserving each argument boundary.
  4. `bash worker.sh "$@"` ✓
    Bash runs `worker.sh`, and quoted `"$@"` passes every positional argument separately.
  5. `./worker.sh "$*"`
    Quoted `"$*"` combines all positional arguments into one word, losing their original boundaries.
The trap
Confuses `"$*"` with `"$@"`. Forgets to quote the expansion. Combines and omits positional arguments.

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 — free

Other Linux Essentials domains

Part of the Certsqill Linux Essentials question bank · The Power of the Command Line · Every answer, right and wrong, comes with its own explanation.