LPI 101-500 Practice Test Questions and Exam Dumps Part 2 Q21-40

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

 

Question: 21. Which command is used to display the first lines of a text file by default?

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

Correct Answer: 4. head

Explanation:

The head command displays the beginning of a file or standard input. By default, it normally displays the first 10 lines. The number of lines can be changed with an option such as head -n 20 file.txt, which displays the first 20 lines. This makes head useful when quickly inspecting the beginning of logs, configuration files, scripts, or other text documents. The tail command works primarily with the end of a file, while less and more are interactive pagers for viewing larger amounts of text. Therefore, head is the appropriate command when the requirement is to display the beginning of a file.

Question: 22. Which command is normally used to display the last lines of a text file?

  1. lastline
    2. head
    3. tail
    4. begin

Correct Answer: 3. tail

Explanation:

The tail command displays the end of a file or stream. Like head, it normally displays 10 lines by default, but the number can be controlled with options. A particularly important feature is tail -f, which continuously follows a file as new data is appended. This is frequently useful when monitoring log files while a service or application is running. The head command displays the beginning rather than the end of a file. begin and lastline are not standard commands for this purpose. Understanding tail, especially its follow functionality, is useful for basic Linux troubleshooting and log monitoring.

Question: 23. Which command is commonly used to determine the type of a file?

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

Correct Answer: 1. file

Explanation:

The file command examines a file and attempts to determine its type by inspecting its contents and, where relevant, filesystem information. This is useful because a Linux filename extension does not necessarily determine what the file actually contains. For example, file document might identify a file as an ASCII text document, executable program, image, archive, or another recognized format. The ls command primarily lists directory information, while typeof and identify are not the standard general-purpose Linux commands for this task. The file command is therefore an important utility for identifying unknown files and understanding their actual format.

Question: 24. Which command is used to create an empty file or update a file’s modification timestamp?

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

Correct Answer: 2. touch

Explanation:

The touch command can create a new empty file if the specified file does not exist. If the file already exists, it normally updates its access and modification timestamps rather than replacing its contents. For example, touch notes.txt creates notes.txt if necessary. The command is often used in shell scripts, testing, and filesystem operations where a file with a particular timestamp or existence state is needed. It does not serve as a general text editor and does not automatically insert content into a file. The other choices are not standard Linux commands for this common filesystem operation.

Question: 25. Which command can be used to count lines, words, and bytes in a file?

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

Correct Answer: 3. wc

Explanation:

The wc command provides counts of lines, words, and bytes or characters, depending on the options used. Running wc file.txt commonly reports several counts together, while options such as wc -l count lines, wc -w count words, and wc -c count bytes. It can also receive input through a pipeline, making it useful for quickly counting command output. The commands count, stats, and measure are not standard replacements for wc. Because Linux utilities are frequently combined using pipes, wc is especially useful for processing the results generated by other commands.

Question: 26. Which redirection operator sends standard output to a file and overwrites the file if it already exists?

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

Correct Answer: 4. >

Explanation:

The > shell redirection operator sends standard output to a specified file. If the file already exists, its previous contents are normally overwritten. For example, echo “Linux” > note.txt creates note.txt or replaces its existing contents with the new output. In contrast, >> appends standard output to the end of a file rather than overwriting it. The < operator redirects standard input from a file, while 2> redirects standard error. Understanding these distinctions is essential for shell scripting and command-line work because incorrect redirection can unintentionally destroy existing data.

Question: 27. Which shell operator appends standard output to an existing file?

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

Correct Answer: 1. >>

Explanation:

The >> operator redirects standard output to a file while appending the new output to the existing contents. If the target file does not exist, the shell normally creates it. For example, echo “New entry” >> log.txt adds the text to the end of log.txt without replacing existing data. This differs from >, which normally truncates the file before writing new output. The | character is used for pipelines, while << introduces a here-document rather than ordinary append redirection. Understanding the difference between > and >> is particularly important when working with logs and shell scripts.

Question: 28. What does the pipe character | do in a Linux shell?

  1. Deletes the output of the first command
    2. Sends the standard output of one command to another command’s standard input
    3. Runs two commands as root
    4. Redirects standard output to a file

Correct Answer: 2. Sends the standard output of one command to another command’s standard input

Explanation:

The pipe operator | connects commands so that the standard output produced by one command becomes the standard input of the next command. For example, ls -l | grep “.txt” sends the directory listing into grep, which then filters the lines containing .txt. Pipes allow small Unix utilities to be combined into more useful processing chains without requiring intermediate files. The pipe does not automatically create a file and does not grant administrative privileges. Understanding pipelines is one of the most important shell concepts because many Linux commands are designed to work together through standard input and standard output.

Question: 29. Which file descriptor represents standard error in a typical Linux process?

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

Correct Answer: 3. 2

Explanation:

Linux processes conventionally use file descriptor 0 for standard input, file descriptor 1 for standard output, and file descriptor 2 for standard error. Standard error is intended for diagnostic and error messages and is separate from normal command output. This distinction allows users to redirect successful output and error messages independently. For example, command 2> errors.txt redirects standard error to errors.txt, while command > output.txt redirects standard output. Knowing these three standard descriptors is essential for understanding shell redirection, pipelines, and basic scripting. Therefore, file descriptor 2 represents standard error.

Question: 30. Which command is commonly used to display the current date and time?

  1. calendar
    2. time-now
    3. clockshow
    4. date

Correct Answer: 4. date

Explanation:

The date command displays the current system date and time and can also format or manipulate date representations depending on its options. Running date without arguments typically produces a human-readable representation of the current date and time. Custom formatting can be requested using format specifiers, making the command useful in shell scripts. It should be distinguished from the time utility, which is commonly used to measure how long a command takes to execute. The other choices are not standard Linux commands for displaying the current system date and time. Therefore, date is the appropriate command for this task.

Question: 31. Which command is used to create a symbolic link?

  1. mklink
    2. ln -s
    3. symlink
    4. link –symbolic

Correct Answer: 2. ln -s

Explanation:

The ln command creates links, and the -s option specifies a symbolic link. For example, ln -s /var/log/application.log app.log creates a symbolic link named app.log pointing to the specified target. Symbolic links store a reference to another pathname rather than directly referring to the same filesystem data in the way a hard link does. They can point to directories and can cross filesystem boundaries, although they can become broken if their target is removed or moved. symlink and mklink are not the standard Linux command forms used for creating symbolic links.

Question: 32. Which command displays the amount of free and used disk space on mounted filesystems?

  1. free
    2. diskfree
    3. du
    4. df

Correct Answer: 4. df

Explanation:

The df command reports filesystem disk-space usage, including the amount of space used, available, and allocated on mounted filesystems. Running df -h is especially common because the -h option presents sizes in human-readable units such as KiB, MiB, or GiB. The du command serves a different purpose: it estimates the disk space used by files and directories. The free command reports memory and swap usage rather than filesystem storage. Therefore, df is the appropriate command when an administrator wants an overview of available and used filesystem space.

Question: 33. Which command is primarily used to estimate the disk space consumed by files and directories?

  1. du
    2. diskuse
    3. df
    4. space

Correct Answer: 1. du

Explanation:

The du command reports disk usage associated with files and directories. It is particularly useful for finding which directories are consuming significant amounts of storage. For example, du -sh /home/user provides a summarized, human-readable estimate of the space used by that directory. This differs from df, which reports free and used space at the filesystem level. The distinction is important when troubleshooting a full disk: df can identify the affected filesystem, while du can help locate directories consuming space within it. The commands space and diskuse are not standard Linux replacements for du.

Question: 34. Which directory usually contains user home directories?

  1. /users
    2. /var
    3. /home
    4. /usr

Correct Answer: 3. /home

Explanation:

