Linux Foundation LFCS Exam Dumps & Practice Test Questions
Question 1:
In Linux systems, the /etc/passwd file stores user account data, with each record on a new line. The format is colon-separated, including fields such as username, UID, GID, home path, and shell.
Which command below properly extracts just the usernames and their corresponding login shells?
A. column -s : 1,7 /etc/passwd
B. chop -c 1,7 /etc/passwd
C. colrm 1,7 /etc/passwd
D. cut -d: -f1,7 /etc/passwd
Correct answer: D
Explanation:
In a typical Linux system, the /etc/passwd file stores user account information. Each line in this file represents one user and is colon-separated into several fields. The fields of interest in this question are:
Field 1: Username
Field 7: Login shell
The command needed should extract only these two fields. The most suitable and widely used Linux utility for this task is cut, which allows you to split text using a delimiter and select specific fields.
Let’s evaluate each option:
Option A: column -s : 1,7 /etc/passwd – This command is invalid syntax. The column command is used for formatting input into a table, not for extracting specific fields. Moreover, the options passed here are not valid for what is intended—the command doesn’t allow 1,7 as a field selection method in this context.
Option B: chop -c 1,7 /etc/passwd – The chop command does not exist by default in Linux distributions. This is not a valid command for extracting or processing fields from a file like /etc/passwd.
Option C: colrm 1,7 /etc/passwd – The colrm command removes columns from a file, and it expects column positions, not fields or delimited content. It is not capable of parsing colon-separated fields, so it cannot be used to extract specific values like the username and shell based on their field number.
Option D: cut -d: -f1,7 /etc/passwd – This is the correct command. Here's what it does:
cut: Linux utility to extract sections from each line of input.
-d:: Sets the delimiter to a colon (:), which is how fields are separated in /etc/passwd.
-f1,7: Specifies to extract the first and seventh fields, which are the username and the login shell, respectively.
An example output from this command might look like:
root:/bin/bash
user1:/bin/zsh
nobody:/usr/sbin/nologin
This command is frequently used in scripting and system administration tasks where parsing /etc/passwd or similar files is necessary.
In conclusion, to extract just the usernames and their corresponding login shells, the correct and most efficient approach is to use the cut command with the -d: and -f1,7 options.
Therefore, the correct answer is D: cut -d: -f1,7 /etc/passwd.
Question 2:
A script named script.sh contains the following lines:
#!/bin/bash
echo $2 $1
Assuming the file has execution permissions and is run using:
./script.sh test1 test2
What output will be printed to the terminal?
A. test1 test2
B. test2 test1
C. script.sh test2
D. script.sh test1
E. test1 script.sh
Correct answer: B
Explanation:
This question tests your understanding of positional parameters in Bash scripting.
In a Bash script, $1, $2, $3, etc., represent the first, second, third, etc., positional parameters passed to the script when it is executed. The name of the script itself is held in the special variable $0.
Given the script:
#!/bin/bash
echo $2 $1
And it is executed with the command:
./script.sh test1 test2
The following is passed:
$0 = ./script.sh
$1 = test1
$2 = test2
Now, the script runs the echo command:
echo $2 $1
This means it will print:
test2 test1
Let’s quickly break down the incorrect answers for clarity:
A. test1 test2 – This is what you'd see if the script echoed $1 $2, but it does the reverse.
C. script.sh test2 – $0 is not used here, so this is incorrect.
D. script.sh test1 – Again, $0 is not part of the output.
E. test1 script.sh – Same issue, $0 is not being echoed.
The script is echoing the second argument first, then the first.
Thus, the correct and accurate output is test2 test1.
Correct answer: B.
Question 3:
Within the CUPS (Common UNIX Printing System) framework, which configuration file holds the settings and definitions for all printers installed on a Linux system?
A. cups-devices.conf
B. snmp.conf
C. printcap.conf
D. printers.conf
E. cupsd.conf
Correct answer: D
Explanation:
The Common UNIX Printing System (CUPS) is the standard printing system used on most Linux and UNIX-like systems. It provides a modular printing system that allows computers to act as print servers and manage print jobs using the Internet Printing Protocol (IPP). CUPS uses several configuration files to manage its services, settings, and attached printers. Understanding the roles of these files is key to configuring or troubleshooting printing on Linux.
Let’s examine the purpose of each option to identify the correct one:
A. cups-devices.conf – This file is sometimes used internally to list device backends but does not store printer configuration. It may be auto-generated by the system to list available devices but isn't the main file for printer definitions.
B. snmp.conf – This file is used by CUPS to configure how it interacts with network printers over SNMP (Simple Network Management Protocol). It can help discover printers or get status updates, but it does not contain printer configuration data.
C. printcap.conf – This is used in older printing systems like LPD (Line Printer Daemon). While some systems might generate a symbolic link or compatibility file called printcap for legacy reasons, it’s not the core configuration file in a modern CUPS setup.
D. printers.conf – This is the correct answer. The printers.conf file (typically found in /etc/cups/) stores configuration details for each printer installed on the system. It contains information such as:
Printer name
Location
Device URI
Default options
State (enabled/disabled, idle/printing)
This file is read and written by the CUPS daemon (cupsd) and is the primary record of the printers configured on the system.
E. cupsd.conf – This is a very important configuration file, but it is used to define server-wide settings, such as:
Access control
Listening ports
Logging configuration
Default policies
It does not contain individual printer definitions, although it influences how CUPS operates overall.
When managing printers in CUPS, the file that contains the definitions and settings for all installed printers is **printers.conf**. It is directly tied to the configuration and operation of each individual printer on the system. Changes made via the web interface or tools like lpadmin are reflected here.
Therefore, the correct answer is D: printers.conf.
Question 4:
In Unix or Linux environments, which command correctly assigns ownership of a file named file.txt to the user dan and the group staff?
A. chown dan/staff file.txt
B. chown dan:staff file.txt
C. chown -u dan -g staff file.txt
D. chown dan -g staff file.txt
Correct answer: B
Explanation:
In Unix and Linux systems, the chown command is used to change the ownership of files and directories. This command allows you to change both the user (owner) and the group associated with a file. The proper syntax for assigning both a user and a group is:
chown user:group filename
Now let's analyze the given options one by one:
Option A: chown dan/staff file.txt – This syntax is incorrect. The slash / is not the standard delimiter for specifying user and group. Historically, some systems may have accepted /, but the colon : is the correct and portable format. Using / can result in an error or misinterpretation depending on the system.
Option B: chown dan:staff file.txt – This is the correct command. It assigns dan as the owner and staff as the group for the file file.txt. This format is recognized across most Unix/Linux distributions and is the standard syntax for chown.
Option C: chown -u dan -g staff file.txt – This option uses invalid flags. The chown command does not accept -u or -g flags. Instead, it relies solely on positional arguments and the colon-separated format for user and group.
Option D: chown dan -g staff file.txt – Again, this is invalid syntax. chown doesn’t have a -g option like chgrp does. This would produce an error since the -g flag is not recognized by the chown command.
Additional Note:
If you only want to change the owner, you can do:
chown dan file.txt
If you only want to change the group, and not the user, you can use:
chown :staff file.txt
But to change both the user and group, as required in this question, the correct syntax is:
chown dan:staff file.txt
This assigns the file’s ownership to the user dan and the group staff.
Therefore, the correct answer is: B: chown dan:staff file.txt.
Question 5:
After making changes to the GRUB bootloader configuration file, which command must be executed to ensure the updated boot settings are applied on the next reboot?
A. kill -HUP $(pidof grub)
B. grub-install
C. grub
D. No command is needed
Correct answer: None of the above are correct. The correct command should be:
**grub-mkconfig -o /boot/grub/grub.cfg**
Explanation:
In modern Linux systems using GRUB 2, the GRUB configuration file (/boot/grub/grub.cfg) is not edited directly. Instead, administrators usually edit templates such as /etc/default/grub or add scripts in /etc/grub.d/, and then they must regenerate the main configuration file using the grub-mkconfig command.
Let’s analyze the options provided:
A. kill -HUP $(pidof grub) – This is entirely incorrect. GRUB is not a running daemon, and sending a hang-up signal (SIGHUP) to a nonexistent process does nothing useful in this context. GRUB is a bootloader, not a background service or process.
B. grub-install – This command is used when installing the GRUB bootloader to a device, such as the MBR (Master Boot Record) or EFI partition. It's essential when setting up GRUB initially or recovering from a broken bootloader, but it does not regenerate the GRUB configuration file. It won’t apply your changes to boot settings.
C. grub – This refers to the legacy GRUB Legacy (version 0.x), not GRUB 2. It is obsolete on most modern systems. Even if installed, this command would not be the correct way to apply configuration updates.
D. No command is needed – This is incorrect. After modifying files like /etc/default/grub, those changes do not automatically propagate to the /boot/grub/grub.cfg file. Without manually regenerating the config, GRUB will continue using the old configuration on the next boot.
Correct Process:
To apply configuration changes in GRUB 2, the proper command is:
sudo grub-mkconfig -o /boot/grub/grub.cfg
Or, depending on your distribution, you might use:
sudo update-grub
(On Debian-based systems like Ubuntu, update-grub is a wrapper that internally runs the grub-mkconfig command.)
This command reads configuration templates and scripts (such as /etc/default/grub and /etc/grub.d/*) and generates a new GRUB configuration file at /boot/grub/grub.cfg. Only after this file is updated will your changes (like kernel parameters or default boot entry) take effect on the next reboot.
None of the options A–D correctly describe the necessary step to apply GRUB configuration changes. The correct command is not listed, but it should be:
grub-mkconfig -o /boot/grub/grub.cfg
This is the only correct way to ensure GRUB applies your updated settings on reboot.
Question 6:
Which of the following environment variables is responsible for defining or modifying the directories in which a program looks for dynamic libraries at runtime?
A. LD_LOAD_PATH
B. LD_LIB_PATH
C. LD_LIBRARY_PATH
D. LD_SHARE_PATH
E. LD_RUN_PATH
Correct answer: C
Explanation:
When a program is executed on a Unix or Linux system, it may depend on dynamic libraries (shared objects, typically with the .so extension). The system must know where to find these libraries at runtime, and this is where specific environment variables and configuration files come into play.
One of the most common and effective ways to influence the runtime linker/loader’s search behavior is to use the LD_LIBRARY_PATH environment variable.
Understanding LD_LIBRARY_PATH:
LD_LIBRARY_PATH is an environment variable used by the dynamic linker (ld.so or ld-linux.so) to determine the search path for dynamic libraries at runtime.
It contains a colon-separated list of directories.
If set, it overrides the default library search paths (e.g., /lib, /usr/lib, etc.).
It’s especially useful during development or when running software that depends on non-standard library locations.
Example:
export LD_LIBRARY_PATH=/opt/custom/lib:/home/user/libs
./my_application
This tells the linker to look in /opt/custom/lib and /home/user/libs for any required shared libraries before the standard system paths.
Evaluating Other Options:
A. LD_LOAD_PATH – This is not a valid environment variable for dynamic linking or library search. It doesn’t exist in standard Unix/Linux environments.
B. LD_LIB_PATH – Often confused with the correct one, but this is not a valid variable either. It’s a common typo of LD_LIBRARY_PATH.
D. LD_SHARE_PATH – This also does not exist in the context of runtime library resolution. It may sound plausible due to the “share” prefix, but it’s unrelated to how dynamic libraries are handled.
E. LD_RUN_PATH – This one does exist, but it is used differently. LD_RUN_PATH is typically used at compile/link time, not runtime. It embeds a library search path into the binary using the rpath mechanism, which the dynamic linker can use later. However, once the binary is compiled, changing LD_RUN_PATH has no effect on execution.
To influence the directories in which the dynamic linker searches for shared libraries at runtime, the correct and most widely supported environment variable is LD_LIBRARY_PATH. It’s recognized by the runtime linker and is the go-to solution for overriding default search paths temporarily.
Therefore, the correct answer is: C: LD_LIBRARY_PATH.
Question 7:
When using the find command in a Linux file system, which option limits how many levels of subdirectories are searched?
A. -dirmax
B. -maxdepth
C. -maxlevels
D. -n
E. -s
Correct answer: B
Explanation:
The find command in Linux is a powerful utility used to search for files and directories based on various criteria such as name, size, type, permissions, and modification time. By default, find performs a recursive search, exploring all directories and subdirectories starting from the specified root directory.
However, in some cases, users may want to limit how deep the search goes into subdirectories. This is where the -maxdepth option becomes useful.
Understanding -maxdepth:
The -maxdepth option tells find to limit the directory traversal to a certain number of levels below the starting point.
The value 1 means that find will only evaluate the current directory and not descend into subdirectories.
A value of 2 allows it to explore the current directory and its immediate subdirectories, and so on.
Example:
find /etc -maxdepth 1 -name "*.conf"
This command searches for .conf files only in /etc, without descending into any subdirectories under /etc.
Another example:
find . -maxdepth 2 -type f
This lists all files in the current directory and its immediate subdirectories, but not deeper than two levels.
Evaluating the Incorrect Options:
A. -dirmax – This is not a valid option in the find command. It doesn’t exist in standard Linux or GNU find.
C. -maxlevels – Although this might sound intuitive, this option does not exist in the find syntax.
D. -n – This is used in other commands (e.g., head -n or echo -n), but it is not a valid flag in the context of find.
E. -s – This option is also not recognized by find for limiting depth. In some contexts (like sort), -s may suppress certain behavior, but not here.
The -maxdepth option is the correct and standard method for limiting how many levels of subdirectories find will search through. It's essential when performing scoped file system searches, particularly in large directory trees where performance and specificity matter.
Therefore, the correct answer is: B: -maxdepth.
Question 8:
Which command in a Unix-like system allows setting restrictions on the size of core dumps created when a program crashes?
A. core
B. edquota
C. ulimit
D. quota
Correct answer: C
Explanation:
In Unix-like systems, a core dump is a file that captures the memory image of a running process at the moment it crashes. This file is used primarily for post-mortem debugging by developers to analyze what caused the failure. However, since core dumps can be quite large and potentially expose sensitive information, system administrators often want to restrict or completely disable them.
The primary tool used to set process-level resource limits, including the maximum size of core dump files, is the ulimit command.
Understanding ulimit:
The ulimit command is a shell built-in (in bash, sh, and other shells).
It manages user-level resource limits imposed by the kernel.
One of its options is -c, which controls the maximum size (in blocks) of a core file.
A value of 0 for ulimit -c means no core dumps will be created.
Example commands:
ulimit -c 0
This disables core dumps entirely for the current shell session.
ulimit -c unlimited
This allows core dumps of any size (subject to filesystem constraints).
These settings can also be made persistent by adding them to a shell initialization file like .bashrc, or configured system-wide through PAM limits or /etc/security/limits.conf.
Evaluating the Other Options:
A. core – There is no such command named core for managing core dumps. Core files may be named core, but this option is not valid.
B. edquota – This command is used to edit disk quotas for users and groups. It's unrelated to core dump size; instead, it's about managing filesystem usage limits.
D. quota – Similar to edquota, this is used to display disk usage quotas for a user or group. Again, it has no role in controlling core dumps.
To manage the maximum size of core dump files, the correct and standard command is **ulimit**. It allows both disabling core dumps (ulimit -c 0) and permitting them (ulimit -c unlimited). It provides fine-grained control over numerous resource limits at the user or shell level, making it an essential tool for both developers and system administrators.
Therefore, the correct answer is: C: ulimit.
Question 9:
Which command-line utility can be used to display the current user's scheduled cron jobs?
A. cronlist
B. showcron
C. crontab -l
D. cronjobs
Correct answer: C
Explanation:
On Unix-like systems, cron is a time-based job scheduler used to execute commands or scripts automatically at specified times and intervals. Each user on the system can define their own crontab (cron table), which contains scheduled tasks formatted with timing specifications and corresponding commands.
To view the current user's cron jobs, the correct command-line utility is:
crontab -l
This command lists the current user’s crontab entries, showing all the cron jobs that are scheduled to run under their account.
Breakdown of the Command:
crontab is the command used to manage cron jobs.
The -l option stands for "list" and instructs the system to display the content of the user's crontab.
No root access is required to run crontab -l for your own user. However, root can use it with -u username to view another user's crontab.
Example:
$ crontab -l
0 5 * * * /home/user/backup.sh
This means that the script /home/user/backup.sh will run every day at 5:00 AM.
Evaluating the Incorrect Options:
A. cronlist – This is not a valid command in any standard Unix or Linux distribution. It's a made-up name and will likely return a "command not found" error.
B. showcron – This also is not a recognized command for interacting with cron jobs. While it might exist in custom scripts or tools, it is not a standard utility.
D. cronjobs – Again, this is not a real command-line tool. While the term "cron jobs" is used informally to refer to scheduled tasks, cronjobs is not a valid CLI command.
Additional Tips:
To edit the current user’s cron jobs:
crontab -e
To remove all cron jobs for the current user:
crontab -r
To list another user's cron jobs (requires sudo or root privileges):
sudo crontab -l -u username
When you're asked to list the current user's cron jobs, the correct and universally supported command is crontab -l. It’s a simple and effective way to check what tasks are scheduled to run in the background under your account.
Therefore, the correct answer is: C: crontab -l.
Question 10:
What is the function of the grep command in Unix-based systems?
A. To rename files and directories
B. To compare file contents
C. To search for patterns within text files
D. To list system processes
Correct answer: C
Explanation:
The grep command is one of the most widely used and essential text-processing utilities in Unix and Linux systems. The name "grep" stands for "Global Regular Expression Print", and it is primarily used to search for specific patterns in files or output streams. It is a powerful command that supports regular expressions, enabling users to perform complex search operations with ease.
Primary Function of grep:
Pattern Searching: grep scans input (either from a file or standard input) line by line and prints lines that match a given pattern.
The search pattern can be a simple string or a complex regular expression.
It's often used in conjunction with other commands via piping, making it invaluable in scripting and system administration.
Basic Syntax:
grep [options] pattern [file...]
Example 1 – Search for a word in a file:
grep "error" /var/log/syslog
This command will search for the word “error” in the file /var/log/syslog and print each line that contains the word.
Example 2 – Case-insensitive search:
grep -i "login" /etc/passwd
This performs a case-insensitive search for “login” in /etc/passwd.
Example 3 – Using grep with a pipe:
ps aux | grep apache
This lists all running processes and filters only the lines containing "apache".
Evaluating Other Options:
A. To rename files and directories – This function is performed by the mv command (short for "move"), not grep. Example: mv oldname newname.
B. To compare file contents – File comparison is done using commands like diff, cmp, or comm, not grep. grep searches, it does not compare.
D. To list system processes – This is the job of commands like ps, top, or htop. grep may be used in combination with ps to filter processes, but it does not list processes by itself.
The grep command is a text searching tool designed to match patterns within files or output streams. It is indispensable for developers, system administrators, and anyone working with text or log files in Unix-based environments. Its ability to recognize and work with regular expressions makes it a flexible and powerful choice for pattern recognition tasks.
Therefore, the correct answer is: C: To search for patterns within text files.