LPI 101-500 Practice Test Questions and Exam Dumps Part 16 Q301-320

View Full LPI 101-500 Exam Dumps and Practice Test Dumps

 

Question: 301. Which command can display all available locations of a command found through the shell’s command lookup mechanism?

  1. command -l
    2. whereis -a
    3. locate -c
    4. type -a

Correct Answer: 4. type -a

Explanation:

The type -a shell command can display all locations or definitions that the shell associates with a command name. This is useful when more than one executable with the same name exists in different directories in the user’s PATH. It can also reveal aliases, builtins, functions, or other command interpretations depending on the shell and command being examined. This differs from which, which commonly reports an executable path, although its behavior can vary between implementations. type -a is therefore useful for understanding exactly how a shell resolves a command name.

Question: 302. Which command can be used to determine how the current shell interprets a command name?

  1. type
    2. resolve
    3. inspect
    4. lookup

Correct Answer: 1. type

Explanation:

The type shell builtin identifies how a command name is interpreted by the current shell. It can indicate whether a name refers to an alias, shell builtin, function, keyword, or executable file. This makes it useful when troubleshooting unexpected command behavior. For example, if a command appears to execute a different program than expected, type can reveal whether an alias or function is overriding the expected executable. It is more informative in this context than simply inspecting the PATH, because command resolution can involve several shell-specific mechanisms beyond searching executable directories.

Question: 303. What does grep -v do?

  1. Searches only binary files
    2. Displays only matching lines
    3. Displays lines that do not match the pattern
    4. Replaces matching text

Correct Answer: 3. Displays lines that do not match the pattern

Explanation:

The -v option of grep inverts the normal matching behavior. Instead of displaying lines that match the supplied pattern, grep -v displays lines that do not match it. This is useful when filtering unwanted entries from command output or text files. For example, an administrator can use grep -v ‘^#’ to remove comment lines from output when examining configuration content. The option does not modify the original file. It simply changes which lines are selected for output. Combining -v with other grep options can create powerful text-filtering commands.

Question: 304. Which grep option enables extended regular expressions?

  1. -x
    2. -E
    3. -R
    4. -P

Correct Answer: 2. -E

Explanation:

The -E option tells grep to interpret the supplied pattern as an extended regular expression. Extended regular expressions provide additional operators that make certain patterns easier to express without requiring as many escape characters. For example, alternation can be expressed using |, and grouping can be performed with parentheses in extended regular-expression syntax. Basic grep uses basic regular expressions by default. The -R option instead performs recursive searching, while -x requires an entire line to match. Understanding -E is useful when constructing more sophisticated text-search patterns.

Question: 305. Which shell keyword can be used to mark a variable as read-only?

  1. constant
    2. fixed
    3. readonly
    4. protect

Correct Answer: 3. readonly

Explanation:

The readonly shell builtin marks a shell variable so that its value cannot normally be changed or unset during the lifetime of that shell. For example, readonly VERSION=1 creates a variable whose value is protected from later assignment. Read-only variables can be useful when a script needs to ensure that an important configuration value is not accidentally overwritten. This feature applies to shell variables and is enforced by the shell. It should not be confused with filesystem permissions, which control access to files and directories rather than whether a shell variable can be reassigned.

Question: 306. Which shell option causes an unset variable to produce an error when expanded?

  1. set -u
    2. set -x
    3. set -n
    4. set -v

Correct Answer: 1. set -u

Explanation:

The set -u shell option enables treatment of unset variables as errors when they are expanded, with some shell-specific exceptions. This can help identify typographical errors and missing variables in shell scripts. Without this option, an unset variable commonly expands to an empty string, which can sometimes cause a script to continue with unintended values. set -x instead traces commands as they are executed, while set -v displays shell input lines. Using set -u is therefore a useful defensive programming technique when scripts depend on variables that must be defined.

Question: 307. Which command executes a shell script in the current shell environment rather than starting a separate shell process for the script?

  1. run
    2. execfile
    3. source
    4. launch

Correct Answer: 2. source

Explanation:

