A Linux user runs the following command:
nohup ping comptia.com &
Which of the following commands should the user execute to attach the process to the current terminal?
Correct answer:
D. fg
Explanation:
The fg (foreground) command is used to move a background process into the current terminal's foreground.
Process Resumption: When a command is run with an ampersand (&), it executes in the background, allowing the user to continue using the shell.
Attaching to Terminal: Running fg without arguments will bring the most recently backgrounded job to the foreground.
Interaction: Once a process is in the foreground, it "attaches" to the terminal, meaning it will display its output directly to the screen and respond to keyboard interrupts like Ctrl+C.
Context: The nohup (no hangup) utility ensures the process continues running even if the user logs out, but fg is the specific mechanism used to bring that running process back to the active terminal session.
Explanation of Incorrect Answers renice:
This command is used to alter the scheduling priority (nice value) of an already running process. It affects how much CPU time the process receives but does not change whether the process is in the background or foreground.
jobs:
The jobs command lists the active jobs and their status (Running, Stopped, etc.) for the current shell session. While it helps you identify which job number to use with fg, it does not perform the attachment itself.
exec:
The exec command is used to replace the current shell with a new process. It does not resume or attach to an existing background process; instead, it terminates the current shell and starts the specified command in its place.
Reference
CompTIA Exam Objective: Domain 1.0 (System Management) – Subsection 1.1: "Summarize and utilize Linux command line tools" (specifically Process Management and Job Control).
Reference: Linux Man Pages (man fg, man jobs); Official CompTIA Linux+ Study Guide, Chapter on Process and Job Management.
Topic · 6 of 30 questions freeAutomation, Orchestration, and Scripting
Question 22Choose 1
A DevOps engineer needs to create a local Git repository. Which of the following commands should the
engineer use?
Correct answer:
A. git init
Explanation:
The git init command is the standard way to initialize a brand-new, empty Git repository in a local directory.
Initialization:
When you run this command, Git creates a hidden subdirectory named .git that contains all the necessary metadata and skeleton files for version control tracking.
Local Workflow:
This is specifically used when starting a project from scratch on a local machine rather than downloading an existing project from a server.
Explanation of Incorrect Answers
git clone:
This command is used to copy an existing repository from a remote source (like GitHub or GitLab) to your local machine. While it results in a local repository, it is used for pre-existing projects rather than creating a new one from a local folder.
git config:
This utility is used to set configuration options, such as your username, email address, or editor preferences. It does not create or initialize a repository; it merely defines how Git behaves on your system.
git add:
The add command moves changes from the working directory to the staging area. You cannot use git add until a repository has already been initialized with git init or git clone.
Reference:
CompTIA Exam Objective: Domain 3.0 (Scripting, Containers, and Automation) – Subsection 3.3: "Explain version control concepts using Git."
Reference: Pro Git Book (Chacon & Straub); Official CompTIA Linux+ Study Guide, Chapter on Automation and Orchestration.
Question 23Choose 1
A DevOps engineer made some changes to files in a local repository. The engineer realizes that the changes
broke the application and the changes need to be reverted back. Which of the following commands is the best
way to accomplish this task?
Correct answer:
B. git reset
Explanation:
The engineer wants to revert changes made in a local repository because they broke the application.
The command best suited for undoing local changes and returning the repository to a previous state is: git reset
What git reset does:
Moves the current branch (HEAD) back to a previous commit.
Can unstage files or completely discard changes depending on options.
Common usage:
git reset --hard HEAD
or
git reset --hard
This restores files to a known working state.
Why the Other Options Are Incorrect
❌ git pull
Fetches and merges changes from a remote repository.
Does not undo local changes.
❌ git rebase
Rewrites commit history to apply commits onto another base.
Not intended for reverting broken local changes.
❌ git stash
Temporarily saves changes for later use.
Does not revert repository back to a working version.
Linux+ XK0-006 Exam Tip
Quick Git recovery mapping:
Situation → Command
Undo local commits/changes → git reset ✅
Temporarily save work → git stash
Update from remote → git pull
Rewrite commit history → git rebase
Exam Keyword Trigger:
If you see “revert local changes” → think git reset.
Question 24Choose 1
Which of the following most accurately describes a webhook?
Correct answer:
D. An HTTP-based callback function
Explanation:
A webhook is a mechanism that allows one system to automatically send data to another system when a specific event occurs, using an HTTP request.
Instead of polling for updates, the receiving system is notified immediately.
How it works:
* Event occurs (e.g., Git push, CI/CD build completion).
* Source system sends an HTTP POST request to a predefined URL.
* Destination system processes the event data.
Example uses:
* GitHub notifying a CI/CD pipeline
* Payment systems notifying apps of transactions
* Monitoring tools sending alerts
❌ Why the Other Options Are Incorrect ❌ Authentication method for web-server communication
Webhooks may use authentication, but they are not an authentication method themselves.
❌ SNMP-based API
SNMP is used for network monitoring, unrelated to webhooks.
❌ Means to transmit sensitive information
Webhooks transmit event data, not specifically sensitive information.
Security depends on implementation.
🧠 Linux+ XK0-006 Exam Tip Key distinction:
Term Behavior
API polling Client repeatedly asks for updates
Webhook Server pushes event via HTTP ✅
💡 Exam keyword trigger:
If you see event-driven HTTP notification, think webhook.
Question 25Choose 1
Which of the following describes PEP 8?
Correct answer:
A. The style guide for Python code
Explanation:
PEP 8 (Python Enhancement Proposal 8) is the primary document that provides guidelines and best practices on how to write Python code.
Consistency and Readability:
The core philosophy is that "code is read much more often than it is written". PEP 8 ensures that code written by different developers looks consistent and is easy for others to maintain.
Key Guidelines:
It covers various formatting rules, including:
- Indentation: Use 4 spaces per indentation level.
- Line Length: Limit all lines to a maximum of 79 characters.
- Naming Conventions: Using snake_case for function and variable names, and PascalCase for classes.
- Whitespace: Proper use of spaces around operators and after commas.
Explanation of Incorrect Answers Python virtual environments: This refers to tools like venv or virtualenv, which allow developers to create isolated environments for different projects to avoid dependency conflicts. While PEPs exist for virtual environments (like PEP 405), PEP 8 is strictly about coding style.
A package installer for Python: The standard package installer for Python is pip. It is used to install and manage additional libraries from the Python Package Index (PyPI).
A Python variable holding octal values: In Python, octal values are represented by prefixing a number with 0o (zero and the letter "o"), such as 0o10. PEP 8 is a documentation standard, not a data type or variable.
Reference
CompTIA Exam Objective: Domain 3.0 (Scripting, Containers, and Automation) – Subsection 3.1: "Identify scripting languages and their common features" (specifically Python syntax and best practices).
Reference: Python Enhancement Proposal 8 (PEP 8) – "Style Guide for Python Code"; Official CompTIA Linux+ Study Guide, Chapter on Scripting and Automation.
Question 26Choose 1
Which of the following Ansible components contains a list of hosts and host groups?
Correct answer:
B. Inventory
Explanation:
In Ansible, the inventory is the component that contains the list of hosts and host groups that Ansible manages.
The inventory can be defined in:
- A static file (commonly /etc/ansible/hosts)
- A dynamic inventory script or plugin (pulling hosts from cloud providers, CMDBs, etc.)
Hosts can be grouped into logical collections (e.g., webservers, dbservers) for targeted playbook execution.
❌ Why the Other Options Are Wrong
Fact: Facts are variables collected from hosts at runtime (e.g., OS version, IP address).
Playbook: Playbooks define tasks, roles, and configurations to apply to hosts, not the host list itself.
Collection: Collections are bundles of Ansible content (roles, modules, plugins), not host definitions.
👉 So the Ansible component that contains a list of hosts and host groups is: Inventory
Question 27Choose 1
Which of the following is a characteristic of Python 3?
Correct answer:
B. It is extensible through modules.
Explanation:
Extensibility is one of Python’s core strengths and a primary reason for its popularity in system administration and automation.
Standard Library and Beyond: Python comes with a large "standard library" of pre-written code, but its true power lies in the ability to import external modules or packages.
Modular Architecture: Administrators can extend Python's functionality to perform specialized tasks—such as interacting with cloud APIs, managing databases, or parsing complex logs—by installing modules using tools like pip.
Code Reusability: This modularity allows developers to use existing, well-tested code instead of writing every function from scratch, which speeds up the development of automation scripts.
Explanation of Incorrect Answers
It is closed source:
Python is an open-source language managed by the Python Software Foundation (PSF). Its source code is freely available for anyone to inspect, modify, and distribute.
It is fully backwards compatible:
This is famously incorrect. One of the defining characteristics of Python 3 was that it was intentionally not fully backwards compatible with Python 2. This "clean break" was designed to fix inherent flaws in the language's design, which necessitated the long migration period known to many Linux administrators.
It is binary compatible with Java:
Python and Java are fundamentally different languages with different runtimes (Python uses an interpreter/bytecode VM, Java uses the JVM). While tools like Jython exist to run Python on the JVM, Python 3 itself is not "binary compatible" with Java.
Reference
CompTIA Exam Objective: Domain 3.0 (Scripting, Containers, and Automation) – Subsection 3.1: "Identify scripting languages and their common features".
Reference: Official CompTIA Linux+ Study Guide, Chapter on Scripting and Automation; Python.org Documentation.
Topic · 1 of 2 questions freeUser and Group Management
Question 28Choose 1
An administrator set up a new user account called "test". However, the user is unable to change their
password. Given the following output:
Which of the following is the most likely cause of this issue?
Correct answer:
A. The SUID bit is missing on the /bin/passwd file.
Explanation:
The error message:
passwd: Authentication token manipulation error
usually indicates that the passwd binary cannot update the shadow password file because it lacks the necessary privileges.
Normally, /bin/passwd should be owned by root and have the SUID bit set (-rwsr-xr-x), allowing regular users to run it with root privileges for password changes.
In the output provided, /bin/passwd is shown as:
-rwxr-xr-x. 1 root root ...
→ Notice the missing s in the permissions. This confirms the SUID bit is not set, preventing the user test from changing their password.
Why the Other Options Are Wrong The password provided by the user "test" does not meet complexity requirements: The error would be different (e.g., "BAD PASSWORD").
The user "test" already changed the password today: The chage output shows minimum days between changes = 0, so this is not a restriction.
The password has been disabled for user "test": The account is active, and root was able to change the password successfully.
Reference:
Linux man page: man passwd → Requires SUID to update /etc/shadow.
CompTIA Linux+ XK0-006 Exam Objectives: User and Group Management (Domain: Security).
Topic · 1 of 2 questions freeStorage and Filesystems
Question 29Choose 1
An administrator added a new disk to expand the current storage. Which of the following commands should
the administrator run first to add the new disk to the LVM?
Correct answer:
C. pvcreate
Explanation:
When adding a new disk to expand LVM storage, the very first step is to initialize the disk as a Physical Volume (PV) using the pvcreate command. This prepares the disk for use in LVM by writing LVM metadata to it.
The LVM Storage Workflow:
When adding new storage to LVM, you must follow this specific order:
Step 1: pvcreate → Step 2: vgextend → Step 3: lvextend
(Initialize disk) (Add PV to VG) (Extend logical volume)
Why pvcreate must come first:
- pvcreate initializes the new disk with LVM metadata
- Writes LVM headers to the disk
- Divides the disk into physical extents
- Makes the disk recognizable as an LVM physical volume
Only after pvcreate can the disk be added to a volume group with vgextend
Finally, you can extend logical volumes with lvextend to use the new space
Example workflow:
# 1. Identify the new disk
lsblk
# Output shows /dev/sdb is the new unpartitioned disk
# 6. Resize filesystem (if needed)
sudo resize2fs /dev/my_volume_group/my_logical_volume
# or for XFS:
sudo xfs_growfs /mount/point
Why other options are incorrect:
❌ vgextend: This command adds a physical volume to a volume group. Cannot be used first because it requires an existing PV. Would fail with error: "Device /dev/sdb not found (or ignored by filtering)". Only valid AFTER pvcreate.
❌ lvextend: This command expands a logical volume. Requires free space in the volume group. Cannot be used first because the disk isn't even in LVM yet. Would fail: "Insufficient free space" (the new disk isn't available to LV).
❌ pvresize: This command resizes an existing physical volume. Used when you've expanded the underlying disk (virtual disk resize). Not for adding new disks. Would fail on a new disk: "Device /dev/sdb not found in LVM".
Complete LVM Disk Addition Process:
# Step 0: Verify new disk is detected
fdisk -l /dev/sdb
# or
lsblk
# Step 1: Create partition (optional but recommended)
fdisk /dev/sdb
# Create a single partition /dev/sdb1 with type 8e (Linux LVM)
# Step 2: Initialize as physical volume
pvcreate /dev/sdb1
# Step 3: Add to volume group
vgextend my_vg /dev/sdb1
LVM Command Summary:
Command Purpose When Used
pvcreate Initialize disk for LVM First step with new disk
pvdisplay Show PV details Verification
vgextend Add PV to volume group After pvcreate
lvextend Grow logical volume After adding space to VG
pvresize Resize existing PV After underlying disk grew
Reference:
LVM = Logical Volume Manager
PV = Physical Volume (disk or partition)
VG = Volume Group (pool of storage)
LV = Logical Volume (virtual partition)
The order is critical: PV → VG → LV
Skipping pvcreate is like trying to pour water into a bottle that doesn't exist yet
Topic · 1 of 1 questions freeScripting, Containers, and Automation
Question 30Choose 1
A systems administrator is writing a script to analyze the number of files in the directory /opt/application
/home/. Which of the following commands should the administrator use in conjunction with ls -l | to count the
files?
Correct answer:
D. wc -l
Explanation
The administrator wants to count the number of files listed by:
ls -l
To count lines of output (each file typically appears on one line), the correct command is:
ls -l | wc -l
What wc -l does:
wc = word count utility
-l = counts lines
Each line corresponds to one listed entry, giving the total file count.
❌ Why the Other Options Are Incorrect
❌ less
Pager used to scroll output.
Does not count anything.
❌ tail -f
Continuously monitors file updates.
Used for logs, not counting lines.
❌ tr -c
Translates or deletes characters.
Not used for counting entries.