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

Question 120

An interactive non-login Bash shell must load user aliases automatically. Which startup file is commonly used?

  1. DISPLAY
  2. ~/.bashrc
  3. PS1
  4. source ./env.sh

Explanation

Correct Answer

B:

Bash normally reads ~/.bashrc for interactive non-login sessions. Login-shell startup may involve files such as ~/.bash_profile instead.

Incorrect Answers

A:

DISPLAY identifies the X server connection for X11 clients; that changes a different part of the system; the requested outcome is configuring interactive non-login Bash behavior.

C:

PS1 expands escape sequences into the interactive primary prompt; it will not provide configuring interactive non-login Bash behavior under these conditions.

D:

source executes shell code in the current shell rather than launching an independent process; using it would leave configuring interactive non-login Bash behavior unresolved.

Question 121

A script should find the current user's home directory without assuming a fixed account name. Which variable is appropriate?

  1. HOME
  2. ~/.bashrc
  3. PS1
  4. DISPLAY

Explanation

Correct Answer

A:

HOME normally contains the current account's configured home path. It is used by applications and shells for per-user locations.

Incorrect Answers

B:

Bash normally reads ~/.bashrc for interactive non-login sessions; the evidence calls for finding a user's home directory from the environment, not merely this separate operation.

C:

PS1 expands escape sequences into the interactive primary prompt; the task involves finding a user's home directory from the environment, whereas this addresses another subsystem.

D:

DISPLAY identifies the X server connection for X11 clients; its scope differs from finding a user's home directory from the environment, so it cannot meet the stated requirement.

Question 122

A shell prompt should display a customized username and working-directory format. Which variable controls Bash's primary prompt?

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

Explanation

Correct Answer

B:

PS1 expands escape sequences into the interactive primary prompt. Its value changes display formatting, not file access rights.

Incorrect Answers

A:

DISPLAY identifies the X server connection for X11 clients; the administrator instead needs formatting the interactive Bash prompt; this option serves a different purpose.

C:

source executes shell code in the current shell rather than launching an independent process; that changes a different part of the system; the requested outcome is formatting the interactive Bash prompt.

D:

Bash normally reads ~/.bashrc for interactive non-login sessions; this does not achieve formatting the interactive Bash prompt on the system described.

E:

HOME normally contains the current account's configured home path; it will not provide formatting the interactive Bash prompt under these conditions.

Question 123

A CSV export needs a reliable total count of lines for a sanity check. Which tool provides this?

  1. xargs
  2. tail -n 30 service.log
  3. wc -l export.csv
  4. awk '{print $3}' report.txt

Explanation

Correct Answer

C:

wc -l counts newline characters in a text stream. It does not validate CSV column structure or quoted multiline fields.

Incorrect Answers

A:

xargs constructs command arguments from input items; using it would leave counting lines in a text file unresolved.

B:

tail selects records from the end of a file and can optionally follow new appends; the requirement is counting lines in a text file, outside the effect of this choice.

D:

awk evaluates an action per input record, with $3 referring to the third whitespace-delimited field by default; the evidence calls for counting lines in a text file, not merely this separate operation.

Question 124

A beginner is editing a server configuration in nano and needs to save the buffer. Which shortcut begins writing the file?

  1. cut -d: -f1 input.txt
  2. Ctrl+O in nano
  3. :wq
  4. sed 's/old/new/g' config.ini

Explanation

Correct Answer

B:

Nano's Write Out shortcut prompts for the destination filename and saves the text. It does not terminate the editor by itself.

Incorrect Answers

A:

cut can extract selected delimiter-separated fields; its scope differs from saving edits from the nano interface, so it cannot meet the stated requirement.

C:

The :wq Ex command writes the buffer and quits when successful; the administrator instead needs saving edits from the nano interface; this option serves a different purpose.

D:

sed transforms text as it passes through its editing script; it answers a neighboring question rather than saving edits from the nano interface.

Question 125

A long log needs its most recent 30 lines printed. Which command fits?

  1. awk '{print $3}' report.txt
  2. sed 's/old/new/g' config.ini
  3. cut -d: -f1 input.txt
  4. tail -n 30 service.log

Explanation

Correct Answer

D:

tail selects records from the end of a file and can optionally follow new appends. It is useful for recent log activity.

Incorrect Answers

A:

awk evaluates an action per input record, with $3 referring to the third whitespace-delimited field by default; this does not achieve displaying the last thirty log records on the system described.

B:

sed transforms text as it passes through its editing script; it will not provide displaying the last thirty log records under these conditions.

C:

cut can extract selected delimiter-separated fields; using it would leave displaying the last thirty log records unresolved.

Question 126

A shell command should append new diagnostic output to an existing log without truncating it. Which redirection applies?

  1. command <<< "$value"
  2. command < input.txt
  3. command 2>error.log
  4. command >> logfile

Explanation

Correct Answer

D:

Double greater-than redirects standard output in append mode. A single greater-than normally truncates the destination first.

Incorrect Answers

A:

A Bash here-string supplies a string to standard input, with a terminating newline; the evidence calls for appending stdout rather than overwriting a file, not merely this separate operation.

B:

The less-than operator opens a file as standard input for the process; the task involves appending stdout rather than overwriting a file, whereas this addresses another subsystem.

C:

File descriptor 2 represents standard error in the shell; its scope differs from appending stdout rather than overwriting a file, so it cannot meet the stated requirement.

Question 127

A generated report needs numeric lines sorted as integers rather than alphabetically. Which command does this?

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

Explanation

Correct Answer

C:

sort -n compares numerical values instead of plain character ordering. Alphabetical sorting could place 10 before 2.

Incorrect Answers

A:

cut can extract selected delimiter-separated fields; it answers a neighboring question rather than ordering integer values numerically.

B:

grep selects lines that match a pattern and prints matching records by default; that changes a different part of the system; the requested outcome is ordering integer values numerically.

D:

tail selects records from the end of a file and can optionally follow new appends; it will not provide ordering integer values numerically under these conditions.

Question 128

A noisy command should write only its errors to error.log while keeping stdout on screen. Which syntax is suitable?

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

Explanation

Correct Answer

A:

File descriptor 2 represents standard error in the shell. Redirecting it does not move ordinary standard output away from the terminal.

Incorrect Answers

B:

tee reads standard input and writes copies to standard output and named files; it does not deliver redirecting standard error without stdout, which is decisive in this scenario.

C:

The less-than operator opens a file as standard input for the process; the evidence calls for redirecting standard error without stdout, not merely this separate operation.

D:

Double greater-than redirects standard output in append mode; the task involves redirecting standard error without stdout, whereas this addresses another subsystem.

E:

A here-document provides literal or expanded lines as standard input until a delimiter is reached; its scope differs from redirecting standard error without stdout, so it cannot meet the stated requirement.

Question 129

A colon-delimited passwd-style file needs only the first field extracted. Which command is suitable?

  1. sed 's/old/new/g' config.ini
  2. cut -d: -f1 input.txt
  3. sort -n values.txt
  4. awk '{print $3}' report.txt

Explanation

Correct Answer

B:

cut can extract selected delimiter-separated fields. It works on existing field positions rather than evaluating full regular expressions.

Incorrect Answers

A:

sed transforms text as it passes through its editing script; that is not equivalent to selecting the first colon-separated field.

C:

sort -n compares numerical values instead of plain character ordering; it answers a neighboring question rather than selecting the first colon-separated field.

D:

awk evaluates an action per input record, with $3 referring to the third whitespace-delimited field by default; that changes a different part of the system; the requested outcome is selecting the first colon-separated field.

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.

CompTIA Linux+ (XK0-006) Practice Tests