LPI 101-500 Practice Test Questions and Exam Dumps Part 7 Q121-140

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

 

Question: 121. Which command can display the absolute path of a command by searching directories listed in PATH?

  1. findpath
    2. which
    3. searchcmd
    4. locatebin

Correct Answer: 2. which

Explanation:
The which command searches the directories listed in the PATH environment variable and can display the location of an executable command. For example, which bash may return the path to the Bash executable that would be selected through the current PATH configuration. This can be useful when multiple versions of a program are installed. which should be distinguished from type, which can also identify aliases, shell builtins, and functions. The find, locate, and similar commands have different purposes and do not specifically reproduce the normal executable lookup performed through the shell’s PATH.

Question: 122. Which command displays the current user’s group memberships?

  1. groups
    2. members
    3. usergroups
    4. group-list

Correct Answer: 1. groups

Explanation:
The groups command displays the groups to which a user belongs. When run without a username, it normally reports the groups associated with the current user. Group membership is important in Linux because groups can be used to organize permissions for shared files, directories, devices, and services. A user may belong to several supplementary groups in addition to the user’s primary group. The id command can provide more detailed identity information, including user and group IDs. Commands such as members and group-list are not standard replacements for groups on a typical Linux system.

Question: 123. Which command displays detailed user and group identity information?

  1. identity
    2. whoami
    3. id
    4. userinfo

Correct Answer: 3. id

Explanation:
The id command displays identity information for a user, including the numeric user ID, primary group ID, group names, and supplementary group memberships. When executed without a username, it normally reports information for the current user. This makes it useful when troubleshooting permission problems or verifying which accounts and groups are associated with a shell session. The whoami command is narrower because it normally prints the effective username. id provides a more complete identity overview, making it a useful command when investigating ownership and access-control behavior.

Question: 124. Which command can display the contents of the current directory in a long listing format?

  1. ls -l
    2. dir-long
    3. list -details
    4. show -l

Correct Answer: 1. ls -l

Explanation:
The ls -l command produces a long-format directory listing. The output commonly includes file type and permissions, link count, owner, group, file size, modification time, and filename. This format is particularly useful when examining ownership and permissions. The command can be combined with other options to modify sorting or display hidden files. The ls command itself lists directory contents, while the -l option requests the detailed long format. Commands such as dir-long, list -details, and show -l are not standard Linux equivalents for this operation.

Question: 125. Which shell feature expands $(command) by replacing it with the command’s output?

  1. Parameter substitution
    2. Command substitution
    3. Filename expansion
    4. Arithmetic expansion

Correct Answer: 2. Command substitution

Explanation:
Command substitution allows the output of one command to be incorporated into another command or assigned to a variable. The modern and preferred syntax is $(command). For example, today=$(date) stores the output of date in the variable today. The shell executes the command inside the substitution and replaces the construct with its output, subject to normal shell processing rules. This differs from filename expansion, which uses wildcard patterns such as *, and arithmetic expansion, which evaluates mathematical expressions. Command substitution is widely used in shell scripts to capture dynamic command output.

