Visit here for our full LPI 010-160 exam dumps and practice test questions.
Question 31
Which command is used to display the current working directory in Linux?
A) cwd
B) pwd
C) cd
D) dir
Answer: B
Explanation:
The pwd command, which stands for print working directory, is used to display the current working directory in Linux. When you execute this command, it shows the full absolute path of the directory you are currently located in within the filesystem hierarchy.
The pwd command is essential for navigation in the Linux command line interface. It helps users keep track of their current location in the directory tree, especially when working with complex directory structures or when multiple terminal sessions are open. The command displays the path starting from the root directory, denoted by a forward slash, and includes all parent directories leading to your current location.
There are two options commonly used with pwd. The pwd -L option displays the logical current working directory, which shows symbolic links as they appear. The pwd -P option displays the physical current working directory, resolving all symbolic links to show the actual directory path. By default, pwd uses the logical path.
The pwd command is particularly useful in shell scripts where you need to determine the script’s execution location or when you need to return to a specific directory after navigating through the filesystem. It is also helpful when you want to verify your location before executing commands that might affect files in the current directory.
The cwd command is not a standard Linux command for displaying the current working directory. While some systems or shells might have this as an alias or custom function, it is not the standard command.
The cd command is used to change directories, not to display the current working directory. When used without arguments, cd takes you to your home directory.
The dir command is primarily a Windows command for listing directory contents. In Linux, the ls command is used for listing directory contents, not pwd.
Question 32
What does the chmod 755 filename command do?
A) Sets read, write, and execute permissions for owner; read and execute for group and others
B) Sets read and write permissions for everyone
C) Sets execute permission only for the owner
D) Removes all permissions from the file
Answer: A
Explanation:
The chmod 755 filename command sets read, write, and execute permissions for the owner, and read and execute permissions for the group and others. This is one of the most commonly used permission settings in Linux, particularly for executable files and directories.
In Linux, file permissions are represented by three sets of three bits each. The first set represents owner permissions, the second set represents group permissions, and the third set represents permissions for others. Each set can have read permission valued at 4, write permission valued at 2, and execute permission valued at 1.
When you use chmod 755, the first digit 7 represents owner permissions. This is calculated as 4 plus 2 plus 1, which means read, write, and execute permissions for the owner. The second digit 5 represents group permissions, calculated as 4 plus 1, meaning read and execute permissions without write permission. The third digit 5 represents permissions for others, also 4 plus 1, providing read and execute permissions.
This permission setting is commonly used for scripts and executable programs that need to be run by anyone but should only be modified by the owner. It is also frequently used for directories, as execute permission on a directory allows users to enter that directory and access its contents.
The permission setting 755 ensures security by preventing unauthorized users from modifying files while still allowing them to read and execute the files. This is ideal for system binaries, shared scripts, and public directories where multiple users need access but modification should be restricted.
Setting read and write permissions for everyone would require a permission value like 666 or 777, not 755, and would be a security risk.
Question 33
Which file contains user account information in Linux?
A) /etc/shadow
B) /etc/passwd
C) /etc/group
D) /etc/users
Answer: B
Explanation:
The /etc/passwd file contains user account information in Linux. This file is a fundamental component of the Linux user management system and stores essential details about every user account on the system.
The /etc/passwd file is a plain text file where each line represents one user account. Each line contains seven fields separated by colons. The fields are username, password placeholder, user ID, group ID, user description or comment, home directory path, and default shell. For example, a typical entry might look like john:x:1001:1001:John Doe:/home/john:/bin/bash.
In modern Linux systems, the actual encrypted passwords are not stored in /etc/passwd for security reasons. Instead, an x character appears in the password field, indicating that the encrypted password is stored in the /etc/shadow file, which has more restrictive permissions. This separation enhances security by allowing /etc/passwd to remain world-readable while keeping actual password hashes protected.
The /etc/passwd file is readable by all users because many programs need to access user information such as usernames, UIDs, home directories, and default shells. However, only the root user can modify this file. Understanding the structure of /etc/passwd is crucial for system administration tasks such as user management, troubleshooting login issues, and automating user account creation.
The /etc/shadow file contains encrypted password information and password aging details but not the complete user account information. This file is only readable by root for security purposes.
The /etc/group file contains information about group memberships, not individual user account details. It defines groups and which users belong to each group.
The /etc/users file does not exist as a standard Linux configuration file. User information is stored in /etc/passwd, not /etc/users.
Question 34
Which command displays the first 10 lines of a file by default?
A) tail
B) head
C) cat
D) more
Answer: B
Explanation:
The head command displays the first 10 lines of a file by default. This command is particularly useful when you want to quickly preview the beginning of a file without opening the entire file, especially when dealing with large log files or data files.
The head command can be customized using various options. The most common option is -n followed by a number, which specifies how many lines to display. For example, head -n 20 filename would display the first 20 lines of the file. You can also use the shorthand syntax head -20 filename to achieve the same result.
Another useful option is -c, which allows you to specify the number of bytes to display instead of lines. This is helpful when working with binary files or when you need precise control over the amount of data displayed. The head command can also process multiple files simultaneously, displaying the first 10 lines of each file with headers showing the filename.
The head command is commonly used in combination with other commands through pipes. For instance, you might use ls -l | head to see the first 10 entries of a directory listing, or use it with grep to find specific patterns in the beginning of files. In system administration, head is frequently used to check log files, configuration files, and data exports.
The tail command is the opposite of head; it displays the last 10 lines of a file by default, not the first 10 lines. The tail command is particularly useful for monitoring log files.
The cat command displays the entire contents of a file, not just the first 10 lines. It concatenates and displays complete files.
The more command is a pager that displays file contents one screen at a time but does not limit output to 10 lines by default.
Question 35
What is the purpose of the sudo command in Linux?
A) To switch user accounts
B) To execute commands with superuser privileges
C) To shut down the system
D) To display system information
Answer: B
Explanation:
The sudo command in Linux is used to execute commands with superuser privileges. The name sudo stands for “superuser do” or “substitute user do,” and it allows authorized users to run commands as the root user or another user as specified in the sudoers configuration file.
The sudo mechanism provides a more secure and auditable alternative to logging in directly as the root user. Instead of sharing the root password with multiple administrators, sudo allows specific users to execute specific commands with elevated privileges while maintaining accountability. Every sudo command execution is logged, creating an audit trail that shows who executed what command and when.
When a user executes a command with sudo, they are prompted to enter their own password, not the root password. The system then checks the /etc/sudoers file to verify whether that user is authorized to execute the requested command. If authorized, the command runs with root privileges. By default, sudo caches the authentication for a short period, usually 15 minutes, so users do not need to enter their password for every sudo command.
The sudo command can be configured with fine-grained control through the /etc/sudoers file, which should only be edited using the visudo command to prevent syntax errors. Administrators can specify which users or groups can execute which commands on which hosts, providing flexible security policies. Common usage includes system administration tasks like installing software with sudo apt install, editing system files with sudo nano /etc/config, or restarting services with sudo systemctl restart.
The su command is used to switch user accounts, not sudo. While sudo can execute commands as other users, its primary purpose is privilege elevation.
Shutting down the system requires the shutdown or poweroff command, though these often need to be run with sudo.
Question 36
Which directory typically contains system log files in Linux?
A) /var/log
B) /etc/log
C) /usr/log
D) /tmp/log
Answer: A
Explanation:
The /var/log directory typically contains system log files in Linux. This directory is the standard location where most system services, applications, and the kernel store their log files, making it the primary location for troubleshooting and monitoring system activities.
The /var directory stands for variable and contains files that are expected to grow or change during normal system operation. Within /var/log, you will find numerous log files and subdirectories containing logs from different services and applications. Common log files include syslog or messages for general system messages, auth.log or secure for authentication attempts, kern.log for kernel messages, and dmesg for boot messages.
Different Linux distributions may organize logs slightly differently, but /var/log remains the standard location. For example, Apache web server logs are typically in /var/log/apache2 or /var/log/httpd, while mail server logs might be in /var/log/mail. System administrators regularly examine these logs to diagnose problems, monitor security events, track system performance, and maintain compliance requirements.
Many modern Linux systems use systemd, which includes the journald logging system. While journald stores logs in a binary format in /var/log/journal, traditional text-based logs are still maintained in /var/log for compatibility and ease of use. Tools like tail, grep, and less are commonly used to read and analyze these log files, and log rotation mechanisms ensure that logs do not consume excessive disk space.
The /etc/log directory does not exist as a standard directory in Linux. The /etc directory contains configuration files, not log files.
The /usr/log directory is not a standard location for log files. The /usr directory contains user programs and data but not system logs.
The /tmp/log directory is not a standard location for system logs. The /tmp directory contains temporary files that are often deleted on reboot.
Question 37
Which command is used to search for files and directories in Linux?
A) locate
B) search
C) find
D) grep
Answer: C
Explanation:
The find command is used to search for files and directories in Linux. It is one of the most powerful and versatile commands for locating files based on various criteria such as name, size, modification time, permissions, and ownership.
The find command searches through the directory hierarchy in real-time, examining each file and directory to match the specified criteria. The basic syntax is find [path] [expression], where path specifies where to search and expression defines what to search for. For example, find /home -name “*.txt” would search for all files ending with .txt in the /home directory and its subdirectories.
The find command offers numerous options and tests for complex searches. You can search by name using -name, by file type using -type, by size using -size, by modification time using -mtime, by permissions using -perm, and by owner using -user. Multiple criteria can be combined using logical operators like -and, -or, and -not to create sophisticated search queries.
One of find’s most powerful features is the ability to execute commands on the files it finds using the -exec option. For example, find /var/log -name “*.log” -mtime +30 -exec rm {} ; would find and delete log files older than 30 days. The find command can also be used with -print to display results, -delete to remove matched files, and various other actions.
The locate command is also used for finding files but works differently by searching a pre-built database rather than searching the filesystem in real-time. While faster, locate may not reflect recent changes.
The search command is not a standard Linux command for finding files.
The grep command searches for text patterns within files, not for files themselves, though it is often used in combination with find.
Question 38
What does the command rm -rf do in Linux?
A) Removes files and asks for confirmation
B) Recursively removes directories and their contents without prompting
C) Renames files and folders
D) Recovers deleted files
Answer: B
Explanation:
The command rm -rf recursively removes directories and their contents without prompting for confirmation. This is one of the most powerful and potentially dangerous commands in Linux, as it can permanently delete large amounts of data without any warning or ability to recover.
The rm command stands for remove and is used to delete files and directories. The -r option, which stands for recursive, tells rm to delete directories and all their contents, including subdirectories and files. The -f option, which stands for force, suppresses all prompts and error messages, allowing the deletion to proceed without user confirmation even for write-protected files.
When you combine these options as rm -rf, the command will delete everything in the specified directory tree without asking questions or displaying warnings. This makes it extremely efficient for removing unwanted directory structures but also extremely dangerous if used carelessly. A simple typo or incorrect path can result in catastrophic data loss, including system files if run with root privileges.
System administrators must exercise extreme caution when using rm -rf, especially when running commands as root or with sudo. Best practices include double-checking the path before executing, using tab completion to ensure accuracy, testing with ls first to verify what will be deleted, and considering safer alternatives like moving files to a trash directory instead of immediate deletion.
The standard rm command without options does ask for confirmation for write-protected files, but the -f flag specifically bypasses this. The -r flag is necessary for directories; without it, rm will refuse to delete directories.
The mv command is used for renaming and moving files, not rm.
Linux does not have a built-in command to recover deleted files, and rm -rf certainly does not recover files.
Question 39
Which command displays information about disk space usage on mounted filesystems?
A) du
B) df
C) fdisk
D) mount
Answer: B
Explanation:
The df command displays information about disk space usage on mounted filesystems. The name df stands for disk free, and it provides a comprehensive overview of how much disk space is available and used on all mounted filesystems.
When you execute df without any options, it displays information for all mounted filesystems including the filesystem name, total size, used space, available space, percentage used, and mount point. This information is typically displayed in 1K blocks by default, which can be difficult to read for large filesystems.
The most commonly used option with df is -h, which stands for human-readable. The df -h command displays sizes in more convenient units like megabytes, gigabytes, and terabytes, making it much easier to understand at a glance. For example, instead of showing 52428800 blocks, it would display 50G for a 50 gigabyte partition.
Other useful df options include -T to display the filesystem type, -i to show inode information instead of block usage, and -t or -x to include or exclude specific filesystem types. The df command is essential for system administrators to monitor disk space, identify filesystems that are running out of space, and plan for storage capacity upgrades.
Understanding df output is crucial for preventing disk-full situations that can cause system crashes, application failures, and data loss. Regular monitoring of df output helps administrators proactively manage storage resources and maintain system stability.
The du command displays disk usage of files and directories, showing how much space individual files and folders consume, but it does not show overall filesystem statistics like df does.
The fdisk command is used for partitioning disks, not for displaying space usage.
The mount command displays or configures mounted filesystems but does not provide detailed space usage statistics.
Question 40
What is the default umask value for most Linux systems?
A) 0022
B) 0777
C) 0644
D) 0755
Answer: A
Explanation:
The default umask value for most Linux systems is 0022. The umask, which stands for user file-creation mode mask, determines the default permissions that are assigned to newly created files and directories by subtracting the umask value from the maximum possible permissions.
The umask works by specifying which permission bits should be removed from the default maximum permissions. For files, the maximum permissions are 666 (read and write for owner, group, and others, with no execute permission by default for security). For directories, the maximum permissions are 777 (read, write, and execute for all).
With a umask of 0022, when you create a new file, the resulting permissions are 644, calculated as 666 minus 022. This gives read and write permission to the owner and read-only permission to group and others. When you create a new directory with umask 0022, the resulting permissions are 755, calculated as 777 minus 022, giving full permissions to the owner and read plus execute to group and others.
The leading zero in 0022 indicates that the umask is specified in octal notation. The subsequent digits represent permissions to be masked for owner, group, and others respectively. A umask of 0022 is considered secure for most purposes because it prevents other users from modifying files while still allowing them to read files and access directories.
You can view your current umask by running the umask command without arguments, and you can change it by running umask followed by the new value. However, this change only affects the current shell session unless you modify configuration files like .bashrc or .profile.
The value 0777 would be an extremely permissive umask that would result in no permissions on created files, which is not practical.
Question 41
Which command is used to change file ownership in Linux?
A) chmod
B) chown
C) chgrp
D) usermod
Answer: B
Explanation:
The chown command is used to change file ownership in Linux. The name chown stands for change owner, and it allows you to modify both the user owner and group owner of files and directories. Only the root user or a user with sudo privileges can change file ownership.
The basic syntax of chown is chown [owner]:[group] filename. You can change just the owner by specifying only the username, change both owner and group by using the colon separator, or change only the group by preceding the group name with a colon. For example, chown john file.txt changes the owner to john, chown john:developers file.txt changes both owner and group, and chown :developers file.txt changes only the group.
The chown command is particularly useful when files need to be transferred between users, when setting up web servers where files must be owned by the web server user, or when fixing permission issues after restoring from backups. The -R option makes chown recursive, allowing you to change ownership of entire directory trees with a single command.
In practice, system administrators frequently use chown to ensure that application files are owned by the appropriate service accounts, that user home directories have correct ownership, and that shared resources have proper group ownership for collaboration. Understanding chown is essential for managing multi-user systems and maintaining proper security boundaries.
The chmod command changes file permissions, not ownership. While both commands are related to file security, they serve different purposes.
The chgrp command changes only the group ownership of files, not the user owner. While it can accomplish part of what chown does, chown is more versatile.
The usermod command modifies user account properties, not file ownership. It operates on user accounts in /etc/passwd, not on files.
Question 42
What does the pipe symbol | do in Linux command line?
A) Redirects output to a file
B) Sends the output of one command as input to another command
C) Runs multiple commands sequentially
D) Creates a logical OR condition
Answer: B
Explanation:
The pipe symbol | sends the output of one command as input to another command. Piping is one of the most powerful features of the Linux command line, allowing users to combine simple commands to perform complex operations by chaining them together.
When you use a pipe, the standard output of the command on the left side becomes the standard input for the command on the right side. This allows data to flow from one program to another without needing temporary files. For example, the command ls -l | grep “txt” would list files in long format and then filter the output to show only lines containing “txt”.
Pipes enable the Unix philosophy of creating small, focused programs that do one thing well and combining them to accomplish complex tasks. You can chain multiple pipes together to create sophisticated data processing pipelines. For instance, cat logfile.txt | grep “error” | sort | uniq would display unique error messages from a log file in sorted order.
Common uses of pipes include filtering output with grep, sorting with sort, paginating with less or more, counting with wc, and transforming data with awk or sed. Pipes are essential for system administration tasks, log analysis, text processing, and data manipulation. Understanding how to effectively use pipes dramatically increases productivity on the command line.
The pipe operates on streams of data in real-time and is more efficient than using temporary files to pass data between commands. It is a fundamental concept that every Linux user should master for effective command-line usage.
Redirecting output to a file uses the > or >> symbols, not the pipe symbol.
Running multiple commands sequentially uses the semicolon ; or && operators, not the pipe.
Question 43
Which command is used to display or set the system hostname?
A) hostname
B) hostnamectl
C) uname
D) Both A and B
Answer: D
Explanation:
Both hostname and hostnamectl commands can be used to display or set the system hostname in Linux. The hostname is the label assigned to a computer on a network and is used to identify the system in various contexts.
The hostname command is the traditional utility for viewing and setting the hostname. When executed without arguments, hostname displays the current hostname of the system. To change the hostname, you can use hostname newhostname, though this change is temporary and will be lost after a reboot unless you also modify the appropriate configuration files.
The hostnamectl command is a more modern tool introduced with systemd and provides more comprehensive hostname management. It displays not only the static hostname but also the transient hostname, pretty hostname, icon name, chassis type, and other system information. To change the hostname permanently using hostnamectl, you use the command hostnamectl set-hostname newhostname, which automatically updates the necessary configuration files.
The hostnamectl command offers several advantages over the traditional hostname command. It provides better integration with systemd, supports different types of hostnames including pretty names for display purposes, automatically updates all relevant configuration files, and provides more detailed system information. However, the hostname command remains widely used due to its simplicity and availability on all Linux systems, including those not using systemd.
System administrators typically need to set hostnames during initial system setup, when repurposing servers, or when organizing systems in large networks. Proper hostname configuration is essential for network identification, logging, authentication, and many networked services.
The uname command displays system information including the kernel name and version but is not primarily used for hostname management, though uname -n can display the hostname.
Question 44
Which file contains DNS server information in Linux?
A) /etc/hosts
B) /etc/resolv.conf
C) /etc/network
D) /etc/dns.conf
Answer: B
Explanation:
The /etc/resolv.conf file contains DNS server information in Linux. This configuration file tells the system which DNS servers to use for resolving domain names to IP addresses, and it is one of the most critical files for network connectivity and internet access.
The /etc/resolv.conf file typically contains nameserver entries that specify the IP addresses of DNS servers to query. Each nameserver line is followed by an IP address, and you can specify multiple nameserver entries for redundancy. The resolver queries these servers in the order they appear until it receives a response. For example, the file might contain nameserver 8.8.8.8 and nameserver 8.8.4.4 to use Google’s public DNS servers.
Additional directives can be included in /etc/resolv.conf such as the search directive, which specifies domain names to append to unqualified hostnames, and the domain directive, which sets the local domain name. The options directive can modify resolver behavior with settings like timeout values and number of retry attempts.
In modern Linux systems using NetworkManager or systemd-resolved, /etc/resolv.conf is often a symbolic link to a dynamically generated file. These systems automatically update DNS configuration based on network connections, DHCP settings, or VPN configurations. Direct manual edits to /etc/resolv.conf may be overwritten by these services, so permanent changes often need to be made through the network management system’s configuration.
Understanding /etc/resolv.conf is essential for troubleshooting DNS resolution issues, configuring static DNS servers, setting up custom DNS solutions, and managing network connectivity in various environments.
The /etc/hosts file maps hostnames to IP addresses locally but does not contain DNS server information.
The /etc/network directory contains network interface configuration but not specifically DNS server settings.
The /etc/dns.conf file does not exist as a standard configuration file in Linux.
Question 45
What is the purpose of the tar command in Linux?
A) To compress files only
B) To create archive files and optionally compress them
C) To transfer files over network
D) To delete old files
Answer: B
Explanation:
The tar command in Linux is used to create archive files and optionally compress them. The name tar stands for tape archive, reflecting its original purpose of writing data to tape drives, but it is now primarily used for creating file archives on disk for backup, distribution, and storage purposes.
The tar command bundles multiple files and directories into a single archive file, preserving file permissions, ownership, timestamps, and directory structure. This makes tar ideal for backing up data, distributing software, and transferring multiple files as a single unit. Unlike some archive formats, tar itself does not perform compression; it simply combines files into one archive.
However, tar is commonly used with compression utilities like gzip, bzip2, or xz. Common options include -c to create an archive, -x to extract an archive, -v for verbose output showing progress, -f to specify the archive filename, -z to compress with gzip, -j to compress with bzip2, and -J to compress with xz. A typical command might be tar -czf archive.tar.gz /path/to/directory to create a gzip-compressed tar archive.
The tar command supports numerous advanced features including incremental backups, selective extraction, file exclusion patterns, and archive verification. System administrators use tar extensively for backup scripts, software deployment, log archiving, and system migration tasks. Understanding tar syntax and options is essential for effective file management and system administration.
Modern alternatives like zip exist, but tar remains the standard on Linux systems due to its flexibility, widespread support, and ability to preserve Unix file attributes that other archive formats may not maintain properly.
While tar can be used with compression, compression is not its only purpose; its primary purpose is archiving files.