Name
test
Synopsis
test condition
or
[ condition ]
Description
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. condition is constructed using the following expressions. Conditions are true if the description holds true.
File conditions
- -a file
file exists.
- -b file
file is a block special file.
- -c file
file is a character special file.
- -d file
file is a directory.
- -e file
file exists.
- -f file
file is a regular file.
- -g file
file has the set-group-ID bit set.
- -h file
file is a symbolic link.
- -k file
file has its sticky bit (no longer used) set.
- -p file
file is a named pipe (FIFO).
- -r file
file is readable.
- -s file
file has a size greater than 0.
- -t [n]
The open file descriptor n is associated with a terminal device; default n is 1.
- -u file
file has its set-user-ID bit set.
- -w file
file is writable.
- -x file
file is executable.
- -G file
file’s group is the process’s effective group ID.
- -L file
file is a symbolic link.
- -N file
file has been modified since its last time of access.
- -O file
file’s owner is the process’s effective user ID.
- -S file
file is a socket.
- f1 -ef f2
Files f1 and f2 are linked (refer to same file through a hard link).
- f1 -nt f2
File f1 is newer than f2.
- f1 -ot f2
File f1 is older than f2.
String conditions
- -n s1
String s1 has nonzero length.
- -o s1
Shell option s1 is set. Shell options are described under the set built-in ...
Get Linux in a Nutshell, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.