The /home directory normally contains the home directories of ordinary users on a Linux system. For example, a user account named alex will commonly have a home directory such as /home/alex. Users typically store personal files, shell configuration files, documents, and other account-specific data there. The root user’s home directory is normally /root, which is separate from /home. The /usr hierarchy contains many installed programs and shared read-only data, while /var contains variable data such as logs and caches. /users is not the standard location defined by the conventional Linux filesystem hierarchy for ordinary user home directories.

Question: 35. Which directory commonly contains variable data such as system logs?

  1. /srv
    2. /var
    3. /etc
    4. /opt

Correct Answer: 2. /var

Explanation:

The /var directory is intended for variable data, meaning data whose contents or size can change during normal system operation. Common examples include logs, spool files, caches, and certain application data. System logs are frequently stored under /var/log. In contrast, /etc is primarily used for configuration files, /opt is traditionally associated with optional application software, and /srv can contain data served by system services. Exact directory contents vary across Linux distributions, but the general purpose of /var remains consistent. Recognizing these filesystem hierarchy conventions is important for navigating Linux systems and locating operational data.

Question: 36. Which command can display information about currently logged-in users?

  1. activeusers
    2. who
    3. users
    4. loginlist

Correct Answer: 2. who

Explanation:

The who command displays information about users currently logged into the system. Its output commonly includes usernames, terminal or pseudo-terminal information, login times, and sometimes the remote source of a login. The related w command provides additional information about what logged-in users are doing and system activity. The users command can also provide a concise list of currently logged-in usernames, but who supplies more session details. loginlist and activeusers are not standard commands. For LPI objectives, understanding basic user and session commands such as who, w, and users is useful for system monitoring.

Question: 37. Which command is commonly used to show the username, UID, GID, and group memberships of a user?

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

Correct Answer: 2. id

Explanation:

The id command displays identity information associated with a user. When run without arguments, it commonly reports the effective username, user ID (UID), primary group ID (GID), and supplementary group memberships. For example, this information can help determine which groups a user belongs to and therefore which resources they may be permitted to access. whoami generally reports only the effective username, while identity and userinfo are not standard commands for this purpose. Because Linux permissions and access controls are closely tied to UIDs and GIDs, id is a valuable command for understanding and troubleshooting user-account permissions.

Question: 38. Which command is commonly used to change the owner of a file?

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

Correct Answer: 2. chown

Explanation:

The chown command changes the ownership of files and directories. It can change the user owner and, with appropriate syntax, the associated group as well. For example, an administrator might use chown alice report.txt to change the owner of a file to user alice. The chgrp command specifically changes the group ownership, while chmod changes permission bits rather than ownership. Ownership changes generally require sufficient privileges, particularly when assigning files to another user. Understanding the relationship between chown, chgrp, and chmod is important because Linux access control depends on both ownership information and permission settings.

Question: 39. Which command changes the group ownership of a file?

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

Correct Answer: 3. 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, assuming the user has the necessary permissions. Group ownership is significant because the group permission bits in a file’s mode determine what members of that group can do with the file. chmod modifies permission bits, while groupmod is used to modify group-account properties rather than directly changing a file’s group ownership. setgroup is not the standard command for this operation. Thus, chgrp is the correct command for changing filesystem group ownership.

Question: 40. Which command is commonly used to terminate a process by sending it a signal?

  1. endproc
    2. kill
    3. stop
    4. terminate

Correct Answer: 2. kill

Explanation:

The kill command sends a signal to a process identified by its process ID (PID). Despite its name, kill is not limited to forcibly terminating processes; it can send different signals for different purposes. For example, kill PID normally sends the default SIGTERM, allowing the process an opportunity to terminate cleanly. A stronger signal such as SIGKILL can be requested with kill -9 PID, although it should be used carefully because the target process cannot catch or handle SIGKILL. Commands such as stop, terminate, and endproc are not the standard general-purpose Linux command for sending process signals.