Bash Test Operators Reference

Logical Operators

  • && - Logical AND
  • || - Logical OR
  • ! - Logical NOT

Integer Comparisons

Traditional numeric comparison operators:

  • -eq - Equal
  • -ne - Not equal
  • -gt - Greater than
  • -ge - Greater than or equal
  • -lt - Less than
  • -le - Less than or equal

Alternative syntax using double parentheses:

(("5" < "10"))
(("7" >= "3"))

String Comparisons

  • = or == - String equality (behavior differs in [ ] vs [[ ]])
  • != - Not equal
  • < - Less than (ASCII comparison)
  • > - Greater than (ASCII comparison)
  • -z - Test for empty string
  • -n - Test for non-empty string

File Teests

  • -e - File exists
  • -f - Regular file (not directory or device)
  • -d - Is a directory
  • -h or -L - Is a symbolic link
  • -b - Block device
  • -c - Character device
  • -p - Named pipe
  • -S - Socket
  • -s - File has non-zero size
  • -t - File descriptor connected too terminal ([ -t 0 ] for stdin, [ -t 1 ] for stdout)
  • -r - Readable
  • -w - Writable
  • -x - Executable
  • -g - SGID bit set
  • -u - SUID bit set
  • -k - Sticky bit set
  • -O - Owned by current user
  • -G - Owned by current group
  • -N - Modified since last read
  • -nt - Newer than ([ f1 -nt f2 ])
  • -ot - Older than ([ f1 -ot f2 ])
  • -ef - Hard link to same file ([ f1 -ef f2 ])

Tags: bash Shell Scripting Linux unix

Posted on Mon, 18 May 2026 03:45:47 +0000 by jshowe