LPI 101-500 Practice Test Questions and Exam Dumps Part 4 Q61-80

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

 

Question: 61. Which command is commonly used to view a text file one screen at a time with support for scrolling backward and forward?

  1. less
    2. cat
    3. head
    4. echo

Correct Answer: 1. less

Explanation:

The less command is commonly used to view text files interactively, one screen at a time. Unlike cat, which normally sends an entire file directly to standard output, less allows the user to scroll forward and backward through the content. It is especially useful for examining large log files or configuration files without displaying everything at once. Users can search within the displayed content and navigate through the file using keyboard commands. The head command displays the beginning of a file, while echo prints specified text. Therefore, less is the appropriate command for interactive text-file viewing.

Question: 62. Which command sorts lines of text alphabetically by default?

  1. order
    2. sort
    3. arrange
    4. rank

Correct Answer: 2. sort

Explanation:

The sort command arranges lines of text according to specified sorting rules. By default, it performs a lexicographic sort, which generally means arranging lines according to their character order. It can also sort numerically, reverse the order, or use particular fields as sorting keys. For example, sort names.txt produces sorted output from the lines in the file. The other commands listed are not standard Linux utilities for performing general text sorting. sort is frequently combined with commands such as uniq when processing and analyzing text data. Understanding basic text-processing commands is an important Linux administration skill.

Question: 63. Which command removes adjacent duplicate lines from sorted or appropriately grouped input?

  1. duplicate
    2. unique
    3. uniq
    4. dedupe

Correct Answer: 3. uniq

Explanation:

The uniq command is used to report or remove repeated adjacent lines from input. A common pattern is to combine sort and uniq, such as sort names.txt | uniq, because uniq only identifies consecutive duplicate lines rather than searching the entire input for duplicates regardless of position. It also provides options for counting occurrences and displaying only repeated or unique lines. The commands duplicate, unique, and dedupe are not standard Linux utilities for this purpose. Understanding the relationship between sort and uniq is useful when processing lists, logs, and other structured text data.

Question: 64. Which command can extract selected characters or fields from each line of text?

  1. cut
    2. slice
    3. field
    4. extract

Correct Answer: 1. cut

Explanation:

The cut command extracts selected portions of each line of input. It can work with character positions, byte positions, or fields separated by a specified delimiter. For example, cut -d: -f1 /etc/passwd can extract the first field from each colon-separated line. This makes cut useful for processing structured text and command output. The commands slice, field, and extract are not standard general-purpose Linux replacements for cut. It is important to understand the difference between selecting character ranges and selecting delimiter-separated fields when using this command.

Question: 65. Which command can translate or replace individual characters in a stream of text?

  1. replace
    2. convert
    3. tr
    4. change

Correct Answer: 3. tr

Explanation:

The tr command translates, replaces, or deletes characters from standard input and writes the result to standard output. For example, tr ‘a-z’ ‘A-Z’ can convert lowercase letters to uppercase letters. It can also remove selected characters using appropriate options. Because tr normally operates on standard input rather than directly modifying a file, it is commonly used in pipelines. The commands replace, convert, and change are not standard Linux utilities serving this exact purpose. tr is particularly useful for simple character-level transformations during shell scripting and text processing.

Question: 66. Which command displays input on standard output while also writing it to one or more files?

  1. tee
    2. split
    3. copyout
    4. duplicate

Correct Answer: 1. tee

Explanation:

The tee command reads data from standard input and writes it both to standard output and to one or more files. This is useful when a user wants to save command output while still seeing it in the terminal. For example, command | tee output.txt displays the command’s output and simultaneously writes it to output.txt. With the appropriate option, tee can append rather than overwrite a file. The commands split, copyout, and duplicate do not provide this standard pipeline behavior. tee is therefore an important utility for shell pipelines and troubleshooting.

Question: 67. Which command is commonly used to execute a command once for each item received from standard input?

  1. each
    2. apply
    3. xargs
    4. foreach

Correct Answer: 3. xargs

Explanation:

The xargs command builds and executes commands using items supplied through standard input. It is particularly useful when the output of one command needs to become arguments for another command. For example, a list of filenames can be passed to another utility through a pipeline using xargs. Depending on its options and the input, xargs can execute the target command multiple times, grouping arguments efficiently. The commands each, apply, and foreach are not standard Linux utilities providing this functionality. Care should be taken with filenames containing spaces or special characters, where appropriate quoting and null-delimited input may be needed.

Question: 68. Which shell syntax performs command substitution and replaces the command with its output?

  1. ${command}
    2. $(command)
    3. <command>
    4. [command]

Correct Answer: 2. $(command)

Explanation:

The $(command) syntax performs command substitution in common Unix shells. The shell executes the command inside the parentheses and substitutes its standard output into the surrounding command line. For example, echo “Today is $(date)” executes date and places its output into the string before echo runs. Command substitution is widely used in shell scripts and interactive commands when the result of one command needs to become part of another command. Although older shell syntax using backticks can also perform command substitution, $(…) is generally clearer and easier to nest.

Question: 69. In a typical POSIX shell, which type of quotes prevents variable expansion and command substitution inside the quoted text?

  1. Double quotes ” “
    2. Parentheses ( )
    3. Brackets [ ]
    4. Single quotes ‘ ‘

Correct Answer: 4. Single quotes ‘ ‘

Explanation:

Single quotes preserve the literal meaning of almost all characters inside them in a POSIX shell. Variable references such as $HOME and command substitutions such as $(date) are not expanded when enclosed in single quotes. Double quotes provide protection from word splitting and pathname expansion but still allow variable expansion and command substitution. This distinction is important when constructing shell commands and scripts that contain special characters or literal dollar signs. Parentheses and brackets have other shell meanings and do not provide the same general quoting behavior. Therefore, single quotes are the correct answer for preventing these expansions.

Question: 70. Which shell character is commonly used to escape the special meaning of the next character?

  1. #
    2. &
    3. \
    4. @

Correct Answer: 3. \

Explanation:

The backslash character, \, is commonly used by the shell to escape the special meaning of the character that follows it. For example, echo \$HOME can display the literal text $HOME rather than expanding the variable. Similarly, a backslash can be used to include spaces or other special characters in appropriate shell contexts. The # character commonly begins comments in shell scripts, & can be used for background execution, and @ has other contextual uses but is not the standard general-purpose escape character. Understanding escaping is essential when working with shell metacharacters and filenames.

Question: 71. Which path represents an absolute path in Linux?

  1. documents/report.txt
    2. ../report.txt
    3. ./report.txt
    4. /home/user/report.txt

Correct Answer: 4. /home/user/report.txt

Explanation:

An absolute path begins at the root directory, represented by /, and identifies a location independently of the user’s current working directory. /home/user/report.txt is therefore an absolute path because it starts from the root and provides the complete path to the file. In contrast, documents/report.txt, ../report.txt, and ./report.txt are relative paths whose meanings depend on the current working directory. Understanding the difference is important when writing shell commands and scripts because absolute paths provide a fixed reference while relative paths depend on where the command is executed.

Question: 72. Which command creates a hard link to an existing file?

  1. ln
    2. linkfile
    3. ln -s
    4. hardlink

Correct Answer: 1. ln

Explanation:

The ln command creates links between filesystem directory entries and files. When used without the -s option, ln normally creates a hard link. A hard link refers to the same underlying inode as the original file, so both directory entries refer to the same file data. By contrast, ln -s creates a symbolic link, which stores a path referring to another file or directory. The commands linkfile and hardlink are not the standard general-purpose Linux commands for creating hard links. Hard links generally cannot cross filesystem boundaries and have restrictions concerning directories.

Question: 73. Which command displays detailed metadata about a file, including information such as its inode, permissions, size, and timestamps?

  1. metadata
    2. stat
    3. fileinfo
    4. details

Correct Answer: 2. stat

Explanation:

The stat command displays detailed information about a file or filesystem object. Its output can include the file size, inode number, permissions, ownership, timestamps, and file type. This makes stat useful when ordinary directory listings do not provide enough information for troubleshooting or administration. The file command can identify the general type of a file, but it does not provide the same detailed metadata. metadata, fileinfo, and details are not the standard Linux command represented here. Therefore, stat is the correct utility for examining detailed filesystem metadata.

