CompTIA Linux+ study materials
CompTIA Linux+ study resources

CompTIA Linux+ practice questions

One question at a time. Build your CompTIA Linux+ understanding.

First 50 of 200 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.

Continue in the practice tool above to load more questions, 50 at a time.

Question 1System Management

Which command displays the target that systemd will boot into by default?

  1. systemctl isolate default.target
  2. systemctl list-units --type=target
  3. systemctl get-default Correct answer.
  4. systemctl cat default.target

Explanation

systemd records the default boot target as the default.target link in /etc/systemd/system, and systemctl get-default prints the name of the unit that link points to. It is a read-only query and does not change the running system.

Question 2System Management

Which command refreshes the package index metadata on a Debian-based system without installing anything?

  1. apt-get install --refresh
  2. apt-get update Correct answer.
  3. apt-get upgrade
  4. dpkg --configure -a

Explanation

apt-get update downloads the Packages indexes from every configured repository so that later install and upgrade operations see current versions. It never installs or upgrades packages by itself.

Question 3System Management

Which command displays messages from the kernel ring buffer, such as hardware detection events?

  1. systemctl status kernel
  2. tail -f /var/log/apt/history.log
  3. dmesg Correct answer.
  4. journalctl --user

Explanation

dmesg reads the kernel ring buffer, which holds boot-time hardware probing, driver loading, and other kernel messages. journalctl -k provides similar output through the journal.

Question 4System Management

An administrator has already created and formatted a swap file at /swapfile. Which command activates it immediately?

  1. swaplabel /swapfile
  2. mkswap /swapfile
  3. mount -t swap /swapfile /swap
  4. swapon /swapfile Correct answer.

Explanation

swapon tells the kernel to begin using an area that has already been prepared with mkswap as swap space. To keep it across reboots, a matching entry is added to /etc/fstab.

Question 5System Management

Which command shows journal entries only for the sshd service?

  1. journalctl -p sshd
  2. journalctl -b sshd
  3. journalctl --unit-list sshd
  4. journalctl -u sshd Correct answer.

Explanation

The -u option filters the journal by a systemd unit name, so only messages attributed to sshd.service are displayed. Filtering is based on the unit metadata attached to each entry.

Question 6System Management

Which command loads a kernel module together with any modules that it depends on?

  1. modinfo mymodule
  2. lsmod mymodule
  3. modprobe mymodule Correct answer.
  4. depmod mymodule

Explanation

modprobe consults the dependency file generated by depmod and loads the requested module plus everything it needs. insmod would insert only a single module and fail if its dependencies were missing.

Question 7System Management

Which command sets the system time zone to America/Denver?

  1. localectl set-keymap America/Denver
  2. timedatectl set-timezone America/Denver Correct answer.
  3. tzselect --set America/Denver
  4. locale-gen America/Denver

Explanation

timedatectl set-timezone points /etc/localtime at the named zoneinfo file and updates the system clock configuration accordingly. The change is immediate and persistent.

Question 8System Management

Which command opens the calling user's crontab for editing?

  1. systemctl edit cron
  2. crontab -l
  3. cat /etc/crontab
  4. crontab -e Correct answer.

Explanation

crontab -e opens the calling user's personal crontab in the editor defined by $EDITOR and installs it after the file is saved. Each user's crontab is stored separately under /var/spool/cron.

Question 9System Management

After editing the ExecStart line of /etc/systemd/system/backup.service, what must be done before the new definition is used?

  1. systemctl enable backup.service
  2. systemctl reset-failed backup.service
  3. systemctl reload backup.service
  4. systemctl daemon-reload Correct answer.

Explanation

systemd caches unit files when it starts, so editing a unit requires systemctl daemon-reload to force the manager to re-read its configuration. The change then applies the next time the unit is started.

Question 10System Management

An administrator changed GRUB_TIMEOUT in /etc/default/grub on a Debian-based system. Which command writes that change into the boot loader configuration?

  1. grub-install /dev/sda
  2. update-grub Correct answer.
  3. systemctl reboot --firmware-setup
  4. dracut --force

Explanation

/etc/default/grub holds variables that are consumed by the configuration generator; update-grub runs grub-mkconfig and writes the results into grub.cfg. The on-disk boot loader code is untouched by this step.

Question 11System Management

A system has been started at emergency.target. Which statement describes that environment?

  1. Only the root filesystem is mounted, and it is read-only. Correct answer.
  2. It is identical to multi-user.target but without a login prompt.
  3. All local filesystems are mounted and networking is enabled.
  4. It runs only the units named in /etc/fstab.

Explanation

emergency.target is the most minimal maintenance mode: it mounts the root filesystem read-only and starts almost nothing else. rescue.target is slightly less restrictive because it mounts local filesystems and starts basic services.

Question 12System Management

Journal entries vanish after every reboot. Which change keeps them on disk permanently?

  1. Enable the systemd-journald-audit socket
  2. Set Storage=persistent in journald.conf Correct answer.
  3. Set ForwardToSyslog=yes in /etc/systemd/journald.conf
  4. Run journalctl --flush after every reboot

Explanation

By default journald keeps logs in the volatile /run directory. Storage=persistent directs journald to write to /var/log/journal, which survives reboots.

Question 13System Management

A file /etc/cron.d/rotate-job contains the line "0 3 * * * root /usr/local/bin/rotate.sh". Which statement about this line is accurate?

  1. It runs the script once every three minutes.
  2. It must first be installed with crontab -e to work.
  3. It contains a user field, which files in /etc/cron.d require. Correct answer.
  4. Files in /etc/cron.d may not run jobs as root.

Explanation

Files placed in /etc/cron.d use the system crontab format, which inserts the account name after the five time fields. Per-user crontabs omit that field because the owner is implied.

Question 14System Management

An administrator creates /etc/systemd/system/cleanup.timer with an OnCalendar setting. What else must exist for the timer to start anything?

  1. A target named cleanup.target
  2. An at job scheduled with at -f
  3. A matching entry in /etc/cron.d/cleanup
  4. A service unit named cleanup.service Correct answer.

Explanation

A timer activates the unit that shares its name with the .service suffix. Without cleanup.service, the timer expires and has nothing to start.

Question 15System Management

Which command identifies the installed package that owns the file /usr/bin/curl on an RPM-based system?

  1. rpm -qf /usr/bin/curl Correct answer.
  2. rpm -qa curl
  3. dnf repoquery curl
  4. dnf list /usr/bin/curl

Explanation

rpm -qf queries the local RPM database for the package that installed a given path. dnf provides can answer a similar question for packages in repositories, but file ownership of what is installed is an rpm query.

Question 16System Management

An ext4 filesystem on logical volume /dev/vg0/data has just been enlarged with lvextend -L +5G. What must be done next?

  1. Run resize2fs /dev/vg0/data. Correct answer.
  2. Run xfs_growfs /dev/vg0/data.
  3. Recreate the filesystem with mkfs.ext4.
  4. Nothing; ext4 grows automatically when the device grows.

Explanation

lvextend only enlarges the block device; the filesystem inside must then be told to use the new space. For ext4 the tool is resize2fs, which can grow the filesystem while it is mounted.

Question 17System Management

Which file reports the current status of the software RAID arrays on a Linux system?

  1. /etc/mdadm.conf
  2. /var/log/mdadm.log
  3. /proc/mdstat Correct answer.
  4. /sys/block/md/status

Explanation

The kernel exports the state of md devices through /proc/mdstat, showing member disks, RAID level, and resync progress. mdadm --detail reports the same information through a different interface.

Question 18System Management

Which command changes a kernel parameter immediately for the running system only?

  1. echo 1 > /etc/sysctl.conf
  2. sysctl -w net.ipv4.ip_forward=1 Correct answer.
  3. systemctl restart systemd-sysctl.service
  4. sysctl -p

Explanation

The -w option writes the value to the matching file under /proc/sys, so the change takes effect at once but is lost at reboot. Persistence requires an entry in a sysctl configuration file.

Question 19System Management

After adding a new entry to /etc/fstab, which command verifies that every listed filesystem can actually be mounted before the next reboot?

  1. mount -a Correct answer.
  2. fsck -A
  3. swapon -a
  4. blkid /etc/fstab

Explanation

mount -a attempts to mount every fstab entry that is not already mounted, so any typo in device, mount point, or options surfaces immediately. Errors reported here would otherwise appear at boot.

Question 20System Management

Which file sets persistent per-user resource limits such as the maximum number of open file descriptors?

  1. /etc/security/limits.conf Correct answer.
  2. /etc/default/limits
  3. /etc/systemd/limits.conf
  4. /proc/sys/fs/limits

Explanation

The pam_limits module reads /etc/security/limits.conf, and drop-in files in /etc/security/limits.d, to apply soft and hard limits at login. System services instead use LimitNOFILE and similar directives in their unit files.

Question 21System Management

