CompTIA XK0-006 (CompTIA Linux+) Practice Test 14

Question 130

A script fails to find a tool installed in /opt/bin when invoked by name. Which environment variable controls executable searches?

  1. HOME
  2. source ./env.sh
  3. ~/.bashrc
  4. DISPLAY
  5. PS1
  6. PATH

Explanation

Correct Answer

F:

PATH is an ordered list of directories searched for external commands without slash-containing paths. Updating it affects command resolution in that shell environment.

Incorrect Answers

A:

HOME normally contains the current account's configured home path; it will not provide searching directories for an unqualified command under these conditions.

B:

source executes shell code in the current shell rather than launching an independent process; using it would leave searching directories for an unqualified command unresolved.

C:

Bash normally reads ~/.bashrc for interactive non-login sessions; the requirement is searching directories for an unqualified command, outside the effect of this choice.

D:

DISPLAY identifies the X server connection for X11 clients; it does not deliver searching directories for an unqualified command, which is decisive in this scenario.

E:

PS1 expands escape sequences into the interactive primary prompt; the evidence calls for searching directories for an unqualified command, not merely this separate operation.

Question 131

An environment setup script must modify variables in the caller's existing Bash process. Which operation should invoke it?

  1. source ./env.sh
  2. PS1
  3. PATH
  4. HOME

Explanation

Correct Answer

A:

source executes shell code in the current shell rather than launching an independent process. Variable assignments can therefore persist in the caller.

Incorrect Answers

B:

PS1 expands escape sequences into the interactive primary prompt; its scope differs from applying environment changes to the current shell, so it cannot meet the stated requirement.

C:

PATH is an ordered list of directories searched for external commands without slash-containing paths; that is not equivalent to applying environment changes to the current shell.

D:

HOME normally contains the current account's configured home path; the administrator instead needs applying environment changes to the current shell; this option serves a different purpose.

Question 132

A log must be filtered for lines containing the exact text ERROR. Which tool is a natural choice?

  1. tail -n 30 service.log
  2. cut -d: -f1 input.txt
  3. grep 'ERROR' app.log
  4. sort -n values.txt

Explanation

Correct Answer

C:

grep selects lines that match a pattern and prints matching records by default. It does not permanently edit the source file.

Incorrect Answers

A:

tail selects records from the end of a file and can optionally follow new appends; that changes a different part of the system; the requested outcome is selecting log lines that match text.

B:

cut can extract selected delimiter-separated fields; this does not achieve selecting log lines that match text on the system described.

D:

sort -n compares numerical values instead of plain character ordering; using it would leave selecting log lines that match text unresolved.

Question 133

A configuration file needs a noninteractive substitution in the displayed stream, leaving the original unchanged. Which command works?

  1. tail -n 30 service.log
  2. sed 's/old/new/g' config.ini
  3. uniq
  4. sort -n values.txt

Explanation

Correct Answer

B:

sed transforms text as it passes through its editing script. Without an in-place flag, output changes are not written back to the input file.

Incorrect Answers

A:

tail selects records from the end of a file and can optionally follow new appends; it does not deliver applying a text substitution only to output, which is decisive in this scenario.

C:

uniq removes consecutively repeated input records rather than converting character encodings or letter case; the task involves applying a text substitution only to output, whereas this addresses another subsystem.

D:

sort -n compares numerical values instead of plain character ordering; its scope differs from applying a text substitution only to output, so it cannot meet the stated requirement.

Question 134

A multi-line configuration snippet must be supplied to a command without creating a separate input file. Which Bash construct applies?

  1. command >> logfile
  2. command 2>error.log
  3. command < input.txt
  4. Here-document with <<EOF

Explanation

Correct Answer

D:

A here-document provides literal or expanded lines as standard input until a delimiter is reached. The quoting of the delimiter controls expansions.

Incorrect Answers

A:

Double greater-than redirects standard output in append mode; the administrator instead needs providing multiline inline standard input; this option serves a different purpose.

B:

File descriptor 2 represents standard error in the shell; it answers a neighboring question rather than providing multiline inline standard input.

C:

The less-than operator opens a file as standard input for the process; that changes a different part of the system; the requested outcome is providing multiline inline standard input.

Question 135

A tar archive's contents must be listed before any files are extracted. Which command accomplishes this?

  1. tar -tf backup.tar
  2. tar -czf site.tar.gz site/
  3. tar -cf backup.tar project/
  4. tar -xf backup.tar -C /restore
  5. cpio -o --null

Explanation

Correct Answer

A:

tar -t lists member names without writing archived files to disk. This helps inspect paths before restoring potentially unsafe content.

Incorrect Answers

B:

tar -z filters archive content through gzip during creation; the requirement is inspecting archived member names without extraction, outside the effect of this choice.

