Test Operators

These are the operators that are used with the [[...]] construct. They can be logically combined with && ("and") and || ("or") and grouped with parenthesis.

Operator True If...
-a file file exists.
-b file file is a block device file.
-c file file is a character device file.
-d file file is a directory.
-f file file is a regular file.
-g file file has its setgid bit set.
-k file file has its sticky bit set.
-n string string is non-null.
-o option option is set.
-p file file is a pipe or named pipe (FIFO file).
-r file file is readable.
-s file file is not empty.
-t N File descriptor N points to a terminal.
-u file file has its setuid bit set.
-w file file is writeable.
-x file file is executable, or file is a directory that can be searched.
-z string string is null.
-G file file's group ID is the same as that of the shell.
-L file file is a symbolic link.
-O file file is owned by the shell's user ID.
-S file file is a socket.
fileA -nt fileB fileA is newer than fileB.
fileA -ot fileB fileA is older than fileB.
fileA -ef fileB fileA and fileB point to the same file.
string = pattern string matches pattern (which can contain wildcards).
string != pattern string does not match pattern.
stringA < stringB stringA comes before stringB in dictionary order.
stringA > stringB stringA comes after stringB in dictionary order.
exprA -eq exprB Arithmetic expressions exprA and exprB are equal.
exprA -ne exprB Arithmetic expressions exprA and exprB are not equal.
exprA -lt exprB exprA is less than exprB.
exprA -gt exprB exprA is greater than exprB.
exprA -le exprB exprA is less than or equal to exprB.
exprA -ge exprB exprA is greater than or equal to exprB.