LPI 101-500 Practice Test Questions and Exam Dumps Part 14 Q261-280

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

 

Question: 261. Which command can display the current user’s login name in a simple form?

  1. uname
    2. whoami
    3. hostname
    4. id

Correct Answer: 2. whoami

Explanation:

The whoami command displays the effective username associated with the current shell process. It is useful when an administrator or user needs to quickly confirm which account is currently being used. This can be especially helpful when switching between users or working with commands that require elevated privileges. The id command provides more detailed identity information, including user and group IDs. uname reports system information, while hostname identifies the system’s hostname. Therefore, when the specific goal is to display the current effective username in a straightforward form, whoami is the appropriate command.

Question: 262. Which command displays information about the operating system kernel and machine architecture?

  1. uname
    2. passwd
    3. groups
    4. alias

Correct Answer: 1. uname

Explanation:

The uname command displays system information associated with the operating system and kernel. Depending on the options used, it can report information such as the kernel name, kernel release, machine hardware architecture, hostname, and operating-system information. For example, uname -a requests a broad set of available system details. groups displays group memberships, passwd is used to change account passwords, and alias manages shell aliases. uname is therefore a useful diagnostic command when an administrator needs to identify the environment in which Linux is running.

Question: 263. Which command can show the groups to which the current user belongs?

  1. groups
    2. sleep
    3. diff
    4. mount

Correct Answer: 1. groups

Explanation:

The groups command displays the group memberships associated with a specified user or, when no username is supplied, the current user. Linux uses groups to organize permissions and allow multiple users to share access to files and resources. A user can have a primary group and may also belong to additional supplementary groups. The id command can provide similar group information along with numeric user and group IDs. mount manages filesystem attachments, diff compares files, and sleep pauses execution. Therefore, groups is the straightforward command for viewing group membership.

Question: 264. Which command can display both the numeric user ID and group IDs associated with a user?

  1. alias
    2. id
    3. jobs
    4. pwd

Correct Answer: 2. id

Explanation:

The id command displays identity information for a user, including the numeric user ID, primary group ID, and supplementary group memberships. When used without a username, it normally reports information about the current user. This is useful when troubleshooting permissions because Linux permissions are ultimately associated with numeric user and group identities. Although groups can display group names, id provides a broader identity summary. pwd displays the current working directory, jobs manages shell jobs, and alias handles command aliases. Understanding id is therefore important when investigating account and permission behavior.

Question: 265. Which command can display the permissions, ownership, size, and timestamps of a file in a detailed listing?

  1. ls -l
    2. cd
    3. rm
    4. echo

Correct Answer: 1. ls -l

Explanation:

The ls -l command produces a long-format directory listing containing information such as file permissions, link count, owner, group, file size, modification time, and filename. This makes it one of the most commonly used commands for examining filesystem metadata from the shell. The first field contains the file type and permission information, while later fields identify ownership and other attributes. cd changes directories, rm removes files, and echo writes text to standard output. Therefore, ls -l is the appropriate command when detailed file information is required.

Question: 266. Which command can compare two text files and report their differences line by line?

  1. cmp
    2. diff
    3. sort
    4. wc

Correct Answer: 2. diff

Explanation:

The diff command compares two files and reports differences between them, commonly in a line-oriented format. It is widely used when comparing configuration files, source code, or versions of text documents. The output can indicate which lines need to be added, removed, or changed to transform one file into another. cmp also compares files but works at a lower byte-oriented level and is useful for determining whether files differ without providing the same line-oriented analysis. sort orders lines, while wc counts lines, words, and bytes. Thus, diff is the standard choice for line-by-line text comparison.

Question: 267. Which command compares two files byte by byte and reports the first difference it encounters?

  1. grep
    2. awk
    3. cmp
    4. cut

Correct Answer: 3. cmp

Explanation:

