102-500 · Question #12
Which of the following comparison operators for test work on elements in the file system? (Choose two.)
The correct answer is C. -d D. -f. Options C (-d) and D (-f) are the correct answers because they operate directly on the file system: -d checks whether a given path exists and is a directory, while -f checks whether a path exists and is a regular file. Both are standard test (or [[ ]]) operators used in shell…
Question
Options
- A-z
- B-eq
- C-d
- D-f
- E-it
How the community answered
(37 responses)- A3% (1)
- B11% (4)
- C81% (30)
- E5% (2)
Explanation
Options C (-d) and D (-f) are the correct answers because they operate directly on the file system: -d checks whether a given path exists and is a directory, while -f checks whether a path exists and is a regular file. Both are standard test (or [[ ]]) operators used in shell scripts to validate filesystem entries before acting on them.
Why the distractors are wrong:
- A (
-z) is a string operator that tests whether a string has zero length - it has no awareness of the file system. - B (
-eq) is a numeric/integer comparison operator (equal) used to compare two numbers, not file paths. - E (
-it) is simply not a validtestoperator at all.
Memory tip: Think of the file system operators as starting with letters that hint at what they test - -d for directory, -f for file, -e for exists, -r/-w/-x for read/write/execute. If an operator sounds like a string or math term (-z = zero-length, -eq = equal), it's not about the file system.
Topics
Community Discussion
No community discussion yet for this question.