Bird
0
0

Which of the following is the correct syntax to check if a file is writable in bash?

easy📝 Syntax Q3 of 15
Bash Scripting - Conditionals
Which of the following is the correct syntax to check if a file is writable in bash?
A[ -x filename ]
B[ -r filename ]
C[ -w filename ]
D[ -d filename ]
Step-by-Step Solution
Solution:
  1. Step 1: Understand each operator's meaning

    -w checks if the file is writable, -x checks executable permission, -r checks readable, and -d checks if it's a directory.
  2. Step 2: Identify the syntax for writable check

    The correct syntax uses [ -w filename ] with spaces and brackets.
  3. Final Answer:

    [ -w filename ] -> Option C
  4. Quick Check:

    Writable check syntax = [ -w filename ] [OK]
Quick Trick: Use [ -w filename ] to test write permission [OK]
Common Mistakes:
MISTAKES
  • Missing spaces inside brackets
  • Using -x for writable
  • Using -d for files

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes