View Full LPI 101-500 Exam Dumps and Practice Test Dumps
Question: 361. Which command can display the current value of the HOME environment variable?
- echo $HOME
2. print-home
3. home –show
4. show HOME
Correct Answer: 1. echo $HOME
Explanation:
The HOME environment variable normally contains the pathname of the current user’s home directory. The command echo $HOME expands the variable and displays its value. This is useful in shell scripts and interactive sessions when a command needs to refer to the user’s home directory without hard-coding a specific pathname. The tilde character ~ also commonly represents the current user’s home directory in shell pathname expansion, but $HOME directly accesses the variable. Environment variables can influence the behavior of many commands and applications, making them an important part of the Linux shell environment.
Question: 362. Which environment variable normally contains the current user’s login shell?
- $USER
2. $SHELL
3. $LOGIN
4. $TERM
Correct Answer: 2. $SHELL
Explanation:
The SHELL environment variable commonly contains the pathname of the user’s default login shell, such as /bin/bash or another supported shell. It can be inspected with echo $SHELL. The USER variable identifies the current username, while TERM identifies the terminal type or terminal environment. Although $SHELL commonly represents the user’s configured login shell, it should not always be interpreted as proof of which shell process is currently executing a particular command or script. Linux environments can contain multiple shells and processes, each potentially having different execution contexts.
Question: 363. Which command can print the current value of the shell’s PATH variable?
- showpath
2. path –print
3. echo $PATH
4. printenv-path
Correct Answer: 3. echo $PATH
Explanation:
The PATH environment variable contains a list of directories that the shell searches when resolving executable command names. The command echo $PATH displays the current value of this variable, normally showing directory names separated by colons. When a user types a command without an explicit pathname, the shell can search these directories according to its command-resolution rules. Modifying PATH can change which executable is selected when multiple programs have the same name. Administrators should therefore understand its contents before troubleshooting unexpected command resolution.
Question: 364. Which shell command can display environment variables and their values?
- env
2. vars
3. environment
4. showenv
Correct Answer: 1. env
Explanation:
The env command can display the environment variables available to the current process environment. It can also be used to run a command with a modified environment. Environment variables provide configuration information to programs and can influence behavior such as command lookup, locale, terminal settings, and user-specific directories. set in some shells can display additional shell variables and functions, so its output is not identical to env. Understanding the distinction between shell variables and exported environment variables is important when troubleshooting scripts and determining which values are inherited by child processes.
Question: 365. Which shell variable contains the number of positional arguments supplied to a script?
- $@
2. $0
3. $#
4. $?
Correct Answer: 3. $#
Explanation:
The special shell parameter $# contains the number of positional parameters supplied to a shell script or function. For example, if a script is invoked with three arguments, $# evaluates to 3. This is useful when a script needs to validate how many arguments were provided before performing an operation. $0 normally represents the script’s invocation name, $@ represents the positional arguments, and $? contains the exit status of the most recently completed command. Correctly using these special parameters is fundamental to writing reliable shell scripts.
Question: 366. Which shell expansion preserves each positional parameter as a separate word when quoted?
- “$*”
2. “$@”
3. $#
**4. $$
Correct Answer: 2. “$@”
Explanation:
When used inside double quotes, “$@” expands positional parameters while preserving each parameter as a separate word. This behavior is especially important in shell scripts that need to pass all supplied arguments to another command without incorrectly combining arguments containing spaces. By contrast, “$*” generally expands the positional parameters as a single word, with the first character of IFS used as the separator. The distinction becomes important when writing functions and scripts that forward arbitrary user-supplied arguments. Proper quoting helps prevent unintended word splitting and glob expansion.
Question: 367. Which command can display the exit status of the most recently executed command?
- echo $?
2. echo $!
3. echo $$
4. echo $#
Correct Answer: 1. echo $?
Explanation:
The special shell parameter $? contains the exit status of the most recently executed command or pipeline, subject to shell semantics. The command echo $? can therefore be used immediately afterward to inspect whether the preceding operation succeeded or failed. Conventionally, an exit status of zero indicates success, while a nonzero status generally indicates some form of failure or other condition. $! relates to the most recently started background process, $$ identifies the current shell process, and $# counts positional arguments. Exit statuses are central to conditional shell execution and scripting.
Question: 368. Which shell builtin can display or modify shell options and positional parameters?
- set
2. options
3. shellctl
4. configure
Correct Answer: 4. set
Explanation:
The set shell builtin has several roles, including changing shell options and assigning positional parameters. Options such as set -e and set -u alter shell behavior, while other forms of set can affect positional parameters. In many shells, running set without suitable options can also display shell variables and functions. Because set has multiple purposes, its exact behavior depends on the arguments supplied and the shell implementation. Administrators should consult the shell’s documentation when using advanced options, especially in scripts where option changes can affect subsequent commands.
Question: 369. Which command can remove an alias definition from the current shell?
- removealias
2. unalias
3. delalias
4. alias -d
Correct Answer: 2. unalias
Explanation:
The unalias shell builtin removes an alias from the current shell. Aliases provide short names or substitutions for commands, but they can sometimes cause confusion when a command behaves differently from its expected executable form. Using unalias allows an administrator or user to remove a particular alias or, with supported syntax, multiple aliases. Alias definitions normally affect the current shell environment and do not automatically modify the underlying executable files. The alias builtin is used to create or inspect aliases, while unalias is specifically intended for removing them.
Question: 370. Which command can show the shell’s command history with command numbers?
- history
2. commands
3. log
4. recall
Correct Answer: 1. history
Explanation:
The history shell builtin displays previously entered commands maintained by the shell’s history mechanism. Entries are commonly shown with numbers, allowing users to refer to earlier commands using history expansion or other shell-specific mechanisms. History is useful for repeating commands, reviewing recent administrative actions, and reducing the need to retype long commands. The exact amount of stored history depends on shell configuration and variables such as HISTSIZE. History should not be confused with system logs, which record events independently of the interactive shell’s command history.
Question: 371. Which command can temporarily change the shell’s working directory to the directory stored in the OLDPWD variable?
- cd –
2. cd –old
3. cd previous
4. back
Correct Answer: 1. cd –
Explanation:
The cd – command changes the current working directory to the previous working directory, commonly represented by the OLDPWD shell variable. It is useful when a user needs to switch between two directories repeatedly. After changing directories, the shell generally updates variables such as PWD and OLDPWD to reflect the current and previous locations. This is different from cd .., which moves to the parent directory, and cd ~, which moves to the current user’s home directory. Understanding these shortcuts can make interactive shell navigation more efficient.
Question: 372. Which pathname refers to the current user’s home directory through shell tilde expansion?
- .
2. ~
3. ..
4. /home
Correct Answer: 2. ~
Explanation:
The tilde character ~ is expanded by many Unix-like shells to the current user’s home directory when used in an appropriate unquoted pathname context. For example, cd ~ normally changes to the user’s home directory. The notation ~user can also refer to another user’s home directory when the shell can resolve that account. The single dot . represents the current directory, while .. represents its parent. /home is the conventional location containing user home directories on many systems but is not itself necessarily the current user’s home directory.
Question: 373. Which command can display the current user’s identity and associated groups in a compact account-information format?
- id
2. account
3. userinfo
4. who
Correct Answer: 1. id
Explanation:
The id command displays identity information associated with a user account, commonly including the numeric user ID, primary group ID, username, and supplementary group memberships. This makes it useful when troubleshooting permission problems or determining which groups a process or user belongs to. The who command instead focuses on users currently logged into the system. The groups command can provide group membership information but does not normally present the same complete identity information as id. Understanding user and group IDs is fundamental to Linux ownership and permission management.
Question: 374. Which permission mode allows the owner to read and write a file while allowing others only to read it?
- 755
2. 644
3. 600
4. 666
Correct Answer: 2. 644
Explanation:
The numeric permission mode 644 gives the owner read and write permissions, represented by 6, while the group and other users receive read-only permissions, represented by 4 and 4. In symbolic form, this is commonly represented as rw-r–r–. The first digit applies to the owner, the second to the group, and the third to others. 755 additionally grants execute permission to all three categories, while 600 restricts access to the owner. Numeric permission notation is a concise way to manage Linux filesystem access.
Question: 375. Which permission mode is commonly appropriate for a private file that should be readable and writable only by its owner?
- 644
2. 755
3. 600
4. 666
Correct Answer: 3. 600
Explanation:
The permission mode 600 gives the owner read and write permissions while granting no permissions to the group or other users. In symbolic notation, it is rw——-. This mode is commonly used for private files that should not be accessible by other accounts on the system. The first numeric digit represents owner permissions, while the second and third represent group and other permissions. A mode such as 644 would allow group and other users to read the file, while 755 would additionally provide execute permissions. Correct permission selection is important for protecting sensitive data.
Question: 376. Which command changes a file’s permission bits using symbolic notation?
- chmod
2. chperm
3. permset
4. access
Correct Answer: 1. chmod
Explanation:
The chmod command changes the permission bits of files and directories. It supports both numeric modes and symbolic notation. For example, chmod u+x script.sh adds execute permission for the owner, while chmod go-w file removes write permission for the group and others. Symbolic notation can be useful when only a specific permission change is needed without redefining every permission bit. chown changes ownership rather than permissions, while chgrp changes group ownership. Understanding chmod is essential for controlling read, write, and execute access on Linux filesystem objects.
Question: 377. Which command changes the owner of a file while also allowing a group to be specified?
- chmod
2. chgrp
3. chown
4. own
Correct Answer: 3. chown
Explanation:
The chown command changes the ownership of files and directories and can also specify a group depending on its syntax. For example, an administrator can use a form such as chown alice:developers project.txt to set the owner to alice and the group to developers. This makes chown broader than chgrp, which specifically changes group ownership. Changing ownership usually requires appropriate administrative privileges. Because ownership directly affects access-control decisions, administrators should verify the intended pathname and ownership values before applying recursive ownership changes.
Question: 378. Which command displays the names of groups to which the current user belongs?
- members
2. groups
3. group-list
4. showgroups
Correct Answer: 2. groups
Explanation:
The groups command displays the group memberships associated with the current user or, when supplied with a username, another specified account. Group membership is important because Linux permission checks can use the user’s group memberships when determining access to files and other resources. The id command provides more detailed identity information, including numeric user and group IDs. groups is therefore a convenient command when the primary question is simply which groups an account belongs to. Group configuration can vary between local accounts and directory-based authentication systems.
Question: 379. Which command can display the contents of a text file with line numbers added to each line?
- cat -n
2. cat -l
3. number
4. lines
Correct Answer: 1. cat -n
Explanation:
The -n option of cat numbers the output lines when displaying a file. For example, cat -n script.sh can make it easier to refer to specific lines while troubleshooting a script or reviewing configuration content. The option changes the displayed output but does not modify the underlying file. Other tools can also number lines, such as nl, which is specifically designed for numbered output. cat -n is convenient when a user is already using cat and wants a simple numbered representation of the file’s contents.
Question: 380. Which command can display the first line of a file followed by the remaining lines unchanged when used with the appropriate options?
- head
2. sed
3. tail
4. cut
Correct Answer: 2. sed
Explanation:
The sed stream editor can process input line by line and selectively perform operations on particular lines while passing other content through unchanged. This makes it suitable for tasks where only a specific line or range needs to be modified or displayed differently. For example, a sed address can target line 1 while the remainder of the input continues through the processing stream. head and tail are primarily used to select the beginning or end of input, while cut extracts selected fields or character positions. sed provides considerably more flexible line-oriented transformations.