TEST(1)
๐
TEST(1) โ the test page, bestie edition ๐
okay so welcome to TEST(1), the manual for test from the General Commands Manual section 1, and honestly? she's a legend. she checks file types and compares values, and she's been carrying every if statement you've ever written. no cap. ๐
โจ NAME โจ
test โ check file types and compare values. that's it, that's the whole job, and she does it flawlessly ๐ซถ
โจ SYNOPSIS โจ
test EXPRESSION
test
[ EXPRESSION ]
[ ]
[ OPTION
likeโฆ yes, [ is literally just test wearing a little outfit. same girl, different bracket. ๐
โจ DESCRIPTION โจ
Check file types and compare values. short description, huge impact. she's the vibe check of your shell scripts fr fr. ๐ธ
โจ OPTIONS โจ
-h,--helpโ print help ๐ (yes,-hmeans help here, but keep reading, because in the file-tests section-h FILEmeans something completely different and that's just how it is, bestie ๐)-V,--versionโ print version โจ
โจ EXTRA โจ
Exit with the status determined by EXPRESSION. that's the whole deal โ she speaks in exit codes, and every script listens. ๐
An omitted EXPRESSION defaults to false. Otherwise, EXPRESSION is true or false and sets exit status. It is one of:
( EXPRESSION )โ EXPRESSION is true! EXPRESSIONโ EXPRESSION is false- EXPRESSION1
-aEXPRESSION2 โ both EXPRESSION1 and EXPRESSION2 are true - EXPRESSION1
-oEXPRESSION2 โ either EXPRESSION1 or EXPRESSION2 is true
๐ String operations:
-n STRINGโ the length of STRING is nonzeroSTRINGโ equivalent to-n STRING-z STRINGโ the length of STRING is zeroSTRING1 = STRING2โ the strings are equalSTRING1 != STRING2โ the strings are not equalSTRING1 > STRING2โ STRING1 is greater than STRING2 in the current localeSTRING1 < STRING2โ STRING1 is less than STRING2 in the current locale
๐งฎ Integer comparisons:
INTEGER1 -eq INTEGER2โ INTEGER1 is equal to INTEGER2INTEGER1 -ge INTEGER2โ INTEGER1 is greater than or equal to INTEGER2INTEGER1 -gt INTEGER2โ INTEGER1 is greater than INTEGER2INTEGER1 -le INTEGER2โ INTEGER1 is less than or equal to INTEGER2INTEGER1 -lt INTEGER2โ INTEGER1 is less than INTEGER2INTEGER1 -ne INTEGER2โ INTEGER1 is not equal to INTEGER2
๐ฆ File operations:
FILE1 -ef FILE2โ FILE1 and FILE2 have the same device and inode numbersFILE1 -nt FILE2โ FILE1 is newer (modification date) than FILE2FILE1 -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 read permission is granted-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 write permission is granted-x FILEโ FILE exists and execute (or search) permission is granted
Except for -h and -L, all FILE-related tests dereference (follow) symbolic links. bestie, beware that parentheses need to be escaped (e.g., by backslashes) for shells, or your shell will eat them before test ever sees them ๐ญ INTEGER may also be -l STRING, which evaluates to the length of STRING.
โ ๏ธ NOTE: Binary-aand-oare inherently ambiguous. Usetest EXPR1 && test EXPR2ortest EXPR1 || test EXPR2instead. seriously. do that. ๐
โ ๏ธ NOTE:[honors the--helpand--versionoptions, buttestdoes not.testtreats each of those as it treats any other nonempty STRING. iconic chaotic behaviour honestly ๐
โ ๏ธ NOTE: your shell may have its own version oftestand/or[, which usually supersedes the version described here. Please refer to your shell's documentation for details about the options it supports. ๐
Errors are reported with the expression echoed back and a caret under the argument at fault whenever stderr is a terminal; anything else reading stderr gets the usual single-line message. so if you're piping it somewhere, the fancy little caret moment justโฆ doesn't happen. โจ
โจ VERSION โจ
v(uutils coreutils) 0.12.0
โจ EXAMPLES โจ
Test if a given variable is equal to a given string:
test "$MY_VAR" = "/bin/zsh"
Test if a given variable is empty ([z]ero length):
test -z "$GIT_BRANCH"
Test if a [f]ile exists:
test -f "path/to/file"
Test if a [d]irectory does not exist:
test ! -d "path/to/directory"
If A is true, then do B, or C in the case of an error (notice that C may run even if A fails):
test condition && echo "true" || echo "false"
Use test in a conditional statement:
if test -f "path/to/file"; then echo "File exists"; else echo "File does not exist"; fi
๐ธ The examples are provided by the tldr-pages project <https://tldr.sh> under the CC BY 4.0 License. Please note that, as uutils is a work in progress, some examples might fail.
and that's the whole page bestie, no notes, she ate and left absolutely no crumbs ๐ that was TEST(1) from uutils coreutils 0.12.0, dated 2026-09-25 โ go forth and write conditionals that actually work ๐ซถ๐โจ
๐ฆ where this page comes from
- ubuntu stonking: rust-coreutils 0.12.0-1ubuntu2 ยท MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms