O'Reilly logo

Learning the Korn Shell, 2nd Edition by Bill Rosenblatt, Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. When used with filenames of the form /dev/fd/ N, they test the corresponding attribute of open file descriptor N.

OperatorTrue if...
-a file

file exists. (Obsolete. -e is preferred.)

-b file file is a block device file.
-c file file is a character device file.
-C file

file is a contiguous file. (Not for most Unix versions.)

-d file file is a directory.
-e file file exists.
-f file file is a regular file.
-g file file has its setgid bit set.
-G file

file’s group ID is the same as the effective group ID of the shell.

-h file file is a symbolic link.
-k file file has its sticky bit set.
-l file

file is a symbolic link. (Only works on systems where /bin/test -l tests for symbolic links.)

-L file file is a symbolic link.
-n string string is non-null.
-o option option is set.
-O file file is owned by the shell’s effective user ID.
-p file file is a pipe or named pipe (FIFO file).
-r file file is readable.
-s file file is not empty.
-S file file is a socket.
-t N File descriptor N points to a terminal.
-u file file has its setuid bit set.
-w file file is writable.
-x file

file is executable, or file is a directory that can be searched.

-z string string is null.
fileA -nt fileB

fileA is newer than fileB, or fileB does not exist.

fileA -ot fileB

fileA is older than fileB

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required