CompTIA Linux+ (XK0-005) Exam-style mock test
CompTIA Linux+ (XK0-005) Practice Exams|Practice test
Full explanations
Exam format
Pass line 72%
33 USD One-time · lifetime access
Enroll →
Sample questions
Example1 · System Management
A web hosting provider adds a new 2 TB disk (/dev/sdc) to a storage node and needs a single partition that supports the full capacity. Which command creates the required partition table?
✓parted /dev/sdc mklabel gpt
Correct. parted ... mklabel gpt writes a GPT label, which supports disks larger than 2 TB.
・mkfs.ext4 /dev/sdc with the default journaling options enabled
Incorrect. mkfs.ext4 builds a filesystem and does not create a partition table.
・fdisk /dev/sdc using an MBR-style table for the whole disk
Incorrect. An MBR table caps usable space at roughly 2 TB and cannot address the full disk.
・pvcreate /dev/sdc so the device becomes a managed physical volume
Incorrect. pvcreate initializes an LVM physical volume rather than a partition table.
Explanation
GPT partition tables are required to fully use disks larger than 2 TB; parted mklabel gpt applies that label.
Example2 · Security
At a web hosting provider, a shared upload directory must let any customer create files but prevent one customer from deleting another customer's files. Which command sets the correct permission?
✓chmod 1777 /srv/uploads
Correct. The sticky bit (leading 1) with 777 lets anyone create files but restricts deletion to the file's owner.
・chmod 0777 /srv/uploads
Incorrect. Plain 0777 allows any user to delete any file, which is exactly what must be prevented.
・chmod 2755 /srv/uploads
Incorrect. 2755 sets the setgid bit and denies group and other write access entirely.
・setfacl -R -m g:web:rwx /srv/uploads and then remove every other entry from the directory tree
Incorrect. This grants broad group write but still lacks the sticky bit needed to protect deletion.
Explanation
The sticky bit on a world-writable shared directory limits deletion and renaming of a file to its owner.
Example3 · Scripting, Containers, and Automation
A web hosting provider's admin writes a Bash script that begins with a line to ensure it runs under Bash regardless of the user's login shell. Which first line should the script contain?
✓#!/bin/bash
Correct. The shebang line #!/bin/bash tells the kernel to execute the script using the Bash interpreter.
・#include bash
Incorrect. #include is a C preprocessor directive, not a shell shebang.
・run with bash shell interpreter located in the bin directory
Incorrect. This is plain prose, not a valid shebang line syntax a script can use.
・import /bin/bash
Incorrect. import is not a shell mechanism for selecting an interpreter.
Explanation
A shebang (#!) followed by the interpreter path forces the script to run under the specified shell.
Example4 · Troubleshooting
A fintech backend engineer is paged because the payments service cannot write transaction logs. The filesystem has plenty of free space according to df -h, yet writes fail with 'No space left on device'. Which command best reveals the actual cause?
✓df -i
Correct. df -i shows inode usage, and a filesystem can report free space while being completely out of inodes, which produces this exact error.
・du -sh /var
Incorrect. du -sh /var totals the disk space consumed by a directory and does not reveal inode exhaustion, which is the real problem here.
・free -m
Incorrect. free -m reports memory and swap usage, not filesystem capacity or inode availability.
・lsblk -f
Incorrect. lsblk -f lists block devices and their filesystem types but does not report inode consumption levels.
Explanation
When space appears free but writes fail with 'No space left on device', the filesystem has typically run out of inodes, which df -i reveals.
Example5 · System Management
A fintech backend engineer runs a batch settlement script and wants both standard output and standard error written to the same file named recon.log, overwriting any prior content. Which redirection command accomplishes this on a Bash shell?
✓./settle.sh > recon.log 2>&1
Correct. Redirecting stdout to recon.log and then pointing stderr (2) at the same destination with 2>&1 captures both streams in one file.
・./settle.sh 2> recon.log
Incorrect. This captures only standard error, so normal settlement output is lost.
・./settle.sh | tee recon.log
Incorrect. tee duplicates stdout to the file and the terminal but does not capture standard error.
・./settle.sh > recon.log && ./settle.sh 2> recon.log overwriting each stream separately
Incorrect. Running the script twice is wasteful and the second invocation would recompute settlement, not merge the streams.
Explanation
Combining stream redirection with 2>&1 after the file target sends both stdout and stderr to the same file.
Example6 · System Management
On a Debian-based fintech API server, an engineer must install the nginx package and its dependencies from the configured repositories without being prompted for confirmation. Which command should be used?
✓apt-get install -y nginx
Correct. apt-get install -y installs nginx, resolves dependencies from the repositories, and the -y flag answers prompts automatically.
・dpkg -i nginx
Incorrect. dpkg installs a local .deb file and does not resolve repository dependencies.
・rpm -ivh nginx
Incorrect. rpm is for RPM-based distributions, not a Debian-based server.
・apt-get download nginx then manually resolve each dependency by hand afterward
Incorrect. apt-get download only fetches the package file and does not install or resolve dependencies for you.
Explanation
apt-get install with -y performs a non-interactive install and handles dependency resolution from the repos.
Example7 · System Management
In a research computing lab, an administrator added a new SSD for genomics datasets and wants it mounted automatically at /data/genomics on every boot. Which file should be edited to achieve persistent mounting?
✓/etc/fstab
Correct. /etc/fstab defines filesystems to mount persistently at boot time.
・The /etc/mtab file that the kernel regenerates on each reboot to list devices
Incorrect. /etc/mtab reflects currently mounted filesystems and does not control boot-time mounting.
・/proc/mounts
Incorrect. /proc/mounts is a kernel-generated view of active mounts, not a configuration file.
・/etc/mounts
Incorrect. /etc/mounts is not a standard Linux configuration file.
Explanation
Persistent mount configuration is defined in /etc/fstab, which systemd and mount read at boot.
Example8 · System Management
On a Rocky Linux node in the lab cluster, a scientist needs to install the hdf5 package along with all its required dependencies from configured repositories. Which command accomplishes this most directly?
・rpm -i hdf5
Incorrect. rpm -i installs a local package but does not resolve dependencies from repositories.
✓dnf install hdf5
Correct. dnf install resolves and installs the package with its dependencies from configured repos.
・dpkg --install the hdf5 package file downloaded manually from an upstream mirror
Incorrect. dpkg is for Debian-based systems, not rpm-based Rocky Linux.
・yum localinstall hdf5
Incorrect. yum localinstall expects a local RPM file path, not a repository package name.
Explanation
On rpm-based distros, dnf install resolves repository dependencies automatically, unlike rpm -i.
Example9 · System Management
A lab administrator wants the Slurm scheduler daemon to start automatically whenever the head node boots, but does not want to start it right now. Which command sets only the boot-time behavior?
・systemctl start slurmctld
Incorrect. start launches the service immediately but does not persist across reboots.
✓systemctl enable slurmctld
Correct. enable creates the symlinks so the unit starts on boot without starting it now.
・systemctl mask slurmctld
Incorrect. mask prevents the service from being started at all.
・systemctl status slurmctld
Incorrect. status only displays current state information.
Explanation
systemctl enable configures boot-time autostart; start affects only the current runtime.
Example10 · System Management
A telecom infrastructure engineer adds a new 2 TB disk to a provisioning server and wants to partition it with a GPT layout because the disk exceeds the MBR size limit. Which utility should the engineer use to create the GPT partition table?
・mkfs
Incorrect. The mkfs command builds a filesystem on an existing partition, not a partition table.
✓gdisk
Correct. The gdisk utility creates and manages GPT partition tables, which support disks larger than the 2 TB MBR limit.
・lsblk
Incorrect. The lsblk command lists block devices and their layout but cannot create partitions.
・blkid
Incorrect. The blkid command reports filesystem UUIDs and types but does not partition disks.
Explanation
GPT partitioning is required for disks beyond the MBR 2 TB ceiling, and gdisk is the standard interactive tool for building GPT tables.
Example11 · System Management
On a telecom billing node, a technician must grow an existing ext4 logical volume that already has free space in its volume group so the filesystem can hold more call-detail records. After extending the LV, which command resizes the ext4 filesystem online?
✓resize2fs
Correct. The resize2fs command grows an ext2/3/4 filesystem to match the extended logical volume, and it supports online resizing.
・pvcreate
Incorrect. The pvcreate command initializes a physical volume and does not resize filesystems.
・vgextend
Incorrect. The vgextend command adds a physical volume to a volume group rather than resizing a filesystem.
・lvreduce
Incorrect. The lvreduce command shrinks a logical volume, which is the opposite of the requested operation.
Explanation
Once an LV is enlarged with lvextend, resize2fs expands the ext4 filesystem to use the new space.
Example12 · System Management
An SRE at a cloud-native SaaS firm edits /etc/default/grub to add a kernel parameter on a fleet of RHEL-based API nodes. The change must persist across reboots after the node images are rebuilt. Which command regenerates the bootloader configuration so the parameter takes effect?
✓grub2-mkconfig -o /boot/grub2/grub.cfg
Correct. grub2-mkconfig reads /etc/default/grub and the scripts in /etc/grub.d to rebuild grub.cfg, so the new kernel parameter persists.
・update-initramfs -u -k all
Incorrect. update-initramfs rebuilds the initramfs image, not the GRUB2 configuration file.
・systemctl daemon-reload
Incorrect. daemon-reload only reloads systemd unit definitions and has no effect on the bootloader.
・mkinitrd --force /boot/initramfs-$(uname -r).img $(uname -r)
Incorrect. mkinitrd creates an initial RAM disk image and does not regenerate grub.cfg.
Explanation
Kernel parameters set in /etc/default/grub are only applied after grub2-mkconfig regenerates the active grub.cfg.
Example13 · System Management
A platform engineer must pin a build-agent VM to a known-good version of the nginx package on a Debian-based host so an automated upgrade job cannot replace it. Which command places nginx on hold?
✓apt-mark hold nginx
Correct. apt-mark hold marks the package so apt/apt-get will not upgrade or remove it automatically.
・dpkg --configure nginx
Incorrect. dpkg --configure finishes configuring an unpacked package and does not prevent upgrades.
・apt-get install --reinstall nginx
Incorrect. Reinstalling nginx reinstalls the current version but leaves it eligible for future upgrades.
・aptitude safe-upgrade nginx
Incorrect. aptitude safe-upgrade would upgrade packages, which is the opposite of pinning the version.
Explanation
apt-mark hold freezes a package at its installed version, blocking automated upgrade jobs.
Example14 · System Management
A government data center administrator added a new 2 TB disk at /dev/sdc to an archive server. Which command displays the full partition table so the administrator can confirm whether the disk already contains partitions before formatting it?
・cat /dev/sdc
Incorrect. Reading the raw block device with cat dumps binary data to the terminal and does not report the partition layout.
✓fdisk -l /dev/sdc
Correct. The fdisk -l command lists the partition table of the specified disk, letting the administrator see existing partitions before formatting.
・mount /dev/sdc
Incorrect. The mount command attaches a filesystem to a directory and does not display partition information.
・du -sh /dev/sdc
Incorrect. The du command reports disk usage of files and directories, not the partition table of a device.
Explanation
fdisk -l prints the partition table for a device, which is the correct way to inspect an unformatted disk before provisioning it.
Example15 · System Management
On an RPM-based government web server, an administrator must install a locally downloaded package file named patch-agent.rpm while also resolving its dependencies from the configured repositories. Which command accomplishes this?
・rpm -i patch-agent.rpm
Incorrect. The rpm -i command installs the package but does not pull in missing dependencies from repositories.
✓dnf install ./patch-agent.rpm
Correct. The dnf install command, given a local file path, installs the package and resolves its dependencies from configured repositories.
・apt install patch-agent.rpm
Incorrect. The apt tool is used on Debian-based systems and does not handle RPM package files.
・yum remove patch-agent
Incorrect. The yum remove command uninstalls software rather than installing the downloaded package.
Explanation
dnf install accepts a local .rpm path and automatically resolves dependencies through enabled repositories, unlike bare rpm -i.
▶ Try 10 free questions (graded)