TEST(1)

๐Ÿ’– test(1) โ€” check file types and compare values ๐Ÿ’–

okay bestie, pull up a chair, we're doing test(1) from GNU coreutils and it's genuinely one of the most underrated little divas in your whole toolbox. no cap.


โœจ NAME โœจ

test โ€” check file types and compare values ๐Ÿฆ‹


๐ŸŒธ SYNOPSIS ๐ŸŒธ

test EXPRESSION
test
[ EXPRESSION ]
[ ]
[ OPTION

๐Ÿ’… DESCRIPTION ๐Ÿ’…

It exits with the status determined by EXPRESSION. that's it. that's the whole gig. she checks the vibe and dips. ๐Ÿ‘‘

  • --help โ€” display this help and exit
  • --version โ€” output version information and exit

If EXPRESSION is omitted, it defaults to false (sad, empty, the void). Otherwise EXPRESSION is either true or false, and that sets the exit status. It's one of these, and I mean literally one of these:

( EXPRESSION )               EXPRESSION is true
! EXPRESSION                 EXPRESSION is false
EXPRESSION1 -a EXPRESSION2   both EXPRESSION1 and EXPRESSION2 are true
EXPRESSION1 -o EXPRESSION2   either EXPRESSION1 or EXPRESSION2 is true

๐ŸŽ€ OPTIONS AND TESTS ๐ŸŽ€

๐Ÿซถ String checks (the text girlies)

  • -n STRING โ€” the length of STRING is nonzero
  • STRING โ€” equivalent to -n STRING
  • -z STRING โ€” the length of STRING is zero
  • STRING1 = STRING2 โ€” the strings are equal
  • STRING1 != STRING2 โ€” the strings are not equal
  • STRING1 > STRING2 โ€” STRING1 is greater than STRING2 in the current locale
  • STRING1 < STRING2 โ€” STRING1 is less than STRING2 in the current locale

๐Ÿงฎ Integer checks (math but make it fashion)

  • INTEGER1 -eq INTEGER2 โ€” INTEGER1 is equal to INTEGER2
  • INTEGER1 -ge INTEGER2 โ€” INTEGER1 is greater than or equal to INTEGER2
  • INTEGER1 -gt INTEGER2 โ€” INTEGER1 is greater than INTEGER2
  • INTEGER1 -le INTEGER2 โ€” INTEGER1 is less than or equal to INTEGER2
  • INTEGER1 -lt INTEGER2 โ€” INTEGER1 is less than INTEGER2
  • INTEGER1 -ne INTEGER2 โ€” INTEGER1 is not equal to INTEGER2

๐Ÿ—‚๏ธ File comparisons (sibling rivalry edition)

  • FILE1 -ef FILE2 โ€” FILE1 and FILE2 have the same device and inode numbers
  • FILE1 -nt FILE2 โ€” FILE1 is newer (modification date) than FILE2
  • FILE1 -ot FILE2 โ€” FILE1 is older than FILE2

๐Ÿ” Single-file checks

  • -b FILE โ€” FILE exists and is block special
  • -c FILE โ€” FILE exists and is character special
  • -d FILE โ€” FILE exists and is a directory
  • -e FILE โ€” FILE exists
  • -f FILE โ€” FILE exists and is a regular file
  • -g FILE โ€” FILE exists and its set-group-ID bit is set
  • -G FILE โ€” FILE exists and is owned by the effective group ID
  • -h FILE โ€” FILE exists and is a symbolic link (same as -L)
  • -k FILE โ€” FILE exists and has its sticky bit set
  • -L FILE โ€” FILE exists and is a symbolic link (same as -h)
  • -N FILE โ€” FILE exists and has been modified since it was last read
  • -O FILE โ€” FILE exists and is owned by the effective user ID
  • -p FILE โ€” FILE exists and is a named pipe
  • -r FILE โ€” FILE exists and the user has read access
  • -s FILE โ€” FILE exists and has a size greater than zero
  • -S FILE โ€” FILE exists and is a socket
  • -t FD โ€” file descriptor FD is opened on a terminal
  • -u FILE โ€” FILE exists and its set-user-ID bit is set
  • -w FILE โ€” FILE exists and the user has write access
  • -x FILE โ€” FILE exists and the user has execute (or search) access

โš ๏ธ THE FINE PRINT, BESTIE, READ IT โš ๏ธ

Except for -h and -L, all FILE-related tests dereference symbolic links. (so like, they follow the link and judge the destination. -h and -L are the only ones who see the link itself. slay.)

Beware that parentheses need to be escaped (e.g., by backslashes) for shells. ๐Ÿซฃ your shell will absolutely eat them otherwise.

INTEGER may also be -l STRING, which evaluates to the length of STRING.

Binary -a and -o are ambiguous. use test EXPR1 && test EXPR2 or test EXPR1 || test EXPR2 instead. fr fr, don't be messy.

[ honors --help and --version, but test treats them as STRINGs. ๐Ÿ’€ iconic behaviour honestly.

Your shell may have its own version of test and/or [, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports. (iykyk โ€” your shell's builtin is probably the one actually running.)


๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Written by Kevin Braunsdorf and Matthew Bradburn. legends. ๐Ÿ’œ


๐Ÿ› REPORTING BUGS ๐Ÿ›


Copyright ยฉ 2026 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.

This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.


๐ŸŒˆ SEE ALSO ๐ŸŒˆ


okay that's the whole page, no notes, you ate it. this one's from GNU coreutils 9.12, dated September 2026, and it lives in section 1 of the manual. go forth and vibe check some files ๐Ÿฆ‹โœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from