C:

tar -c creates an archive and -f selects the output filename; it does not deliver inspecting archived member names without extraction, which is decisive in this scenario.

D:

The -C option changes the extraction target before processing members; the evidence calls for inspecting archived member names without extraction, not merely this separate operation.

E:

cpio can create an archive from pathnames on stdin, and --null supports null-terminated names; the task involves inspecting archived member names without extraction, whereas this addresses another subsystem.

Question 136

A tarball should be extracted into a designated recovery directory instead of the working directory. Which invocation is appropriate?

  1. tar -czf site.tar.gz site/
  2. tar -xf backup.tar -C /restore
  3. tar -tf backup.tar
  4. cpio -o --null

Explanation

Correct Answer

B:

The -C option changes the extraction target before processing members. The destination directory must exist and archive paths should be reviewed.

Incorrect Answers

A:

tar -z filters archive content through gzip during creation; its scope differs from directing archive extraction to a target directory, so it cannot meet the stated requirement.

C:

tar -t lists member names without writing archived files to disk; the administrator instead needs directing archive extraction to a target directory; this option serves a different purpose.

D:

cpio can create an archive from pathnames on stdin, and --null supports null-terminated names; it answers a neighboring question rather than directing archive extraction to a target directory.

Question 137

A directory is to be archived and compressed with gzip in a single tar command. Which flags accomplish this?

  1. tar -xf backup.tar etc/hosts
  2. tar -czf site.tar.gz site/
  3. tar -tf backup.tar
  4. cpio -o --null

Explanation

Correct Answer

B:

tar -z filters archive content through gzip during creation. The .tar.gz extension is conventional but the compression choice is determined by the option.

Incorrect Answers

A:

Supplying a member name after the archive selects that specific entry for extraction; this does not achieve creating a gzip-compressed tar archive on the system described.

C:

tar -t lists member names without writing archived files to disk; using it would leave creating a gzip-compressed tar archive unresolved.

D:

cpio can create an archive from pathnames on stdin, and --null supports null-terminated names; the requirement is creating a gzip-compressed tar archive, outside the effect of this choice.

Question 138

A .bz2 file must be decompressed to standard output for another pipeline stage. Which syntax provides that?

  1. zgrep 'ERROR' access.log.gz
  2. xz
  3. gzip -k access.log
  4. bzip2 -dc report.bz2

Explanation

Correct Answer

D:

bzip2 can decompress to stdout with -dc rather than writing a recovered file. A downstream tool can process the stream.

Incorrect Answers

A:

zgrep decompresses gzip data for pattern matching and reports matching records; the evidence calls for streaming decompressed bzip2 content, not merely this separate operation.

B:

xz uses the LZMA2 compression format and often provides high compression ratios; the task involves streaming decompressed bzip2 content, whereas this addresses another subsystem.

C:

gzip compresses a file and -k keeps the source rather than deleting it; its scope differs from streaming decompressed bzip2 content, so it cannot meet the stated requirement.

Question 139

A backup operator needs to view gzip-compressed text one screen at a time without fully extracting it. Which utility fits?

  1. rsync -a -e ssh src/ host:/backup/
  2. zless access.log.gz
  3. rsync --delete
  4. ddrescue with a mapfile

Explanation

Correct Answer

B:

zless presents decompressed gzip text through a pager. It is suited for human inspection rather than archive creation or disk imaging.

Incorrect Answers

A:

rsync -a preserves many file attributes and can transfer only changed data over SSH; it answers a neighboring question rather than paging through gzip-compressed text.

C:

The --delete option removes destination-side files absent from the source within the synchronized scope; this does not achieve paging through gzip-compressed text on the system described.

D:

GNU ddrescue tracks which disk sectors were copied or failed in a mapfile; it will not provide paging through gzip-compressed text under these conditions.

Question 140

A single large log should be compressed using gzip while retaining the original for comparison. Which command is correct?

  1. bzip2 -dc report.bz2
  2. zgrep 'ERROR' access.log.gz
  3. gzip -k access.log
  4. xz

Explanation

Correct Answer

C:

gzip compresses a file and -k keeps the source rather than deleting it. The result is normally stored with a .gz suffix.

Incorrect Answers

A:

bzip2 can decompress to stdout with -dc rather than writing a recovered file; the requirement is preserving a source file while gzip-compressing it, outside the effect of this choice.

B:

zgrep decompresses gzip data for pattern matching and reports matching records; it does not deliver preserving a source file while gzip-compressing it, which is decisive in this scenario.

D:

xz uses the LZMA2 compression format and often provides high compression ratios; the task involves preserving a source file while gzip-compressing it, whereas this addresses another subsystem.

CompTIA Linux+ (XK0-006) Practice Tests