|
NAME | SYNOPSIS | DESCRIPTION | AUTHOR | REPORTING BUGS | COPYRIGHT | SEE ALSO | COLOPHON |
|
|
|
TEST(1) User Commands TEST(1)
test - check file types and compare values
test EXPRESSION
test
[ EXPRESSION ]
[ ]
[ OPTION
Exit with the status determined by EXPRESSION.
]8;;https://www.gnu.org/software/coreutils/test#test--help\--help]8;;\ display this help and exit
]8;;https://www.gnu.org/software/coreutils/test#test--version\--version]8;;\
output version information and exit
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 -a EXPRESSION2
both EXPRESSION1 and EXPRESSION2 are true
EXPRESSION1 -o EXPRESSION2
either EXPRESSION1 or EXPRESSION2 is true
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-n\-n STRING]8;;\
the length of STRING is nonzero
STRING equivalent to -n STRING
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-z\-z STRING]8;;\
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
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-eq\INTEGER1 -eq INTEGER2]8;;\
INTEGER1 is equal to INTEGER2
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-ge\INTEGER1 -ge INTEGER2]8;;\
INTEGER1 is greater than or equal to INTEGER2
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-gt\INTEGER1 -gt INTEGER2]8;;\
INTEGER1 is greater than INTEGER2
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-le\INTEGER1 -le INTEGER2]8;;\
INTEGER1 is less than or equal to INTEGER2
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-lt\INTEGER1 -lt INTEGER2]8;;\
INTEGER1 is less than INTEGER2
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-ne\INTEGER1 -ne INTEGER2]8;;\
INTEGER1 is not equal to INTEGER2
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-ef\FILE1 -ef FILE2]8;;\
FILE1 and FILE2 have the same device and inode numbers
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-nt\FILE1 -nt FILE2]8;;\
FILE1 is newer (modification date) than FILE2
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-ot\FILE1 -ot FILE2]8;;\
FILE1 is older than FILE2
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-b\-b FILE]8;;\
FILE exists and is block special
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-c\-c FILE]8;;\
FILE exists and is character special
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-d\-d FILE]8;;\
FILE exists and is a directory
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-e\-e FILE]8;;\
FILE exists
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-f\-f FILE]8;;\
FILE exists and is a regular file
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-g\-g FILE]8;;\
FILE exists and is set-group-ID
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-G\-G FILE]8;;\
FILE exists and is owned by the effective group ID
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-h\-h FILE]8;;\
FILE exists and is a symbolic link (same as -L)
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-k\-k FILE]8;;\
FILE exists and has its sticky bit set
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-L\-L FILE]8;;\
FILE exists and is a symbolic link (same as -h)
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-N\-N FILE]8;;\
FILE exists and has been modified since it was last read
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-O\-O FILE]8;;\
FILE exists and is owned by the effective user ID
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-p\-p FILE]8;;\
FILE exists and is a named pipe
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-r\-r FILE]8;;\
FILE exists and the user has read access
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-s\-s FILE]8;;\
FILE exists and has a size greater than zero
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-S\-S FILE]8;;\
FILE exists and is a socket
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-t\-t FD]8;;\ file descriptor FD is opened on a terminal
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-u\-u FILE]8;;\
FILE exists and its set-user-ID bit is set
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-w\-w FILE]8;;\
FILE exists and the user has write access
]8;;https://www.gnu.org/software/coreutils/manual/coreutils.html#test-x\-x FILE]8;;\
FILE exists and the user has execute (or search) access
Except for -h and -L, all FILE-related tests dereference symbolic
links. Beware that parentheses need to be escaped (e.g., by
backslashes) for shells. 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.
'[' honors --help and --version, but 'test' treats them as
STRINGs.
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.
Written by Kevin Braunsdorf and Matthew Bradburn.
Report bugs to: bug-coreutils@gnu.org
GNU coreutils home page: <https://www.gnu.org/software/coreutils/>
General help using GNU software: <https://www.gnu.org/gethelp/>
Report any translation bugs to
<https://translationproject.org/team/>
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.
access(2)
Full documentation <https://www.gnu.org/software/coreutils/test>
or available locally via: info '(coreutils) test invocation'
This page is part of the coreutils (basic file, shell and text
manipulation utilities) project. Information about the project
can be found at ⟨http://www.gnu.org/software/coreutils/⟩. If you
have a bug report for this manual page, see
⟨http://www.gnu.org/software/coreutils/⟩. This page was obtained
from the tarball coreutils-9.11.tar.xz fetched from
⟨http://ftp.gnu.org/gnu/coreutils/⟩ on 2026-05-24. If you
discover any rendering problems in this HTML version of the page,
or you believe there is a better or more up-to-date source for the
page, or you have corrections or improvements to the information
in this COLOPHON (which is not part of the original manual page),
send a mail to man-pages@man7.org
GNU coreutils 9.11 April 2026 TEST(1)