Question: 126. Which shell construct is used to perform arithmetic expansion?

  1. $((expression))
    2. $(expression)
    3. ${#expression}
    4. [[expression]]

Correct Answer: 1. $((expression))

Explanation:
The $((expression)) syntax performs arithmetic expansion in shells such as Bash. It allows arithmetic calculations to be evaluated and substituted into a command. For example, echo $((5 + 3)) produces 8. Arithmetic expansion supports common mathematical operations and can use shell variables without the same quoting requirements associated with ordinary text expansion. $(…) is command substitution and executes a command, while ${…} represents parameter expansion. The [[…]] construct is used for conditional expressions in shells such as Bash and is not the standard syntax for arithmetic expansion.

Question: 127. Which shell variable contains the directories searched for executable commands?

  1. $HOME
    2. $SHELL
    3. $PATH
    4. $PWD

Correct Answer: 3. $PATH

Explanation:
The PATH environment variable contains a colon-separated list of directories that the shell searches when the user enters a command without specifying its path. For example, when a user enters ls, the shell searches the directories listed in PATH until it finds an appropriate executable or command definition. $HOME identifies the user’s home directory, $SHELL commonly identifies the user’s login shell, and $PWD represents the current working directory in many shells. Understanding PATH is important when commands cannot be found or when multiple versions of an executable are installed.

Question: 128. Which shell variable commonly identifies the user’s home directory?

  1. $HOME
    2. $USERDIR
    3. $PWD
    4. $ROOT

Correct Answer: 1. $HOME

Explanation:
The HOME environment variable normally contains the path to the current user’s home directory. Commands and applications can use $HOME when they need to refer to user-specific configuration or data without hard-coding a particular pathname. For example, cd “$HOME” changes to the user’s home directory. $PWD generally represents the current working directory, while $PATH contains command-search directories. The name $ROOT does not normally represent the current user’s home directory. Understanding standard shell variables helps users write portable shell commands and scripts that work across different user accounts.

Question: 129. Which command prints a text string or variable value to standard output?

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

Correct Answer: 2. echo

Explanation:
The echo command writes text or expanded variable values to standard output. For example, echo “$HOME” prints the current value of the HOME variable. It is commonly used in shell scripts to display messages and inspect variable values. Although printf is often preferred for more precise and portable formatted output, echo remains a simple and widely used command. Shell behavior for certain echo options and escape sequences can vary, which is one reason printf is often recommended for complex output requirements. The other commands listed are not standard shell commands for this purpose.

Question: 130. Which command provides formatted output and is generally more predictable than echo for shell scripting?

  1. format
    2. printf
    3. print
    4. out

Correct Answer: 2. printf

Explanation:
The printf command produces formatted output according to a specified format string. It is especially useful in shell scripts because its behavior is generally more consistent and predictable than echo when handling escape sequences and formatting options. For example, printf ‘%s\n’ “$HOME” prints a variable followed by a newline. It also supports format specifications for numbers and text. While echo is convenient for simple messages, printf is better suited to controlled output. The commands format, print, and out are not standard replacements for the shell’s printf utility.

Question: 131. Which command displays the last portion of a text file by default?

  1. bottom
    2. tail
    3. end
    4. lastlines

Correct Answer: 2. tail

Explanation:
The tail command displays the end of a file. By default, it commonly shows the final 10 lines, although the number can be changed with options such as -n. A particularly useful feature is tail -f, which follows a file as new content is appended, making it valuable for monitoring log files. The head command performs the complementary operation by displaying the beginning of a file. Commands such as bottom, end, and lastlines are not standard Linux utilities for displaying the end of a file.

Question: 132. Which command displays the beginning portion of a text file by default?

  1. head
    2. start
    3. first
    4. topfile

Correct Answer: 1. head

Explanation:
The head command displays the beginning of a file. By default, it normally prints the first 10 lines, although options can be used to request a different number of lines or bytes. This makes head useful for quickly inspecting the structure or initial contents of a file without opening the entire file. It is often paired conceptually with tail, which displays the end of a file. Unlike an interactive pager such as less, head simply outputs the requested initial portion and returns control to the shell.

Question: 133. Which command can display a text file one screen at a time while allowing interactive navigation?

  1. cat
    2. less
    3. showfile
    4. page

Correct Answer: 2. less

Explanation:
The less command is an interactive pager that allows users to view text one screen at a time. It supports navigation through the file, searching for text, and moving forward or backward without loading the entire file into a simple terminal output stream. This makes it especially useful for large log files, documentation, and command output. The cat command generally sends the entire requested file directly to standard output, which can quickly scroll past the terminal. less therefore provides a more practical interface for examining large amounts of text.

Question: 134. Which command counts lines, words, and bytes in a file?

  1. count
    2. measure
    3. wc
    4. stattext

Correct Answer: 3. wc

Explanation:
The wc command reports counts for text input. Without additional options, it commonly displays the number of lines, words, and bytes for a file. Options such as -l, -w, and -c can request individual types of counts. This makes wc useful in shell pipelines when administrators or scripts need basic statistics about text. For example, wc -l file.txt reports the number of newline characters, which is commonly interpreted as the number of lines in a normal text file. Commands such as count and measure are not standard Linux replacements.

Question: 135. Which command searches for lines containing a specified text pattern?

  1. grep
    2. searchtext
    3. findtext
    4. scan

Correct Answer: 1. grep

Explanation:
The grep command searches input for lines matching a specified pattern and prints matching lines by default. It is one of the most commonly used tools in Linux pipelines and text-processing tasks. For example, grep ‘error’ logfile searches a log file for lines containing the specified pattern. Options can enable case-insensitive matching, recursive searching, line numbering, and other behaviors. grep can work with regular expressions, giving it considerable flexibility. It is distinct from find, which searches for filesystem objects based on criteria such as name, type, or permissions.

Question: 136. Which command searches for files and directories based on specified criteria within a filesystem hierarchy?

  1. grep
    2. find
    3. searchfs
    4. locate-text

Correct Answer: 2. find

Explanation:
The find command searches a filesystem hierarchy and can select files or directories based on many criteria, including pathname, file type, size, ownership, permissions, and modification time. It can also perform actions on matching objects when appropriate options are supplied. For example, a user can search for regular files beneath a specified directory using find. This differs from grep, which searches text content, and from locate, which normally searches a prebuilt filename database. find is particularly powerful because it performs a direct filesystem traversal and supports complex combinations of selection criteria.

Question: 137. Which command displays the type of data contained in a file based on its contents?

  1. file
    2. typeof
    3. identify
    4. datatype

Correct Answer: 1. file

Explanation:
The file command examines a file and attempts to identify its type based largely on its contents and associated signatures rather than relying solely on the filename extension. For example, it can distinguish text files, executable binaries, archives, images, and other formats. This is useful when a file has an unusual or misleading extension or when an administrator needs to quickly determine what kind of data it contains. The commands typeof, identify, and datatype are not standard Linux replacements. file is therefore a useful diagnostic tool for basic file identification.

Question: 138. Which command creates an empty file or updates the modification timestamp of an existing file?

  1. makefile
    2. newfile
    3. touch
    4. create

Correct Answer: 3. touch

Explanation:
The touch command can create an empty file if the specified file does not already exist. If the file exists, touch normally updates its access and modification timestamps unless options are used to alter that behavior. This makes it useful for creating placeholder files and manipulating timestamps in administrative or scripting tasks. touch does not normally overwrite the existing contents of a file. Commands such as makefile, newfile, and create are not standard Linux commands for this purpose. Understanding touch is also helpful when working with build systems and scripts that use timestamps.

Question: 139. Which command changes the group ownership of a file or directory?

  1. groupmod
    2. chgrp
    3. setgroup
    4. groupown

Correct Answer: 2. chgrp

Explanation:
The chgrp command changes the group ownership associated with a file or directory. For example, chgrp developers project.txt changes the file’s group to developers, provided the user has the necessary permissions. Group ownership is important for collaborative access because group permissions can allow several users to work with the same files. chown can also change ownership and can specify a group, while chgrp focuses specifically on group ownership. groupmod manages group account properties rather than changing the group associated with individual files.

Question: 140. Which command creates a symbolic link to another file or directory?

  1. link -s
    2. shortcut
    3. ln -s
    4. symlink

Correct Answer: 3. ln -s

Explanation:
The ln -s command creates a symbolic link, also called a symlink. A symbolic link contains a reference to another pathname rather than being a second directory entry pointing directly to the same inode in the way a hard link does. For example, ln -s /var/log/app.log current.log creates a symbolic link named current.log that refers to the specified target. Symbolic links can point across filesystems and can refer to directories. If the target is moved or removed, the symbolic link may become dangling. Understanding symbolic links is important when managing flexible filesystem layouts and application paths.