Name

test

Synopsis

    test condition
             or
    [ condition ]
             or
    [[ condition ]]

Evaluate a condition and, if its value is true, return a zero exit status; otherwise, return a nonzero exit status. An alternate form of the command uses [ ] rather than the word test. An additional alternate form uses [[ ]], in which case word splitting and pathname expansion are not done. (See the [[ ]] entry.) condition is constructed using the following expressions. Conditions are true if the description holds true. Features that are specific to Bash are marked with a (B). Features that are specific to the Korn shell are marked with a (K). Features that are specific to ksh93 are marked with a (K93).

File Conditions

-a file

file exists.

-b file

file exists and is a block special file.

-c file

file exists and is a character special file.

-C file

(K) file exists and is a contiguous file. This facility is not available on most Unix systems.

-d file

file exists and is a directory.

-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 its group is the effective group ID.

-h file

file exists and is a symbolic link.

-k file

file exists, and its sticky bit is set.

-L file

file exists and is a symbolic link.

-N file

(B) file exists and was modified after it was last read.

-O file

file exists, and its owner is the effective user ID.

-p file

file exists and is a named pipe (FIFO).

-r file

file exists ...

Get Unix in a Nutshell, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.