A bad /etc/fstab entry has dropped a server into emergency mode with the root filesystem mounted read-only. Which command makes the root filesystem writable so that fstab can be repaired?

  1. chroot / /bin/bash
  2. mount -o remount,rw / Correct answer.
  3. fsck -y /
  4. systemctl isolate multi-user.target

Explanation

Remounting the already-mounted root filesystem with the rw option changes its mount flags without unmounting it, which is required before editing files in emergency mode. After the fix, a reboot or systemctl default restores normal operation.

Question 22System Management

Which combination of directives in a file under /etc/modprobe.d/ stops a module from loading even when another module requests it as a dependency?

  1. blacklist alone, since it blocks dependency loading too
  2. blacklist plus install with /bin/true Correct answer.
  3. remove plus softdep pre: none
  4. alias off plus options disabled

Explanation

A bare blacklist entry only suppresses loading by alias, so the module can still be pulled in as a dependency. Adding an install line that runs /bin/true makes modprobe silently do nothing instead of inserting the module, blocking every load path.

Question 23System Management

Which kernel command-line parameter boots the system into a single-user maintenance target for one boot only?

  1. systemd.setenv=rescue
  2. systemd.unit=rescue.target Correct answer.
  3. rd.live.ram=1
  4. grub.cfg=rescue

Explanation

The systemd.unit= parameter overrides the target that PID 1 starts, and it can be typed temporarily at the GRUB edit screen with the 'e' key. Because nothing is written to disk, the next normal boot is unaffected.

Question 24System Management

Which single command enlarges logical volume /dev/vg0/data by 10 GB and grows the filesystem on it at the same time?

  1. lvresize -l +100%FREE /dev/vg0/data && mkfs.ext4 /dev/vg0/data
  2. lvextend -L 10G /dev/vg0/data
  3. lvextend -L +10G -r /dev/vg0/data Correct answer.
  4. vgextend -L +10G vg0

Explanation

The -r option tells lvextend to invoke the appropriate filesystem resize tool (resize2fs or xfs_growfs) after the device grows. Without it, the extra space stays unused until the filesystem is resized manually.

Question 25System Management

After moving a set of RAID member disks into a new server, which command scans the system and starts the existing arrays?

  1. mdadm --assemble --scan Correct answer.
  2. mdadm --detail --scan
  3. mdadm --grow --scan
  4. mdadm --create --scan

Explanation

--assemble puts an existing array back together from its member devices, and --scan makes mdadm search all block devices for valid RAID metadata. The output of --detail --scan is then used to build /etc/mdadm.conf so assembly happens automatically at boot.

Question 26System Management

Which command both marks the nginx.service unit to start at boot and starts it immediately?

  1. systemctl start --now nginx
  2. systemctl preset nginx --start
  3. systemctl enable nginx && systemctl reload nginx
  4. systemctl enable --now nginx Correct answer.

Explanation

The enable subcommand creates the WantedBy symlinks that pull the unit in at boot, and the --now switch adds an immediate start in the same invocation. Running enable and start as two separate commands produces the same result.

Question 27System Management

Which apt command removes packages that were pulled in as dependencies and are no longer required by any installed package?

  1. apt autoremove Correct answer.
  2. apt purge
  3. apt clean
  4. apt --fix-broken install

Explanation

autoremove deletes packages that were installed automatically as dependencies and are now orphaned because nothing installed depends on them. The list of automatic packages is tracked in the extended_states database.

Question 28System Management

A swap file /swapfile has just been created and initialized with mkswap. Which command activates it for the current running system?

  1. systemctl enable swapfile
  2. swapon /swapfile Correct answer.
  3. swapoff /swapfile
  4. mount -a

Explanation

swapon hands the prepared swap area to the kernel so it can be used immediately. Making the swap survive a reboot requires an fstab entry of type swap, not just activation.

Question 29System Management

Which command creates a volume group named vg0 using the physical volume /dev/sdb1?

  1. vgcreate vg0 /dev/sdb1 Correct answer.
  2. vgcreate /dev/sdb1 vg0
  3. lvcreate vg0 /dev/sdb1
  4. pvcreate vg0 /dev/sdb1 --force

Explanation

vgcreate takes the volume group name first and then one or more physical volumes that already carry LVM metadata. The PV must therefore be initialized with pvcreate beforehand.

Question 30System Management

Which command lists the kernel modules that are currently loaded in the running kernel?

  1. modinfo
  2. depmod
  3. insmod
  4. lsmod Correct answer.

Explanation

lsmod reads /proc/modules and prints each loaded module together with its size and the modules that use it. It performs no loading or unloading of its own.

Question 31System Management

Which command reports the default target that the system starts on the next boot?

  1. systemctl get-default Correct answer.
  2. systemctl list-targets
  3. systemctl isolate default
  4. runlevel --default

Explanation

get-default reads the default.target symlink and prints the target it resolves to, such as multi-user.target or graphical.target. That target determines which units are started during boot.

Question 32System Management

An administrator wants to guarantee that cups.service can never be started, not even as a dependency of another unit. Which command accomplishes this?

  1. systemctl stop cups
  2. systemctl disable cups
  3. systemctl mask cups Correct answer.
  4. systemctl preset cups

Explanation

mask replaces the unit's name with a symlink to /dev/null, so any attempt to start it, including as a dependency, fails. Disabling alone only removes the boot-time symlinks and still allows manual or dependency-driven starts.

Question 33System Management

Which command displays the journal entries that were recorded during the boot before the current one?

  1. journalctl -p err
  2. journalctl -f
  3. journalctl -b -1 Correct answer.
  4. journalctl --since yesterday

Explanation

The -b switch selects a boot by relative offset, where -b 0 is the current boot and -b -1 is the immediately preceding one. The offset is only meaningful when journal data from earlier boots has been retained.

Question 34System Management

Which file is created to hold the local override when an administrator runs systemctl edit backup.service?

  1. /etc/systemd/system/backup.service
  2. /etc/systemd/override.d/backup.service.conf
  3. /etc/systemd/system/backup.service.d/override.conf Correct answer.
  4. /usr/lib/systemd/system/backup.service.d/local-override.conf

Explanation

systemctl edit creates a drop-in directory under /etc/systemd/system named after the unit with a .d suffix, and writes override.conf inside it. Drop-ins in /etc take precedence and do not require editing the vendor-supplied unit file.

Question 35System Management

Which command prints the UUID and filesystem type of the block device /dev/sda1?

  1. df -T /dev/sda1
  2. fdisk -l /dev/sda1
  3. parted /dev/sda1 print
  4. blkid /dev/sda1 Correct answer.

Explanation

blkid reads the superblock of a device and reports its UUID, label, and filesystem type. That UUID is commonly placed in /etc/fstab so the mount does not depend on device naming.

Question 36System Management

A member disk /dev/sdc1 of the array /dev/md0 is misbehaving and must be ejected from the array so a rebuild can begin with a replacement. Which command marks it as faulty?

  1. mdadm --fail /dev/md0 /dev/sdc1 Correct answer.
  2. mdadm --zero-superblock /dev/md0 /dev/sdc1
  3. mdadm --stop /dev/md0 /dev/sdc1
  4. mdadm --remove /dev/md0 /dev/sdc1

Explanation

The --fail operation flags a member device as faulty, which causes the array to drop it from the active set so a spare can take over. The device usually still has to be removed afterward before physical replacement.

Question 37System Management

A process with PID 4321 currently has a nice value of 0. Which command changes it to a nice value of 10, giving it less CPU preference?

  1. renice -n -10 -p 4321
  2. renice -n 10 -p 4321 Correct answer.
  3. nice 10 -p 4321
  4. chrt 10 -p 4321

Explanation

renice adjusts the niceness of an already running process, and -p identifies it by PID. Larger nice values mean lower scheduling priority.

Question 38System Management

Which signal should be sent to a process so that it can perform an orderly shutdown and save its state before exiting?

  1. SIGKILL
  2. SIGSTOP
  3. SIGTERM Correct answer.
  4. SIGHUP

Explanation

SIGTERM (15) requests termination and can be caught or handled by the process, which allows cleanup. It is the default signal sent by the kill command when none is specified.

Question 39System Management

Which directive in /etc/default/grub supplies extra kernel arguments that are appended to every boot entry?

  1. GRUB_TIMEOUT_STYLE="hidden"
  2. GRUB_DEFAULT
  3. GRUB_CMDLINE_LINUX Correct answer.
  4. GRUB_DISTRIBUTOR

Explanation

GRUB_CMDLINE_LINUX holds kernel parameters such as console settings that the GRUB tools add to each generated menu entry. The grub.cfg file must be regenerated afterwards for the change to take effect.

Question 40System Management

Within a logrotate configuration stanza, which directive sets how many older rotated copies of a log file are retained before the oldest is deleted?

  1. missingok
  2. daily
  3. create
  4. rotate Correct answer.

Explanation

The rotate directive takes a number and defines how many rotated generations are kept; older files beyond that count are removed. Rotation frequency and file creation are controlled by separate directives.

