Skip to content

Linux test Guide

Mattscreative edited this page Dec 5, 2025 · 2 revisions

Linux test Guide

Complete beginner-friendly guide to test on Linux, covering Arch Linux, CachyOS, and other distributions including conditional testing, file checks, and script logic.


Table of Contents

  1. test Basics
  2. File Tests
  3. String Tests
  4. Numeric Tests
  5. Troubleshooting

test Basics

File Exists

Basic usage:

# Test if file exists
test -f file.txt && echo "File exists"

# -f = file (regular file)

Using Brackets

Alternative syntax:

# Using [ ] brackets
[ -f file.txt ] && echo "File exists"

# [ ] is equivalent to test

File Tests

File Types

Different checks:

# Regular file
test -f file.txt

# Directory
test -d directory/

# File exists (any type)
test -e file.txt

File Permissions

Permission checks:

# Readable
test -r file.txt

# Writable
test -w file.txt

# Executable
test -x file.txt

String Tests

String Comparison

Compare 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"

Numeric Tests

Number Comparison

Compare numbers:

# Equal
test 5 -eq 5

# Not equal
test 5 -ne 3

# Greater than
test 5 -gt 3

# Less than
test 3 -lt 5

Troubleshooting

test Not Found

Check installation:

# test is built-in shell command
# Always available

# Check test
which test

Summary

This guide covered test usage, conditional testing, and script logic for Arch Linux, CachyOS, and other distributions.


Next Steps


This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.

Clone this wiki locally