The cmp command compares two files byte by byte and can report the location of the first difference. It is useful when the exact byte-level equality of two files needs to be checked. Unlike diff, which is designed to provide a line-oriented description of changes between text files, cmp focuses on direct file comparison. It can therefore be useful for binary files as well as text files. grep searches text for patterns, awk processes structured text, and cut extracts fields or character ranges. Understanding the distinction between cmp and diff helps select the correct comparison tool.

Question: 268. Which command is commonly used to display the first several lines of a text file?

  1. head
    2. tail
    3. less
    4. more

Correct Answer: 1. head

Explanation:

The head command displays the beginning portion of a file or input stream. By default, implementations commonly display the first several lines, while options can be used to request a specific number of lines or bytes. This is useful when quickly inspecting the structure or header of a large file without reading the entire contents. tail focuses on the end of a file, while less provides an interactive pager for viewing larger amounts of text. The more utility can also page through text, but head is specifically designed for extracting the beginning of input.

Question: 269. Which command is most appropriate for interactively viewing a long text file one screen at a time?

  1. touch
    2. less
    3. mkdir
    4. ln

Correct Answer: 2. less

Explanation:

The less command is a terminal pager designed for interactively viewing text that may be longer than the available screen. Users can move forward and backward through the content, search for text, and navigate without loading the entire file into a simple command-line output stream. This makes less particularly useful for logs, manuals, configuration files, and large text documents. touch changes timestamps or creates files, mkdir creates directories, and ln creates links. Therefore, less is the appropriate choice when interactive navigation through lengthy text is required.

Question: 270. Which command removes an empty directory?

  1. rmdir
    2. rm
    3. unlink
    4. erase

Correct Answer: 1. rmdir

Explanation:

The rmdir command removes directories that are empty. Its requirement that the directory contain no entries provides an additional safeguard against accidentally deleting files contained inside the directory. If a directory contains files or subdirectories, rmdir normally reports an error rather than recursively removing its contents. The rm command can remove files and, with appropriate options, directories and their contents. unlink is generally associated with removing a directory entry for a file, while erase is not the standard Linux command for this purpose. Thus, rmdir is specifically suited to removing empty directories.

Question: 271. Which command creates a new directory named reports?

  1. touch reports
    2. mkdir reports
    3. cd reports
    4. cat reports

Correct Answer: 2. mkdir reports

Explanation:

The mkdir command creates directories. Therefore, mkdir reports requests creation of a directory named reports in the current working directory. The command can also accept options for creating parent directories when necessary and for setting permissions at creation time. touch reports creates a regular file if the specified path does not already exist, while cd reports attempts to change into an existing directory. cat reports attempts to display file contents. Understanding the distinction between creating a directory and creating or accessing a file is a fundamental Linux command-line skill.

Question: 272. Which command changes the current working directory to /var/log?

  1. pwd /var/log
    2. ls /var/log
    3. cd /var/log
    4. cat /var/log

Correct Answer: 3. cd /var/log

Explanation:

The cd command changes the shell’s current working directory. Therefore, cd /var/log moves the current shell session into the /var/log directory, assuming the path exists and the user has appropriate permissions to access it. pwd displays the current directory rather than changing it. ls lists directory contents, while cat displays file contents and is not normally used for directory navigation. Because the current working directory affects how relative paths are interpreted, understanding cd is essential for effective command-line navigation and shell scripting.

Question: 273. Which symbol represents the parent directory in a relative pathname?

  1. .
    2. ~
    3. ..
    4. /

Correct Answer: 3. ..

Explanation:

The special pathname component .. represents the parent directory of the current directory. For example, cd .. moves the shell one directory level upward in the filesystem hierarchy. A single dot (.) represents the current directory, while / represents the root directory when used as the beginning of an absolute pathname. The tilde (~) is commonly expanded by the shell to represent the current user’s home directory. These pathname shortcuts are fundamental to navigating Linux filesystems and are frequently used in relative paths and shell commands.

Question: 274. Which shell expansion commonly represents the current user’s home directory?

  1. ~
    2. ..
    3. /
    4. .

Correct Answer: 1. ~

Explanation:

The tilde (~) is commonly expanded by the shell to represent the current user’s home directory. For example, cd ~ normally changes to the user’s home directory, while ~/documents refers to a documents path beneath that home directory. The exact expansion is performed by the shell before the command is executed. A single dot represents the current directory, two dots represent the parent directory, and / represents the root of the filesystem hierarchy. Tilde expansion is therefore a convenient way to refer to user-specific paths without typing the complete home-directory pathname.

Question: 275. Which command can display the absolute pathname of the current working directory?

  1. cd
    2. pwd
    3. ls
    4. echo

Correct Answer: 2. pwd

Explanation:

The pwd command displays the pathname of the shell’s current working directory. This is useful when navigating through directories because it provides an exact location rather than requiring the user to infer the path from the prompt. By default, pwd commonly presents an absolute pathname. cd changes the current directory, ls lists directory contents, and echo displays supplied text or variable values. Knowing the current working directory is especially important when using relative paths, because relative pathnames are interpreted from that location.

Question: 276. Which command can rename a file from old.txt to new.txt?

  1. cp old.txt new.txt
    2. mv old.txt new.txt
    3. ln old.txt new.txt
    4. cat old.txt > new.txt

Correct Answer: 2. mv old.txt new.txt

Explanation:

The mv command is used to move files or directories and can also rename them when the source and destination are within the same filesystem context. Therefore, mv old.txt new.txt changes the directory entry name from old.txt to new.txt. cp creates a copy while leaving the original in place, and ln creates a link rather than performing a normal rename. Redirecting cat output can create another file containing copied data but is not an appropriate general-purpose rename operation. mv is therefore the standard command for renaming files and directories.

Question: 277. Which redirection operator appends standard output to an existing file instead of overwriting it?

  1. >
    2. <
    3. >>
    4. 2>

Correct Answer: 3. >>

Explanation:

The >> redirection operator appends standard output to a file. If the specified file already contains data, the new output is added to the end rather than replacing the existing contents. If the file does not exist, the shell normally creates it. In contrast, > redirects standard output while normally overwriting an existing file, < redirects standard input from a file, and 2> redirects standard error. Understanding these operators is essential when working with logs, command output, and shell scripts because choosing the wrong redirection can unintentionally destroy existing data.

Question: 278. Which file descriptor represents standard error in a Linux shell?

  1. 0
    2. 1
    3. 2
    4. 3

Correct Answer: 3. 2

Explanation:

File descriptor 2 represents standard error, commonly abbreviated as stderr. It is used by commands to report diagnostic or error messages separately from normal standard output. File descriptor 0 represents standard input, while 1 represents standard output. This separation allows shell users to redirect normal results and error messages independently. For example, 2>errors.txt redirects standard error to a file. Understanding the three standard file descriptors is fundamental to Linux command-line redirection and is especially important when writing scripts that need to handle normal output and errors separately.

Question: 279. Which operator connects the standard output of one command to the standard input of another command?

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

Correct Answer: 2. |

Explanation:

The pipe operator (|) connects commands by sending the standard output produced by the command on its left to the standard input of the command on its right. This allows multiple simple utilities to be combined into powerful processing pipelines. For example, the output of one command can be filtered, sorted, counted, or transformed by another command. The >> operator appends output to a file, && conditionally runs a following command when the previous command succeeds, and ; separates sequential commands. Pipes are one of the most important mechanisms for combining Linux command-line tools.

Question: 280. Which command changes the owner of a file?

  1. chgrp
    2. chmod
    3. chown
    4. umask

Correct Answer: 3. chown

Explanation:

The chown command changes the ownership associated with a file or directory. Depending on the syntax and privileges available, it can change the user owner, the group owner, or both. For example, an administrator can use chown user:group file to assign a particular user and group ownership. chgrp specifically changes the group ownership, while chmod modifies permission bits. umask controls the default permission mask applied when new filesystem objects are created. Understanding the distinction between ownership and permissions is important because both affect access to files and directories but are managed through different commands.