Question 41System Management

Which command schedules the script /usr/local/bin/report.sh to run once at 22:00 tonight?

  1. crontab 22:00 -f /usr/local/bin/report.sh
  2. atq 22:00 -f /usr/local/bin/report.sh
  3. batch 22:00 -f /usr/local/bin/report.sh
  4. at 22:00 -f /usr/local/bin/report.sh Correct answer.

Explanation

The at command queues a one-time job for a specified time, and -f reads the commands to run from the named file. The job must be permitted by /etc/at.allow or /etc/at.deny and requires the atd service to be running.

Question 42System Management

An administrator suspects a unit failed while the system was booting. Which command lists the units that are currently in a failed state?

  1. systemctl --all
  2. journalctl --failed
  3. systemctl list-jobs
  4. systemctl --failed Correct answer.

Explanation

The --failed switch filters systemctl output down to units whose state is failed, which is the quickest way to spot a service that did not come up. The underlying state can then be investigated with journalctl for that unit.

Question 43System Management

A kernel module exposes a tunable parameter that may be changed while it is loaded. Which path exposes the current value of that parameter in the running system?

  1. /proc/modules/<module>/<param>
  2. /sys/module/<module>/parameters/<param> Correct answer.
  3. /lib/modules/$(uname -r)/<module>/<param>
  4. /etc/modules-load.d/<module>.conf

Explanation

Loaded modules are represented in sysfs, and each writable parameter appears as a file under /sys/module/<module>/parameters. Writing to such a file changes the value only until the module is unloaded or the system reboots.

Question 44System Management

Which command shows how much time each service took to initialize during the most recent boot?

  1. journalctl --list-boots --unit=*
  2. systemd-analyze blame Correct answer.
  3. systemctl list-dependencies --after
  4. systemd-analyze critical-chain

Explanation

systemd-analyze blame prints units sorted by the time they consumed during startup, which points at the slowest services. The critical-chain view instead shows the dependency path that determined total boot time.

Question 45System Management

The command umount /data fails with the message that the target is busy. Which command identifies the processes that hold files open there?

  1. ps aux | grep /data
  2. du -sh /data
  3. fuser -vm /data Correct answer.
  4. stat /data

Explanation

fuser with -m reports every process that has a file open on the named mount point, and the verbose switch shows the user and access type. The offenders can then be closed or terminated so the unmount can succeed.

Question 46System Management

A volume group vg0 was discovered after disks were moved from another server, but its logical volumes are not active. Which command activates every logical volume in vg0?

  1. lvchange -ay vg0
  2. vgchange -ay vg0 Correct answer.
  3. vgchange -an vg0
  4. vgcfgrestore vg0

Explanation

vgchange with -a y sets the activation flag for all logical volumes belonging to the named volume group, making their device nodes usable. Activation state is what distinguishes visible metadata from mounted-capable devices.

Question 47Services and User Management

Which command configures a systemd unit to start automatically during boot without starting it right now?

  1. systemctl enable nginx.service Correct answer.
  2. systemctl start nginx.service
  3. systemctl reload nginx.service
  4. systemctl enable --now nginx.service

Explanation

systemctl enable creates the symlinks that pull the unit in at boot but leaves the unit's current runtime state untouched. Adding --now would also start (or restart) the unit immediately. Starting the unit alone does not make it persistent across reboots.

Question 48Services and User Management

Which file stores the UID, primary GID, home directory, and login shell for each local account?

  1. /etc/login.defs
  2. /etc/passwd Correct answer.
  3. /etc/shadow
  4. /etc/group

Explanation

/etc/passwd is the world-readable account database with seven colon-separated fields per line. /etc/shadow holds the password hash and aging data, and /etc/group maps group names to members.

Question 49Services and User Management

Which command removes the account mike along with its home directory and mail spool?

  1. userdel -r mike Correct answer.
  2. userdel mike
  3. userdel -f mike
  4. deluser mike

Explanation

The -r option tells userdel to delete the home directory and mail spool in addition to the account entry. A plain userdel removes only the passwd, shadow, and group entries, leaving files behind.

Question 50Services and User Management

Which systemd target corresponds most closely to the traditional SysV runlevel 3 state of networking with a text console?

  1. multi-user.target Correct answer.
  2. rescue.target
  3. poweroff.target
  4. graphical.target

Explanation

multi-user.target brings up a full multi-user system with networking but without a display manager, mirroring runlevel 3. graphical.target adds the display manager and corresponds to runlevel 5.