-
-
Notifications
You must be signed in to change notification settings - Fork 1
Linux test Guide
Mattscreative edited this page Dec 5, 2025
·
2 revisions
Complete beginner-friendly guide to test on Linux, covering Arch Linux, CachyOS, and other distributions including conditional testing, file checks, and script logic.
Basic usage:
# Test if file exists
test -f file.txt && echo "File exists"
# -f = file (regular file)Alternative syntax:
# Using [ ] brackets
[ -f file.txt ] && echo "File exists"
# [ ] is equivalent to testDifferent checks:
# Regular file
test -f file.txt
# Directory
test -d directory/
# File exists (any type)
test -e file.txtPermission checks:
# Readable
test -r file.txt
# Writable
test -w file.txt
# Executable
test -x file.txtCompare strings:
# Strings equal
test "string1" = "string2"
# Strings not equal
test "string1" != "string2"
# String is empty
test -z "$string"
# String is not empty
test -n "$string"Compare numbers:
# Equal
test 5 -eq 5
# Not equal
test 5 -ne 3
# Greater than
test 5 -gt 3
# Less than
test 3 -lt 5Check installation:
# test is built-in shell command
# Always available
# Check test
which testThis guide covered test usage, conditional testing, and script logic for Arch Linux, CachyOS, and other distributions.
- Bash Scripting Guide - Scripting basics
- Conditional Statements - If/else statements
-
test Documentation:
man test
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.