O'Reilly logo

Linux in a Nutshell, 6th Edition by Robert Love, Stephen Figgins, Ellen Siever, 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

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.

File conditions

-a file, -e file

file exists.

-b file

file exists and is a block special file.

-c file

file exists and is a character special file.

-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, -L file

file exists and is a symbolic link.

-k file

file exists, and its sticky bit is set.

-N file

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 and is readable.

-s file

file exists and has a size greater than zero.

-S file

file exists and is a socket.

-t [n]

The open file descriptor n is associated with a terminal device; default n is 1.

-u file

file exists, and its set-user-id bit is set.

-w file

file exists and is writable.

-x file

file exists and is executable.

f1 -ef f2

Files f1 and f2 are linked (refer to same file).

f1 -nt f2

File f1 is newer than ...

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