Interview Prep/Shell Scripting/Arrays, conditionals and loops

List the most-used file test operators.

BeginnerConceptArrays, conditionals and loops
Answer
Test True if
-e f exists (any type)
-f f regular file
-d f directory
-L f / -h f symlink
-s f exists and size > 0
-r / -w / -x f readable / writable / executable by you
f1 -nt f2 f1 newer than f2 (mtime)
-S f / -p f socket / named pipe
[[ -s /var/backups/latest.tar.gz ]] || die "backup missing or empty"
[[ -x /usr/local/bin/aws ]] || die "aws CLI not installed"

-e follows symlinks, so a broken symlink fails -e but passes -L.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arrays, conditionals and loops