0
0
Bash Scriptingscripting~5 mins

File test operators (-f, -d, -e, -r, -w, -x) in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the -f file test operator check in a bash script?
The -f operator checks if a given path is a regular file (not a directory or special file).
Click to reveal answer
beginner
How do you test if a directory exists using bash file test operators?
Use the -d operator to check if a directory exists at the given path.
Click to reveal answer
intermediate
What is the difference between -e and -f operators?
-e checks if a file or directory exists (any type), while -f checks specifically for a regular file.
Click to reveal answer
beginner
Which file test operator checks if a file is readable?
The -r operator checks if the current user has read permission on the file.
Click to reveal answer
beginner
Explain what -w and -x operators check in bash.
-w checks if the file is writable, and -x checks if the file is executable by the current user.
Click to reveal answer
Which operator would you use to check if a file exists regardless of type?
A-d
B-f
C-e
D-r
What does the -d operator test for?
AIf a directory exists
BIf a regular file exists
CIf a file is readable
DIf a file is executable
If you want to check if a file can be executed, which operator do you use?
A-r
B-w
C-f
D-x
Which operator would confirm a file is writable?
A-r
B-w
C-e
D-d
What does -f specifically check?
AFile is a regular file
BFile is a directory
CFile exists (any type)
DFile is executable
Describe how you would check if a file exists and is readable in a bash script using file test operators.
Think about testing existence first, then readability.
You got /4 concepts.
    Explain the difference between checking if a path is a directory versus a regular file using bash file test operators.
    Directories and files behave differently in scripts.
    You got /4 concepts.