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 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 checks (math but make it fashion)
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 comparisons (sibling rivalry edition)
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
๐ 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-aand-oare ambiguous. usetest EXPR1 && test EXPR2ortest EXPR1 || test EXPR2instead. 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 ๐
- Report bugs to: <bug-coreutils@gnu.org>.
- Report any translation bugs to: <https://translationproject.org/team/>.
- GNU coreutils home page: <https://www.gnu.org/software/coreutils/>
- General help using GNU software: <https://www.gnu.org/gethelp/>
๐ COPYRIGHT ๐
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 ๐
access(2)- Full documentation <https://www.gnu.org/software/coreutils/test> or available locally via:
info '(coreutils) test invocation'
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
- arch rolling: coreutils 9.12-2 ยท GPL-3.0-or-later AND GFDL-1.3-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms