Sign in
Home/CompTIA/CompTIA Linux+ (XK0-006)/Free questions

CompTIA Linux+ (XK0-006) — Free Practice Questions

10 free sample questions from a bank of 401, with the correct answers and explanations. No signup required — start practising right now.

1A Linux administrator needs to create and then connect to the app-01-image container. Which of the following commands accomplishes this task?
  • docker run -it app-01-image
  • docker start -td app-01-image
  • docker build -ic app-01-image
  • docker exec -dc app-01-image
Answer: A

The short version

A — Docker run minus it creates and connects. Run pulls the image if needed, creates a container and attaches an interactive terminal in one step. Start, build and exec each assume a different prior state.

Key concepts in this question

  • Run versus start: run creates plus starts, start only starts an existing stopped container.
  • Interactive terminal flags: minus i keeps stdin open, minus t allocates a pseudo TTY for shell use.
  • Build and exec roles: build makes images from Dockerfiles, exec enters already running containers.
  • Task wording: create and then connect implies one command that does both.

Why A is correct

App-01-image names an image, not yet a container, so the admin must instantiate it and get a shell. Docker run minus it app-01-image performs create plus start plus attach with terminal handling. Other verbs either miss creation or miss connection.

Why the others are wrong

  • B. Start resumes an existing container and uses detached flags that do not attach interactively.
  • C. Build compiles a Dockerfile into an image and never connects to a shell.
  • D. Exec attaches to an already running container and cannot create from an image.

XK0-006 exam tip

Create plus connect to an image always means docker run minus it, not start or exec.

2To perform a live migration, which of the following must match on both host servers? (Choose two).
  • USB ports
  • Network speed
  • Available swap
  • CPU architecture
  • Available memory
  • Disk storage path
Answer: D, F

The short version

DF — CPU architecture plus disk path must match. Live migration moves running memory and device state between hosts, so instruction set and backing storage location must align. USB, speed, swap and memory size do not gate compatibility.

Key concepts in this question

  • Live migration needs: move a running guest with no downtime across two hypervisors.
  • CPU architecture match: same vendor generation and flags so paused vCPU state resumes cleanly.
  • Storage path match: shared or identical disk path so both hosts see the same virtual disks.
  • Non-gating facts: port counts, link speed and free memory affect performance, not state resume.

Why DF is correct

Hypervisors check that the destination can interpret the exact CPU context and reach the same disk files before allowing live move. Matching architecture plus matching storage path satisfies both resume conditions. Other pairs leave either execution or disk access incompatible.

Why the others are wrong

  • A. USB port presence has no bearing on guest CPU or disk continuity.
  • B. Network speed affects copy time, not migration correctness.
  • C. Swap size is host tuning, not guest state compatibility.
  • E. Available memory varies dynamically and is not a fixed match requirement here.

XK0-006 exam tip

Live migration match pair to memorize is CPU arch plus disk storage path.

3A 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?
  • cd /var/www/html/ && gzip -c /home/dev/web.bkp | tar xf -
  • pushd /var/www/html/ $$ cpio -idv < /home/dev/web.bkp && popd
  • tar -c -f /home/dev/web.bkp /var/www/html/
  • unzip -c /home/dev/web.bkp /var/www/html/
Answer: A

The short version

A — Cd plus gzip plus tar extracts to target dir. Changing to html then piping decompressed archive into tar extract places web files correctly. Cpio, create and unzip forms misuse direction or tools.

Key concepts in this question

  • Archive flow: web dot bkp is compressed tar content needing decompress plus extract.
  • Target directory control: cd first ensures relative extract lands under html for serving.
  • Gzip minus c plus tar xf: decompress to stdout then read archive from stdin for extraction.
  • Shell chaining: double ampersand plus pipe sequence controls order and data flow safely.
  • Wrong verbs: cpio syntax, tar create and unzip do not match the needed extract path.

Why A is correct

Option A moves to the destination, streams the backup through gzip decompress, and feeds tar extract from stdin. That writes the archived tree into the current html directory as required. Other options either create archives or use the wrong extractor for this tar-gzip format.

Why the others are wrong

  • B. Cpio with pushd grammar does not parse the tar-gzip backup as intended.
  • C. Tar minus c minus f creates an archive from html instead of extracting into it.
  • D. Unzip targets zip files and flags, not a tar backup stream.

XK0-006 exam tip

Extract compressed backup to a dir means cd there then gzip minus c pipe tar xf minus.

4Which of the following Ansible components contains a list of hosts and host groups?
  • Fact
  • Inventory
  • Playbook
  • Collection
Answer: B

The short version

B — Inventory holds hosts and groups. Ansible inventory lists managed nodes plus group membership for play targeting. Facts, playbooks and collections serve variables, tasks or packaging instead.

Key concepts in this question

  • Inventory role: static or dynamic source of hostnames plus group hierarchy.
  • Playbook contrast: YAML tasks that run against inventory-selected hosts.
  • Fact contrast: discovered variables about a host, not the host roster itself.
  • Collection contrast: packaged roles plus modules for reuse, not host lists.
  • Targeting flow: plays select inventory groups before tasks execute on those nodes.

Why B is correct

Ansible must know which machines exist and how they group before it can run anything. That roster lives in inventory files or scripts. Other components consume that list but never define the host set themselves, so inventory is the only correct answer.

Why the others are wrong

  • A. Fact records discovered host details during a run, not the managed roster.
  • C. Playbook defines desired actions and targets groups, but needs inventory first.
  • D. Collection bundles content for sharing, never host membership.

XK0-006 exam tip

Hosts and host groups in Ansible always means Inventory, playbook means tasks.

5Which of the following filesystems contains non-persistent or volatile data?
  • /boot
  • /usr
  • /proc
  • /var
Answer: C

The short version

C — Proc holds volatile kernel data. Proc is a virtual filesystem exposing process plus kernel state that vanishes on reboot. Boot, usr and var persist on disk across restarts by design.

Key concepts in this question

  • Volatile meaning: contents exist in memory and regenerate each boot rather than on disk.
  • Proc contents: PID dirs, meminfo, cpuinfo and tunables reflecting live state.
  • Pseudo filesystem behavior: reads query kernel structures, writes tune live parameters immediately.
  • Persistent peers: boot loader, user programs and variable spools survive reboots.
  • Exam contrast: pick the pseudo filesystem, skip real on-disk trees every time.

Why C is correct

Proc is mounted as a kernel interface, not block storage, so reads reflect current memory structures. Power loss clears it by design. Other paths live on persistent volumes and retain files, so only proc matches volatile.

Why the others are wrong

  • A. Boot stores kernels and loader files that must persist for next start.
  • B. Usr holds installed programs and libraries kept on disk.
  • D. Var spools logs and mail that persist by intent.

XK0-006 exam tip

Volatile or non-persistent filesystem always means proc, never var or usr. Proc entries reflect live kernel tables, so they reset on reboot while disk-backed paths retain data across restarts.

6An 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?
  • qetent passwd accounting
  • id accounting
  • grep accounting /etc/shadow
  • who accounting
Answer: A

The short version

A — Getent passwd shows ID plus home plus shell. The passwd database entry for accounting contains UID, GID, home and login shell in one line. Id, shadow grep and who each miss at least one field.

Key concepts in this question

  • Required triple: numeric user ID, home directory path and assigned shell.
  • Passwd database line: name plus UID plus GID plus home plus shell from Name Service Switch.
  • NSS coverage: getent consults files plus directory services, not just local files alone.
  • Id and who limits: id shows IDs and groups, who shows logins, neither shows home plus shell fully.
  • Shadow limit: holds hashes readable only by root, not the requested triple.

Why A is correct

Querying the passwd map for accounting returns the full account record with all three facts together. That single lookup satisfies the stem without combining tools. Other commands omit home, shell or both while adding unneeded data, so A is uniquely complete.

Why the others are wrong

  • B. Id reports UID plus groups but omits home directory and login shell.
  • C. Shadow grep exposes hashes without home plus shell and needs root.
  • D. Who lists logged-in sessions, not account database details.

XK0-006 exam tip

ID plus home plus shell in one query always means getent passwd user.

7A Linux user needs to download the latest Debian image from a Docker repository. Which of the following commands makes this task possible?
  • docker image init debian
  • docker image pull Debian
  • docker image import debian
  • docker image save debian
Answer: B

The short version

B — Docker image pull fetches Debian. Pull downloads the latest tagged layers from the configured registry to local storage. Init, import and save handle other image lifecycle steps.

Key concepts in this question

  • Download task: bring remote repository image down for later run or build use.
  • Pull semantics: contact registry, resolve tag, fetch missing layers incrementally.
  • Tag latest behavior: without explicit tag, pull resolves to latest stable Debian layers.
  • Import versus save: import makes an image from a tarball, save exports one to a tarball.
  • Init distractor: no standard pull replacement for fetching images exists.

Why B is correct

The user needs the latest Debian image locally from Docker Hub or a mirror. Image pull is the documented fetch operation for that goal. Other verbs either create from files or export outward rather than download, so pull is the only match.

Why the others are wrong

  • A. Image init is not the fetch verb and will not download repository layers.
  • C. Image import builds from a local archive, not from a registry pull.
  • D. Image save writes a local image out, opposite to downloading.

XK0-006 exam tip

Download image from a repository always means docker image pull. Registry pull resolves tags and fetches missing layers, so local run commands work offline after the download completes.

8In 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?
  • echo "profile-$(num)-$name"
  • echo 'profile-$num-$name'
  • echo "profile-‘Snum‘-$name"
  • echo "profile-${num}-$name"
Answer: D

The short version

D — Braced num separates name from suffix. Profile dash dollar num dash dollar name parses num plus literal dash without braces ambiguity. Braces delimit num so the trailing dash is not taken as part of the name.

Key concepts in this question

  • Shell expansion greed: dollar name consumes longest valid identifier after dollar.
  • Brace isolation: dollar brace num brace ends the variable exactly before surrounding text.
  • Quote effects: double quotes still expand, single quotes suppress, subshell forms do not fix names.
  • Symptom clue: num appears unexpanded because dash merges into a longer bogus name.

Why D is correct

Without braces the shell looks for a variable named num-dash-something instead of num alone. Wrapping as dollar brace num brace forces expansion of num then literal dash then name. Only option D applies that standard brace fix inside double quotes.

Why the others are wrong

  • A. Dollar paren form runs command substitution for num, not variable expansion.
  • B. Single quotes suppress all expansion, so neither variable would expand.
  • C. Backtick style with Snum mangles the name and never isolates num correctly.

XK0-006 exam tip

Variable glued to dash or text always needs braces, use dollar brace var brace.

9A 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?
  • tail -f /var/log/apache2/error.log > logfile.txt
  • tail -f /var/log/apache2/error.log | logfile.txt
  • tail -f /var/log/apache2/error.log >> logfile.txt
  • tail -f /var/log/apache2/error.log | tee logfile.txt
Answer: D

The short version

D — Tee watches live while saving to file. Tail minus f follows error dot log, pipe to tee copies the stream to screen plus logfile. Single redirect hides live view, double redirect and bare pipe misuse the sink.

Key concepts in this question

  • Follow mode: tail minus f emits new log lines as Apache writes them.
  • Tee behavior: duplicates stdin to stdout plus named files for watch plus archive.
  • Append versus truncate: greater-than truncates, double greater appends, tee preserves live display in both cases.
  • Redirect limits: greater-than hides display, double greater still hides display without tee.
  • Pipe need: logfile dot txt is a file, not a command, so bare pipe fails.

Why D is correct

The admin must both review in real time and keep a copy for later analysis. Piping the followed stream into tee satisfies both at once by displaying and writing simultaneously. Other forms either lose the live view or fail to write correctly to the file.

Why the others are wrong

  • A. Single redirect saves but shows nothing live on the terminal.
  • B. Piping to a filename tries to execute a file as a command and fails.
  • C. Double redirect appends correctly yet still hides the real-time display.

XK0-006 exam tip

Follow plus see plus save always means tail minus f pipe tee file.

10Which of the following describes the method of consolidating system events to a single location?
  • Log aggregation
  • Health checks
  • Webhooks
  • Threshold monitoring
Answer: A

The short version

A — Log aggregation centralizes system events. Collecting syslog plus journal plus app logs into one searchable store enables correlation across hosts. Health checks, webhooks and thresholds monitor or notify but do not consolidate.

Key concepts in this question

  • Consolidation goal: one location for all host events to query and retain centrally.
  • Aggregation pipeline: forwarders plus indexers normalize time and host fields centrally.
  • Correlation value: single store lets analysts join web plus auth plus kernel events by timestamp.
  • Health versus threshold: liveness and alert limits evaluate state rather than gather logs.
  • Webhook role: event callback for automation, not a log store.

Why A is correct

Describing consolidation of system events to a single location is the textbook definition of log aggregation. Only aggregation ingests many sources into unified retention with search. Other options perform checks or callbacks on top of already collected data, not collection itself.

Why the others are wrong

  • B. Health checks probe service up or down without centralizing event text.
  • C. Webhooks push notifications outward instead of gathering logs inward.
  • D. Threshold monitoring alerts on metric breach rather than storing event streams.

XK0-006 exam tip

Events to a single location always means log aggregation, not monitoring.

Want the full bank of 401 questions for CompTIA Linux+ (XK0-006)? See all practice exams.