The source command reads and executes commands from a file in the current shell environment. The shorthand . can also perform this operation in POSIX-compatible shells. This distinction matters because variables, functions, aliases, and other shell state created or modified by the sourced file can remain available in the current shell afterward. Running a script as a separate executable normally gives it its own shell environment, so changes to variables do not automatically affect the parent shell. source is frequently used for loading shell configuration files and environment-setting scripts.

Question: 308. Which command can display the value of a shell variable using formatted output?

  1. printf
    2. format
    3. display
    4. show

Correct Answer: 3. printf

Explanation:

The printf shell builtin produces formatted output and provides more predictable formatting control than many uses of echo. It supports format strings and conversion specifications, allowing scripts to control spacing, numeric formatting, and line endings precisely. For example, printf ‘%s\n’ “$HOME” can safely display the value of the HOME variable followed by a newline. This makes printf particularly useful in shell scripts where consistent output is important. Although echo is convenient for simple messages, printf is generally preferred when precise formatting or reliable handling of special characters is required.

Question: 309. What does the uniq command normally do when processing sorted input containing repeated lines?

  1. Deletes the input file
    2. Combines adjacent identical lines into a single displayed line
    3. Sorts the lines alphabetically
    4. Converts all lines to lowercase

Correct Answer: 2. Combines adjacent identical lines into a single displayed line

Explanation:

The uniq command removes repeated adjacent lines from its output. It does not independently sort its input, which is why sort is commonly used before uniq when the goal is to identify duplicate lines throughout an entire file. For example, sort names.txt | uniq can consolidate identical entries that were originally separated in the file. uniq also provides options for counting repeated lines and selecting specific occurrences. Its key behavior is based on adjacent identical lines, so understanding that limitation is important when designing text-processing pipelines.

Question: 310. Which option makes grep report the number of matching lines rather than displaying the matching lines themselves?

  1. -l
    2. -m
    3. -n
    4. -c

Correct Answer: 4. -c

Explanation:

The -c option causes grep to report a count of matching lines for each input file instead of displaying the matching lines themselves. This is useful when an administrator needs to determine how frequently a condition occurs without processing the complete matching output. The -n option adds line numbers to matching lines, while -l reports filenames containing matches. The count produced by -c represents matching lines rather than necessarily counting every occurrence of a pattern within each line. This distinction is important when interpreting search results programmatically.

Question: 311. Which sed expression replaces the first occurrence of old with new on each processed line?

  1. sed ‘s/old/new/’
    2. sed ‘r/old/new/’
    3. sed ‘c/old/new/’
    4. sed ‘x/old/new/’

Correct Answer: 4. sed ‘s/old/new/’

Explanation:

The s command in sed performs substitution. The expression s/old/new/ searches each processed line for the first occurrence of old and replaces it with new. By default, the substitution affects the first matching occurrence on each line; adding the g flag causes all matching occurrences on a line to be replaced. Unless an in-place editing option is used, sed normally writes the transformed content to standard output rather than changing the original file. This makes substitution useful in pipelines and scripts where modified output needs to be inspected or redirected.

Question: 312. Which awk option specifies the input field separator?

  1. -O
    2. -F
    3. -I
    4. -S

Correct Answer: 2. -F

Explanation:

The -F option specifies the field separator that awk should use when splitting input records into fields. For example, awk -F: ‘{print $1}’ /etc/passwd treats the colon character as the separator and prints the first field from each record. By default, awk commonly treats runs of whitespace as field separators. Explicitly specifying a separator is particularly useful when processing structured text such as colon-separated configuration or account files. The separator can be a literal character or an appropriate regular-expression pattern depending on the awk implementation and command being used.

Question: 313. What does sort -r do?

  1. Removes duplicate lines
    2. Sorts lines in reverse order
    3. Sorts only numeric values
    4. Randomizes the input

Correct Answer: 2. Sorts lines in reverse order

Explanation:

The -r option reverses the normal ordering used by sort. For a standard lexical sort, this means entries are presented in descending rather than ascending order. The option can also be combined with other sorting options. For example, sort -nr performs a numeric sort in reverse order, which is useful when placing the largest numbers first. sort -r does not remove duplicate entries or randomize data. Duplicate removal is commonly associated with uniq, while randomization requires a different tool or approach. Understanding option combinations is important when constructing shell pipelines.

Question: 314. Which command combines corresponding lines from two files side by side?

  1. merge
    2. join
    3. paste
    4. combine

Correct Answer: 3. paste

Explanation:

The paste command combines lines from multiple files and writes them side by side, normally separated by a tab character. For example, paste names.txt departments.txt can produce output where the first line of one file appears alongside the first line of the other file. This differs from join, which combines lines based on a common field and is more closely related to relational data processing. paste is useful for simple column-oriented combinations where corresponding line positions are important. Options can also change the delimiter or alter how input files are combined.

Question: 315. Which option controls the maximum number of arguments passed to each command invocation by xargs?

  1. -n
    2. -d
    3. -p
    4. -t

Correct Answer: 1. -n

Explanation:

The -n option of xargs specifies the maximum number of arguments that should be passed to each invocation of the command being executed. This can be useful when a command should process input in manageable groups rather than receiving every item at once. For example, xargs -n 2 command attempts to invoke command with up to two input arguments per invocation. Other xargs options serve different purposes, such as selecting delimiters, prompting before execution, or displaying commands. Proper use of -n can make batch processing more controlled and predictable.

Question: 316. Which option makes tee append output to a file instead of replacing its existing contents?

  1. -r
    2. -a
    3. -p
    4. -n

Correct Answer: 4. -a

Explanation:

The -a option causes tee to append its output to the specified file instead of overwriting the file’s existing contents. tee is useful when a command’s output needs to continue through a pipeline while also being saved to a file. For example, a command can send output through tee -a logfile, allowing the output to remain available to later pipeline stages while being appended to the log. Without -a, the specified file is normally overwritten. This makes the append option especially useful for accumulating command output over multiple operations.

Question: 317. Which shell builtin is commonly used to pause execution until a specified background process completes?

  1. wait
    2. hold
    3. sleep
    4. pause

Correct Answer: 1. wait

Explanation:

The wait builtin synchronizes a shell script with background processes. When a script launches a command asynchronously using &, the shell can continue immediately. If the script later needs to ensure that the background operation has completed, wait can be used with the relevant process ID or job specification. The command can also return the exit status of the process it waited for, allowing a script to react to success or failure. This differs from sleep, which merely delays execution for a period and does not verify whether a particular background process has finished.

Question: 318. What does fg %1 normally do in a shell with job control enabled?

  1. Terminates job 1
    2. Lists job 1
    3. Brings job 1 to the foreground
    4. Deletes job 1 from the job table

Correct Answer: 3. Brings job 1 to the foreground

Explanation:

The fg shell builtin brings a stopped or background job into the foreground. The %1 notation identifies job number 1 in the shell’s job-control table. When a job is brought to the foreground, the terminal becomes associated with that job, allowing interactive input and job-control signals to be directed to it. This differs from bg, which resumes a stopped job in the background. jobs is used to list managed jobs, while disown can remove a job from the shell’s job table. Job specifications such as %1 are shell-specific job-control notation.

Question: 319. Which command can display only the number of lines in a text file?

  1. wc -w
    2. wc -c
    3. wc -m
    4. wc -l

Correct Answer: 4. wc -l

Explanation:

The wc -l command counts newline characters and is commonly used to report the number of lines in a text file. This is useful for quickly determining the approximate record count of line-oriented data or verifying the size of generated output. The related wc -w option counts words, wc -c counts bytes, and wc -m counts characters where supported. The distinction between bytes and characters can matter with multibyte encodings. In normal text-processing tasks, wc -l is a simple and widely used way to obtain a line count.

Question: 320. Which shell feature allows a command to continue only when the preceding command succeeds?

  1. ||
    2. &&
    3. ;;
    4. |

Correct Answer: 2. &&

Explanation:

The && operator connects two commands so that the second command is executed only if the first command exits successfully, normally with an exit status of zero. This is useful for conditional command execution in shell scripts and interactive administration. For example, mkdir project && cd project attempts to change into the directory only if the directory creation succeeds. The || operator provides the opposite style of conditional behavior by executing the following command when the preceding command fails. The pipe operator | instead connects standard output from one command to standard input of another.