Question: 74. Which command extracts the final component of a pathname?

  1. pathpart
    2. dirname
    3. basename
    4. lastpath

Correct Answer: 3. basename

Explanation:

The basename command extracts the final component of a pathname. For example, basename /home/user/report.txt returns report.txt. This is useful in shell scripts when a script needs to separate a filename from the directory portion of a path. The complementary dirname command extracts the directory portion instead. The commands pathpart and lastpath are not standard Linux utilities for this purpose. Understanding basename and dirname is useful for manipulating paths without manually processing strings in shell scripts.

Question: 75. Which command outputs a specified string or the value of a variable to standard output?

  1. echo
    2. display
    3. printtext
    4. show

Correct Answer: 1. echo

Explanation:

The echo command writes specified text or expanded variable values to standard output. It is commonly used interactively and within shell scripts to display messages or simple values. For example, echo “$HOME” displays the value of the HOME environment variable. Shell implementations may provide echo as a builtin, and its behavior for certain escape sequences can vary between implementations, which is one reason printf is often preferred for portable formatted output. Nevertheless, echo remains a fundamental command for basic shell output. The other listed commands are not standard general-purpose replacements for echo.

Question: 76. Which command is generally preferred for portable formatted output in shell scripts?

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

Correct Answer: 2. printf

Explanation:

The printf command provides formatted output and is generally preferred over echo when predictable behavior is important in shell scripts. It supports format specifications such as %s, %d, and %f, allowing scripts to control how values are displayed. For example, printf “User: %s\n” “$USER” produces predictable formatted output. Although echo is convenient for simple messages, its handling of certain options and escape sequences can vary among implementations. printf follows well-defined formatting behavior and is therefore particularly useful in portable shell scripting. The other choices are not standard replacements for formatted shell output.

Question: 77. Which command makes a shell variable available to programs started from that shell?

  1. export
    2. share
    3. envset
    4. publish

Correct Answer: 1. export

Explanation:

The export command marks a shell variable so that it becomes part of the environment inherited by subsequently executed child processes. For example, export EDITOR=vim makes the EDITOR variable available to programs launched from that shell. A variable that has been assigned without being exported normally remains a shell variable and is not automatically inherited by child processes. The commands share, envset, and publish are not standard shell commands for exporting variables. Understanding the distinction between shell variables and environment variables is important when configuring programs and writing shell scripts.

Question: 78. Which command can display the environment variables available to a command or shell?

  1. vars
    2. environment
    3. env
    4. showenv

Correct Answer: 3. env

Explanation:

The env command can display the environment variables associated with the current execution environment. It can also be used to run a command with a modified environment. For example, running env without arguments generally displays environment variable assignments such as HOME, PATH, and USER. Environment variables differ from ordinary shell variables because exported variables are inherited by child processes. The commands vars, environment, and showenv are not the standard Linux utility represented here. Therefore, env is the correct command for viewing or manipulating the execution environment.

Question: 79. Which shell variable contains the exit status of the most recently executed foreground command?

  1. $STATUS
    2. $EXIT
    3. $RESULT
    4. $?

Correct Answer: 4. $?

Explanation:

The special shell parameter $? contains the exit status returned by the most recently executed foreground pipeline or command, depending on the shell context. A value of 0 conventionally indicates successful completion, while a nonzero value generally indicates some form of failure or special condition. Scripts can test this value to make decisions based on whether a previous command succeeded. For example, command; echo $? can display the command’s exit status. $STATUS, $EXIT, and $RESULT are not the standard special parameter used by POSIX shells for this purpose.

Question: 80. Which shell operator executes the command on the right only if the command on the left succeeds?

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

Correct Answer: 2. &&

Explanation:

The && operator allows commands to be conditionally chained so that the command on the right is executed only when the command on the left returns a successful exit status. For example, mkdir test && cd test attempts to change into the directory only if creating the directory succeeds. The || operator provides the opposite conditional behavior, executing the right-hand command when the left-hand command fails. The pipe | connects standard output to standard input, while ;; has specific uses within shell constructs such as case. Therefore, && is the correct operator for success-based command chaining.