Unit 4 - Practice Quiz
1 Which of the following is a core principle of the Linux and Unix design philosophy?
2 Which command is used to list the contents of the current directory?
ls
show
list
dirlist
3
To read the official manual page for the grep command, which command would you enter in the terminal?
man grep
guide grep
info grep
help grep
4 What is the most common command used to execute a single command with root (superuser) privileges?
admin
su
root
sudo
5 Which command is commonly used to add a new user to a Linux system?
newuser
mkuser
useradd
createuser
6
Which command is used to create a new group named sales?
mkgroup sales
group create sales
newgroup sales
groupadd sales
7 Which command displays the user ID (UID), group ID (GID), and all group memberships for the current user?
userinfo
groups
id
whoami
8 Which file in a user's home directory is typically read by the Bash shell to configure the environment for an interactive login session?
/etc/profile
~/.profile
~/.bash_history
/etc/passwd
9 Which command is used to change the permissions of a file?
chperm
chgrp
chmod
chown
10
To change the owner of file.txt to the user bob, which command would you use?
chgrp bob file.txt
owner bob file.txt
chmod bob file.txt
chown bob file.txt
11 What does the 'sticky bit' permission on a directory do?
12
You try to run a script and get a "Permission denied" error. Running ls -l shows the script has -rw-r--r-- permissions. What is the most likely problem?
13 Which of the following is a widely used command-line utility for creating and managing partition tables on a disk?
format
fdisk
dd
mount
14 In the Logical Volume Manager (LVM) hierarchy, what are Logical Volumes (LVs) created from?
15
What is the purpose of the /etc/fstab file?
16
Which command is used to create an ext4 filesystem on the partition /dev/sda1?
format /dev/sda1 ext4
newfs -t ext4 /dev/sda1
fs.create ext4 /dev/sda1
mkfs.ext4 /dev/sda1
17
In the Linux shell, what does the cd ~ command do?
/)
18 Which directory in the Filesystem Hierarchy Standard (FHS) is designated for system-wide configuration files?
/etc
/home
/bin
/var
19 Which file contains the encrypted passwords for user accounts on a modern Linux system?
/etc/group
/etc/passwd
/etc/shadow
/etc/login.defs
20 What is a 'mount point' in Linux?
21
An administrator needs to set permissions for a directory named /srv/project_data so that:
The owner (root) can read, write, and enter the directory.
Members of the developers group can read and enter the directory, but cannot create or delete files.
* All other users have no access at all.
Which chmod command will correctly apply these permissions?
chmod 754 /srv/project_data
chmod 640 /srv/project_data
chmod 770 /srv/project_data
chmod 750 /srv/project_data
22
A logical volume lv_archive in volume group vg_storage is running out of space. You have already added a new physical volume /dev/sdd1 to the volume group using vgextend. The logical volume is formatted with an ext4 filesystem. Which sequence of commands will extend the logical volume to use all the new free space and make it available to the operating system?
lvresize -l +100%FREE /dev/vg_storage/lv_archive followed by mount -o remount /dev/vg_storage/lv_archive
lvextend -l +100%FREE /dev/vg_storage/lv_archive followed by resize2fs /dev/vg_storage/lv_archive
lvextend -L +100G /dev/vg_storage/lv_archive (This command alone is sufficient)
resize2fs /dev/vg_storage/lv_archive followed by lvextend -l +100%FREE /dev/vg_storage/lv_archive
23
You manage a shared directory /data/team_files. You need to ensure that when a user deletes a file from this directory, they can only delete files they own, even if they have write permissions on the directory itself. Which command would you use to enforce this behavior?
chattr +i /data/team_files
chmod u+s /data/team_files
chmod +t /data/team_files
chmod g+s /data/team_files
24
A user sara, who is a member of the analysts group, is unable to execute a script located at /opt/scripts/run_report.sh. The permissions for the script are -rw-r-x--- 1 admin analysts 1204 Oct 26 15:00 run_report.sh. What is the most likely reason sara cannot run the script?
admin, not sara.
/opt, which sara cannot access.
analysts group, which sara belongs to, does not have the execute (x) permission.
sara is in the analysts group.
25
A user needs to become the root user and have the environment configured as if they had logged in directly as root (e.g., sourcing /root/.bash_profile). Which command is the most appropriate for this task?
su -
su
sudo -s
sudo bash
26
You need to modify the user account bwayne to add them to the supplementary groups justice and league without removing them from any existing groups they are already a part of. Which command achieves this?
gpasswd -a bwayne justice && gpasswd -a bwayne league
usermod -G justice,league bwayne
usermod -aG justice,league bwayne
useradd -G justice,league bwayne
27
You have an entry in /etc/fstab for a network filesystem that is not always available at boot. The system boot process is failing or being significantly delayed because it's trying to mount this filesystem. Which mount option should you add to the /etc/fstab entry to prevent the system from trying to mount it automatically at boot?
nofail
noauto
lazy
defaults
28
The ability to redirect the standard output of one command into the standard input of another command, such as ps aux | grep 'httpd' | wc -l, is a powerful feature of the Linux shell. This directly embodies which two interconnected Linux philosophies?
29
A directory /var/www/html is owned by root:root. You need to change its group ownership to www-data without altering its user ownership. Which command is the most direct way to do this?
chown .www-data /var/www/html
chown root:www-data /var/www/html
chmod g+w /var/www/html
chgrp www-data /var/www/html
30
An administrator wants to prevent a critical configuration file, /etc/app.conf, from being modified or deleted by any user, including root. Which command would make the file immutable?
chown nobody:nobody /etc/app.conf
setfacl -x u:root /etc/app.conf
chmod 000 /etc/app.conf
chattr +i /etc/app.conf
31
You are currently in the directory /usr/share/doc. You want to execute a command that is located in your current user's home directory, in a subdirectory named bin. Which of the following commands would execute the script mytool correctly without changing your current directory?
../home/user/bin/mytool
./bin/mytool
cd ~/bin && ./mytool
~/bin/mytool
32
After running a command, you find that the / (root) filesystem is nearly full. You need to find the largest directories within /var to identify what is consuming the most space. Which command is most suitable for this task?
find /var -size +1G
ls -lS /var
df -h /var
du -sh /var/* | sort -rh | head -n 10
33
As an administrator, you need to delete the group interns. However, you first want to ensure that no users have this group set as their primary group, as this could cause issues. Which command would help you find any users whose primary group is interns?
grep "^.*:.*:$(getent group interns | cut -d: -f3):" /etc/passwd
members interns
getent group interns
find /home -group interns
34
You are trying to understand the purpose of the -p option for the mkdir command. You want to see the official, detailed documentation for mkdir. Which command is the most direct way to access this information?
man mkdir
mkdir --help
apropos mkdir
info mkdir
35
A script needs to check if a user named jenkins exists on the system, regardless of whether the user is defined locally in /etc/passwd or in a network directory service like LDAP. Which command provides the most reliable way to perform this check?
grep '^jenkins:' /etc/passwd
getent passwd jenkins
id jenkins
ls /home/jenkins
36
A user wants to create a set of custom command aliases (e.g., alias ll='ls -alF') that are loaded every time they open a new interactive terminal, but not for non-interactive scripts. Where is the most appropriate file for the user to place these alias definitions on a typical bash-based system?
~/.bash_profile
/etc/profile
~/.bashrc
/etc/bash.bashrc
37 You need to run a command that will take a long time to complete. You want to start the command and be able to log out of your SSH session without terminating the process. Which of the following is a common and effective way to achieve this?
bg.
nohup and place it in the background with &.
Ctrl+Z.
(long_command).
38
You have a web server running as the www-data user. A PHP script needs to write to a cache directory located at /var/www/html/cache. You've set the permissions on the cache directory to 775 and the ownership to youruser:www-data. However, the script still fails with a "permission denied" error. What is a likely cause related to the directory's parentage?
777, allowing anyone to write.
www-data user.
www-data user does not have execute permission on one of the parent directories, such as /var/www/ or /var/www/html/.
www-data:www-data.
39
You are using fdisk to partition a new 1TB disk (/dev/sdb) on a server that uses a traditional MBR (Master Boot Record) partition table. You plan to create 5 partitions. What is the most appropriate partitioning scheme to accomplish this?
40
You need to safely reduce the size of an ext4-formatted logical volume lv_data in volume group vg_main from 100G to 80G. What is the correct and mandatory order of operations to avoid data loss?
41
A system administrator needs to shrink an ext4 filesystem located on a logical volume vg_data/lv_app from 100G to 80G. The volume group vg_data has sufficient free space. Which of the following sequences of commands is the correct and safest way to perform this operation?
umount /dev/vg_data/lv_app2.
lvreduce --size 80G /dev/vg_data/lv_app3.
resize2fs /dev/vg_data/lv_app 80G4.
mount /dev/vg_data/lv_app /mnt/app
resize2fs /dev/vg_data/lv_app 80G2.
lvreduce --size 80G /dev/vg_data/lv_app3.
mount -o remount,rw /dev/vg_data/lv_app
lvreduce --size 80G /dev/vg_data/lv_app2.
resize2fs /dev/vg_data/lv_app
umount /dev/vg_data/lv_app2.
fsck -f /dev/vg_data/lv_app3.
resize2fs /dev/vg_data/lv_app 80G4.
lvreduce --size 80G /dev/vg_data/lv_app
42
A user 'dev1' reports they cannot read the file /project/app/src/main.c. 'dev1' is a member of the 'developers' group. The permissions are as follows:
bash
$ ls -ld /project /project/app /project/app/src
drwxr-x--x. 2 root root 4096 Jun 10 10:00 /project
drwxr-x---. 3 projectd developers 4096 Jun 10 10:05 /project/app
drwxr-s---. 4 projectd developers 4096 Jun 10 10:10 /project/app/src
$ ls -l /project/app/src/main.c
-rw-rw-r--. 1 dev2 developers 1204 Jun 10 11:00 /project/app/src/main.c
What is the root cause of the permission issue?
main.c has incorrect permissions; the 'others' category has read access while the group only has read-write.
main.c file is owned by user 'dev2', not 'dev1'.
/project/app directory does not have the SGID bit set, causing incorrect group ownership on new files.
/project directory.
43
A system administrator sets the SUID bit on a Bash script owned by root (chmod u+s /usr/local/bin/cleanup.sh) that performs privileged operations. However, when a non-root user executes the script, the whoami command inside the script still outputs their own username, not 'root'. What is the most accurate explanation for this behavior?
nosuid option.
#! (shebang) line in the script is missing or incorrect, preventing the kernel from executing it with the correct interpreter.
44 A user logs into a system running Bash via a graphical login manager (like GDM or LightDM) and then opens a terminal window. Which of the following files would be sourced, and in what primary order, to establish the environment for that terminal window?
/etc/bash.bashrc, then ~/.bashrc
/etc/profile, then ~/.bash_profile
/etc/profile, then ~/.profile, then ~/.bashrc
~/.bash_profile, then ~/.bashrc
45
A server's primary data partition, formatted with XFS, is nearly full. df -h shows 99% usage. However, df -i shows only 10% inode usage. An administrator deletes a 500GB log file, but df -h still reports 99% usage. The lsof command shows no open file descriptors for the deleted file. What is the most likely cause and the appropriate command to reclaim the space on this XFS filesystem?
xfs_fsr.
xfs_repair from a rescue environment.
46
What is the primary functional difference between the following two commands?
Command A: find . -type f -exec grep 'pattern' {} +
Command B: find . -type f | xargs grep 'pattern'
xargs handles them correctly by default.
grep process for every single file found.
-exec ... + builds a single grep command line, whereas xargs may invoke grep multiple times.
find is too long for a single command line, while Command A will not.
47
A user's umask is set to 0027. The user then creates a new directory named testdir and a new file named testfile inside it. What will be the final octal permissions of testdir and testfile?
testdir: 775, testfile: 664
testdir: 750, testfile: 660
testdir: 750, testfile: 640
testdir: 757, testfile: 640
48
An administrator needs to run a complex command as root: log_dumper -u webapp | gzip > /opt/backups/webapp_$(date +%F).log.gz. The log_dumper command requires root privileges. Which of the following is the most effective and syntactically correct way to execute this entire pipeline with sudo?
sudo (log_dumper -u webapp | gzip > /opt/backups/webapp_$(date +%F).log.gz)
sudo log_dumper -u webapp | gzip > /opt/backups/webapp_$(date +%F).log.gz
sudo sh -c 'log_dumper -u webapp | gzip > /opt/backups/webapp_$(date +%F).log.gz'
sudo log_dumper -u webapp | sudo gzip > /opt/backups/webapp_$(date +%F).log.gz
49
Consider the following directory structure:
/data/app/config -> /etc/app/config.conf (symbolic link)
/data/app/logs/ (directory)
Both /data/app and its contents are owned by user1:group1. The symbolic link target, /etc/app/config.conf, is owned by root:root. What is the result of running chown -R user2:group2 /data/app?
/data/app, /data/app/logs, the link /data/app/config, AND the target file /etc/app/config.conf will be changed to user2:group2.
/data/app and /data/app/logs will change to user2:group2. The ownership of the symbolic link itself (/data/app/config) and its target (/etc/app/config.conf) will not change.
/data/app, /data/app/logs, and /data/app/config will be changed to user2:group2. The target file /etc/app/config.conf will remain owned by root:root.
50
The command tar cf - /some/dir | ssh remote_host 'tar xf - -C /dest/dir' is often used to copy directory trees between hosts. This pipeline is a powerful illustration of the Linux design philosophy. Which set of principles does this single command line most comprehensively demonstrate?
51
A directory /var/www/shared has permissions drwxrws---. A user, 'webdev', who is a member of the directory's group, creates a new subdirectory /var/www/shared/assets. What will be the group ownership and permissions of the new assets directory, assuming a umask of 002?
drwxr-xr-x (755).
drwxrwsr-x (2775).
/var/www/shared, and permissions will be drwxr-sr-x (2755).
/var/www/shared, and permissions will be drwxrwsr-x (2775).
52
An administrator is provisioning a new 6TB disk (/dev/sdc) on a modern server that will boot using UEFI. They need to create a 200MB EFI System Partition, a 4GB swap partition, and assign the rest of the space to a single data partition. Which partitioning tool and label type are required for this task, and why?
cfdisk with a gpt label, but the total number of primary partitions cannot exceed 4.
parted with an msdos (MBR) label, because it can handle disks larger than 2TB by using logical partitions.
gdisk with a gpt label, because MBR has a 2TB partition limit and cannot support a 6TB disk.
fdisk with an msdos (MBR) label, because it is the most compatible standard.
53
A system administrator needs to provide access to a directory, /srv/data, inside a chroot jail located at /var/jail. To improve security, the data must be read-only inside the jail, and no new device nodes can be created within it. Simply copying the data is not feasible due to its size. Which /etc/fstab entry would best achieve this?
/srv/data /var/jail/data none ro,bind 0 0
LABEL=data /var/jail/data ext4 defaults,ro 0 2
/srv/data /var/jail/data auto remount,ro,nodev 0 0
/srv/data /var/jail/data none bind,ro,nodev,noexec 0 0
54
A script needs to reliably get the primary group name of a user 'testuser' on a system where user information could be served by local /etc/passwd files, NIS, or LDAP. Which of the following commands is the most robust and portable way to achieve this?
groups testuser | awk '{print $3}'
id -gn testuser
grep '^testuser:' /etc/passwd | cut -d: -f4 | xargs -I{} grep ':{}' /etc/group | cut -d: -f1
getent passwd testuser | cut -d: -f4 | getent group | grep -w "$(cat -)" | cut -d: -f1
55
According to the Filesystem Hierarchy Standard (FHS), what is the fundamental distinction and intended use case for /opt versus /usr/local?
/opt is for optional, self-contained, proprietary software packages that do not scatter files across the filesystem, while /usr/local is the standard location for software compiled from source by the administrator that follows the traditional bin/, lib/, share/ structure.
/usr/local is a legacy directory that is now symbolically linked to /opt on most modern systems.
/opt is for essential system software installed by the package manager, while /usr/local is for temporary user-compiled software.
/opt is for multi-user applications, while /usr/local is for single-user applications.
56
An administrator runs userdel -r olduser. The user 'olduser' had a home directory at /home/olduser which contained files and was also the only member of the group 'olduser'. Which of the following statements most accurately describes the state of the system after the command completes?
/etc/group and must be removed manually with groupdel.
/home/olduser remains, with its files now owned by UID/GID numbers.
/home/olduser and its contents are removed, and the group 'olduser' is also removed if no other users have it as their primary group.
57
A sysadmin wants to find a specific configuration directive within a very large man page, like man 5 sssd.conf. They know the directive contains the word 'timeout' but are tired of scrolling. What is the most efficient way to search for 'timeout' within the man pager (which is typically less) and navigate between occurrences?
/timeout and press Enter to search forward. Then press n to find the next occurrence or N to find the previous one.
grep timeout and press Enter. This will filter the man page.
F timeout and press Enter to start a forward search.
man, and run man 5 sssd.conf | grep timeout.
58
A web server running as the user www-data needs to write to a log file at /var/log/webapp/app.log. The administrator sets the ownership of /var/log/webapp to root:www-data and permissions to 775. They set the ownership of app.log to root:www-data with permissions 664. The web application still fails to write to the log file with a 'permission denied' error. What is the most likely misconfiguration that has been overlooked?
/var/log/webapp/.
/var/log does not grant write access to the www-data user or group.
www-data user needs execute permissions on the app.log file itself to write to it.
59
A logical volume lv_data is part of a volume group vg_main that consists of two physical volumes: /dev/sda2 and /dev/sdb1. An administrator takes a snapshot of lv_data called lv_data_snap. After the snapshot is created, 5GB of new data is written to the original lv_data. What is the effect on the disk space usage?
vg_main to store the original, pre-change data blocks for the snapshot.
lv_data logical volume itself.
60 An administrator needs to change the Group ID (GID) of an existing group 'developers' from 1005 to 2005. The system has thousands of files owned by this group. Which command would correctly change the group's GID and what is a critical follow-up action the administrator must take?
/etc/group to change the GID. Then, reboot the server for the changes to apply to the filesystem.
groupmod -g 2005 developers. No follow-up is needed as the kernel handles the mapping dynamically.
groupadd -g 2005 newdevs, migrate users to the new group, and then delete the old 'developers' group.
groupmod -g 2005 developers, then run find / -group 1005 -exec chgrp -h developers {} \; to update the GID on all associated files.