TEST(1)

๐Ÿ’– Welcome to the test manual ๐Ÿ’–

Okay bestie, this is the manual for test, which is TEST(1) in the User Commands section ๐ŸŽ€ It's literally the tool that checks file types and compares values, and I'm obsessed with it. Let's go โœจ


๐ŸŒธ NAME ๐ŸŒธ

test - check file types and compare values ๐Ÿฆ‹

๐Ÿงš SYNOPSIS ๐Ÿงš

test EXPRESSION
test
[ EXPRESSION ]
[ ]
[ OPTION

๐Ÿ‘‘ DESCRIPTION ๐Ÿ‘‘

Okay so the whole point is to exit with the status determined by EXPRESSION ๐Ÿ’… It's giving exit codes, not printed output.

These two flags are the only ones you get, and they're giving main character energy:

  • --help โ€” shows this help and exits ๐Ÿ™ˆ
  • --version โ€” outputs version info and exits โœจ

If you leave out EXPRESSION entirely, it defaults to false. Otherwise the expression is either true or false, and that's what sets the exit status. Here's the whole menu ๐Ÿ“

  • ( 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
  • -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
  • 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
  • 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
  • -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 is set-group-ID
  • -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

Quick vibe check on the file tests: except for -h and -L, all FILE-related tests dereference symbolic links ๐Ÿ”— Also, parentheses need to be escaped (e.g., by backslashes) for shells, so don't skip that ๐Ÿซถ And INTEGER may also be -l STRING, which evaluates to the length of STRING ๐Ÿงฎ

โš ๏ธ Binary -a and -o are ambiguous, so it's giving chaos. Use test EXPR1 && test EXPR2 or test EXPR1 || test EXPR2 instead ๐Ÿ˜ญ
๐Ÿ™ˆ [ honors --help and --version, but test treats them as STRINGs. Iykyk.

Your shell might have its own version of test and/or [, and that version usually takes over from the one described here ๐Ÿ’… Check your shell's documentation for the options it supports.


๐ŸŽ€ AUTHOR ๐ŸŽ€

Written by Kevin Braunsdorf and Matthew Bradburn ๐Ÿ’œ

๐Ÿž REPORTING BUGS ๐Ÿž

GNU coreutils online help: <https://www.gnu.org/software/coreutils/> ๐ŸŒˆ Report any translation bugs to <https://translationproject.org/team/> ๐ŸŒ

๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

Full documentation <https://www.gnu.org/software/coreutils/test> or available locally via: info '(coreutils) test invocation' ๐Ÿ“–

Packaged by Debian (9.7-3) ๐Ÿ“ฆ Copyright ยฉ 2025 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.


Served fresh from GNU coreutils 9.7, June 2025, with love from your bestie ๐Ÿซถ๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from