Linux "test" Command Line Options and Examples
check file types and compare values

Exit with the status determined by EXPRESSION. --help display this help and exit --version output version information and exit An omitted EXPRESSION defaults to false. Otherwise, EXPRESSION is true or false and sets exit status.


Usage:

test EXPRESSION
    test


    [ EXPRESSION ]
    [ ]
    [ OPTION




Command Line Options:

--help
display this help and exit
test --help ...
--version
output version information and exitAn omitted EXPRESSION defaults to false. Otherwise, EXPRESSION is true or false and sets exit status. It isone of:( EXPRESSION )EXPRESSION is true! EXPRESSIONEXPRESSION is falseEXPRESSION1 -a EXPRESSION2both EXPRESSION1 and EXPRESSION2 are trueEXPRESSION1 -o EXPRESSION2either EXPRESSION1 or EXPRESSION2 is true
test --version ...
-n
the length of STRING is nonzeroSTRING equivalent to -n STRING
test -n ...
-z
the length of STRING is zeroSTRING1 = STRING2the strings are equalSTRING1 != STRING2the strings are not equalINTEGER1 -eq INTEGER2INTEGER1 is equal to INTEGER2INTEGER1 -ge INTEGER2INTEGER1 is greater than or equal to INTEGER2INTEGER1 -gt INTEGER2INTEGER1 is greater than INTEGER2INTEGER1 -le INTEGER2INTEGER1 is less than or equal to INTEGER2INTEGER1 -lt INTEGER2INTEGER1 is less than INTEGER2INTEGER1 -ne INTEGER2INTEGER1 is not equal to INTEGER2FILE1 -ef FILE2FILE1 and FILE2 have the same device and inode numbersFILE1 -nt FILE2FILE1 is newer (modification date) than FILE2FILE1 -ot FILE2FILE1 is older than FILE2
test -z ...
-b
FILE exists and is block special
test -b ...
-c
FILE exists and is character special
test -c ...
-d
FILE exists and is a directory
test -d ...
-f
FILE exists and is a regular file
test -f ...
-g
FILE exists and is set-group-ID
test -g ...
-G
FILE exists and is owned by the effective group ID
test -G ...
-h
FILE exists and is a symbolic link (same as -L)
test -h ...
-k
FILE exists and has its sticky bit set
test -k ...
-L
FILE exists and is a symbolic link (same as -h)
test -L ...
-O
FILE exists and is owned by the effective user ID
test -O ...
-p
FILE exists and is a named pipe
test -p ...
-r
FILE exists and read permission is granted
test -r ...
-s
FILE exists and has a size greater than zero
test -s ...
-S
FILE exists and is a socket
test -S ...
-t
FD file descriptor FD is opened on a terminal
test -t ...
-u
FILE exists and its set-user-ID bit is set
test -u ...
-w
FILE exists and write permission is granted
test -w ...
-x
FILE exists and execute (or search) permission is grantedExcept for -h and -L, all FILE-related tests dereference symbolic links. Beware that parentheses need to beescaped (e.g., by backslashes) for shells. INTEGER may also be -l STRING, which evaluates to the length ofSTRING.NOTE: Binary -a and -o are inherently ambiguous. Use 'test EXPR1 && test EXPR2' or 'test EXPR1 || test EXPR2'instead.NOTE: [ honors the --help and --version options, but test does not. test treats each of those as it treatsany other nonempty STRING.NOTE: your shell may have its own version of test and/or [, which usually supersedes the version describedhere. Please refer to your shell's documentation for details about the options it supports.AUTHORWritten by Kevin Braunsdorf and Matthew Bradburn.REPORTING BUGSGNU coreutils online help: <http://www.gnu.org/software/coreutils/>Report [ translation bugs to <http://translationproject.org/team/>COPYRIGHTCopyright © 2017 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later<http://gnu.org/licenses/gpl.html>.This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent per‐mitted by law.
test -x ...