XK0-006 Automation, Orchestration, and Scripting Practice Question
A system administrator is writing a Bash script that must check if a file exists and is readable. Which two test expressions can be used to achieve this? (Choose two.)
⚠ Common exam trap
The trap is assuming -f or -s implies readability; -f only checks regular-file type and -s only checks non-zero size, so neither validates the 'readable' requirement.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
-e /path/to/file
Option A, `-e /path/to/file`, is correct because the `-e` test in Bash returns true if the file exists, regardless of its type (regular file, directory, device, etc.), which satisfies the existence check. Option C, `-r /path/to/file`, is correct because the `-r` test returns true if the file exists and the current user has read permission on it, satisfying the readability check. Together, `-e` and `-r` cover the two required conditions of existence and readability. Option B, `-s`, only checks that the file exists and has a size greater than zero, so it does not verify readability. Option D, `-x`, checks for execute permission rather than read permission, so it does not meet the requirement. Option E, `-f`, only checks that the path exists and is a regular file, not that it is readable.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
-e /path/to/file
Why this is correct
The -e unary test operator returns true when the pathname resolves to an existing file or directory, regardless of type. It satisfies the existence half of the stem's requirement, letting the script confirm the file is present before attempting any read operation.
- ✗
-s /path/to/file
Why it's wrong here
-s tests whether a file exists and has a size greater than zero, so it fails for empty readable files. It is tempting because it does confirm existence, and it would be correct when the script must verify that a file is non-empty before processing its contents.
- ✓
-r /path/to/file
Why this is correct
The -r unary operator tests whether the invoking user has read permission on the pathname, returning true only when access is granted. It satisfies the readability half of the stem's requirement, complementing an existence check in the same conditional.
- ✗
-x /path/to/file
Why it's wrong here
-x tests execute permission, which is unrelated to readability and can be true or false independently. It is tempting because it is a file test operator, and it would be correct when the script must verify that a file can be executed rather than read.
- ✗
-f /path/to/file
Why it's wrong here
-f tests that the path exists and is a regular file, but says nothing about read permission. It is tempting because it is the standard existence check, and it would be correct when the script only needs to confirm a regular file is present, not that it is readable.
Go deeper
Related to this question
Learn chapter
User and Group Administration
Key term
User
A user is any person, system, or device that interacts with an IT service, resource, or identity system, typically authenticated through credentials and authorized to perform specific actions.
Key term
Bash script
A Bash script is a text file containing a sequence of commands for the Unix shell Bash, allowing users to automate repetitive tasks and streamline system administration on Linux and macOS.
About these practice questions
One of 781 original XK0-006 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official CompTIA exam blueprint
This XK0-006 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the XK0-006 exam.