Bird
0
0

Which of the following is the correct syntax to check if a file report.log exists and is a regular file in bash?

easy📝 Syntax Q12 of 15
Bash Scripting - File Operations in Scripts
Which of the following is the correct syntax to check if a file report.log exists and is a regular file in bash?
Aif [ -d report.log ]; then echo "Exists"; fi
Bif [ -f report.log ]; then echo "Exists"; fi
Cif [ -e report.log ]; then echo "Exists"; fi
Dif test -x report.log; then echo "Exists"; fi
Step-by-Step Solution
Solution:
  1. Step 1: Identify the test for regular file

    The -f option checks if the file exists and is a regular file (not directory).
  2. Step 2: Confirm the syntax

    The syntax if [ -f report.log ]; then ... fi correctly checks for a regular file.
  3. Final Answer:

    if [ -f report.log ]; then echo "Exists"; fi -> Option B
  4. Quick Check:

    -f checks regular file existence [OK]
Quick Trick: Use [ -f filename ] to check regular file existence [OK]
Common Mistakes:
MISTAKES
  • Using -d which checks for directories
  • Using -x which checks for executable permission
  • Confusing -e (exists) with -f (regular file)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes