Learn how the `test` command makes scripts decide by checking files, strings and numbers. 14.05.2026 | reading time: 2 min When a script must decide he reaches for `test`, the small POSIX tool that checks files, strings and numbers and returns a simple exit status to steer control flow. Quick hands-on example ```sh $ touch /tmp/example.txt $ test -f /tmp/example.txt && echo 'exists' exists $ test -s /tmp/example.txt && echo 'not empty' || echo 'empty' empty $ [ 'foo' = 'foo' ] && echo 'strings equal' strings equal $ test 5 -gt 3 && echo '5 greater than 3' 5 greater than 3 $ test ! -d /tmp/nope && echo 'no directory' no directory ``` Useful operators and pitfalls `test` exposes file checks like -e -f -d -s -r -w, string checks -z -n and = !=, and numeric comparisons -eq -ne -gt -ge -lt -le; remember to quote variables to avoid word splitting and to leave spaces around the bracket when using `[` since it is a separate command, and prefer clear boolean logic over the ambiguous -a and -o operators for portable scripts. Where `test` fits in scripts Use `test` or `[` in POSIX shell scripts for portability, expect a zero exit on success and nonzero on failure, note that many shells also provide a builtin `test` and bash adds `[[` for extended syntax, and combine `test` results with if, while and conditional chaining for real decisions. Next steps and learning path Master `test` by rewriting conditional fragments in existing scripts, then move to `find` and `stat` for richer file logic; deepen skills and consider formal certification like CompTIA Linux+ or LPIC-1 and intensive exam preparation at bitsandbytes.academy to turn practiced commands into professional expertise. Join Bits & Bytes Academy First class LINUX exam preparation. utilities scripting filesystem troubleshooting