10 free CompTIA Linux+ XK0-006 practice questions with the correct answer and a full explanation for each, taken from the CertStash pack of 155 questions. Work through them, then open each answer to check your reasoning.
Get all 155 questions (US$39) · Download these 10 as a PDF
Question 1
A Linux administrator needs to create and then connect to the app-01-image container.
Which of the following commands accomplishes this task?
Show answer and explanation
Correct answer: A. docker run -it app-01-image
The `docker run -it app-01-image` command creates a new container from the specified image and connects to it interactively. The `-i` flag keeps STDIN open even if not attached, and `-t` allocates a pseudo-terminal, allowing the administrator to interact with the running container immediately.
Why the other options are wrong
- B. docker start is used to start an existing stopped container, not create a new one from an image.
- C. docker build is used to build images from a Dockerfile, not create or connect to containers.
- D. docker exec runs commands in an already-running container; it cannot be used to initially create and connect to a container.
Question 2
To perform a live migration, which of the following must match on both host servers? (Choose two).
Show answer and explanation

Question 3
A Linux systems administrator needs to extract the contents of a file named /home/dev/web.bkp to the /var/www/html/ directory.
Which of the following commands should the administrator use?
Show answer and explanation
Correct answer: A. cd /var/www/html/ && gzip -c /home/dev/web.bkp | tar xf –
– Only this option moves into the destination directory first and then feeds the backup file through a pipe to `tar xf -`, where `-x` extracts and `-f -` reads the archive stream from standard input, so the contents land in /var/www/html/. In practice the decompression flag is `-dc` (or zcat).
Why the other options are wrong
- B. `$$` is not a valid command separator (it should be `&&` or `;`), and cpio expects a cpio-format stream.
- C. tar `-c` creates an archive instead of extracting, and the paths are reversed for this task.
- D. unzip handles ZIP archives only, and this syntax would not extract into the target directory.
Question 4
Which of the following Ansible components contains a list of hosts and host groups?
Show answer and explanation
Correct answer: B. Inventory
An Ansible Inventory is the component that contains the list of hosts and host groups that Ansible will manage. It can be a static file (like /etc/ansible/hosts) or dynamically generated, and organizes target systems into groups for orchestration.
Why the other options are wrong
- A. Facts are system information gathered from hosts during playbook execution, not a listing of hosts themselves.
- C. Playbooks are YAML files containing tasks and plays to execute on hosts, not the inventory of hosts.
- D. Collections are organized groupings of Ansible content like roles, modules, and plugins, not host listings.
Question 5
Which of the following filesystems contains non-persistent or volatile data?
Show answer and explanation
Correct answer: C. /proc
The /proc filesystem is a virtual filesystem containing non-persistent, volatile data about running processes and kernel information. It is generated dynamically at boot and resides entirely in RAM, disappearing when the system reboots.
Why the other options are wrong
- A. /boot contains persistent kernel and bootloader files essential for system startup.
- B. /usr contains persistent user applications, libraries, and documentation.
- D. /var contains persistent variable data like logs, mail, and databases, though some subdirectories may have volatile content.
Question 6
An administrator needs to verify the user ID, home directory, and assigned shell for the user named “accounting.”
Which of the following commands should the administrator use to retrieve this information?
Show answer and explanation
Correct answer: A. qetent passwd accounting
The `getent passwd accounting` command (note: the question shows 'qetent' which appears to be a typo for 'getent') retrieves user information from the passwd database, displaying the user ID (UID), home directory, and assigned shell for the specified user in a single output line.
Why the other options are wrong
- B. The `id` command displays UID, GID, and group memberships, but not the home directory or shell information.
- C. The /etc/shadow file contains password hashes and expiration information, not user ID, home directory, or shell assignments.
- D. The `who` command shows currently logged-in users, not detailed user account configuration like UID, home directory, or shell.
Question 7
A Linux user needs to download the latest Debian image from a Docker repository.
Which of the following commands makes this task possible?
Show answer and explanation
Correct answer: B. docker image pull Debian
The `docker image pull Debian` command downloads the latest Debian image from the default Docker repository (Docker Hub) to the local system. The `pull` subcommand is the correct operation for fetching images from remote repositories.
Why the other options are wrong
- A. docker image init is not a valid Docker command for downloading images.
- C. docker image import is used to import images from tar archives or containers, not to pull from repositories.
- D. docker image save exports existing local images to tar files; it does not download images from repositories.
Question 8
In the echo "profile-$num-$name" line of a shell script, the variable $num seems to not be expanding during execution.
Which of the following notations ensures the value is expanded?
Show answer and explanation
Correct answer: D. echo "profile-${num}-$name"
The `${num}` notation uses braces to explicitly delimit the variable name, ensuring proper expansion even when followed by characters that could be mistaken as part of the variable name. This is the correct fix when variable expansion is not working as expected in double-quoted strings.
Why the other options are wrong
- A. $(num) is command substitution; it runs a command named num rather than expanding the variable.
- B. Single quotes suppress expansion, so the literal text $num is printed.
- C. The stray quote characters make the text literal instead of expanding the variable.
Question 9
A systems administrator wants to review the logs from an Apache 2 error.log file in real time and save the information to another file for later review.
Which of the following commands should the administrator use?
Show answer and explanation
Correct answer: D. tail -f /var/log/apache2/error.log | tee logfile.txt
The `tee` command reads from stdin and writes to both stdout and a file simultaneously, allowing real-time viewing while saving to a file. Option A uses `>` which overwrites and doesn't display in real-time. Option B uses a pipe to a filename which is invalid syntax. Option C uses `>>` which appends but doesn't display output in real-time to the terminal.
Why the other options are wrong
- A. The `>` operator redirects only to file without displaying output to the terminal in rea-ime.
- B. Piping to a filename is invalid syntax; a command must follow the pipe operator.
- C. The `>>` operator appends to file but doesn't display the output on the terminal simultaneously.
Question 10
Which of the following describes the method of consolidating system events to a single location?
Show answer and explanation
Correct answer: A. Log aggregation
Log aggregation is the practice of collecting and consolidating system logs from multiple sources into a single centralized location for easier monitoring and analysis. Health checks monitor system status but don't consolidate logs. Webhooks are event-driven notifications. Threshold monitoring alerts when metrics exceed set limits.
Why the other options are wrong
- B. Health checks verify system availability and status but don't consolidate logs to a single location.
- C. Webhooks are callbacks for event notifications, not log consolidation mechanisms.
- D. Threshold monitoring alerts when values exceed limits but is not about consolidating system events.
That was 10 of 155.
The full CompTIA Linux+ XK0-006 pack has all 155 questions, each with the answer, the explanation and why the other options are wrong, plus a questions-only copy for timed runs. US$39, paid once, with free monthly updates and a pass-or-your-money-back guarantee.
