Excerpted from http://www.comptechdoc.org/os/linux/usersguide/linux_ugshellpro.html
Tests
There is a function provided by bash called Test which returns a true or False value depending on the result of the tested Expression. It syntax is:
Test expression
It can also be implied as follows:
[Expression]
The tests below is test conditions provided by the shell:
- -B File = True If the file exists and is block special file.
- -c File = True If the file exists and is character special file.
- -D file = True If the file exists and is a directory.
- -E File = True If the file exists.
- -F file = True If the file exists and is a regular file
- -G file = True If the file exists and the Set-group-id bit is set.
- -K File = True if the files ' "sticky" bit is set.
- -L FILE = True If the file exists and is a symbolic link.
- -P file = True If the file exists and is a named pipe.
- -R file = True If the file exists and is readable.
- -S File = True If the file exists and its size is greater than zero.
- -S File = True If the file exists and is a socket.
- -T FD = True If the file descriptor is opened on a terminal.
- -U File = True If the file exists and its Set-user-id bit is set.
- -W File = True If the file exists and is writable.
- -X File = True If the file exists and is executable.
- -O file = True If the file exists and is owned by the effective user ID.
- -G file = True If the file exists and is owned by the effective group ID.
- File1–nt file2 = True If file1 is newer, by modification date, than file2.
- file1 ot file2 = True If file1 is older than file2.
- File1 EF file2 = True if file1 and file2 have the same device and inode numbers.
- -Z string = True If the length of the string is 0.
- -N String = True If the length of the string is Non-zero.
- string1 = string2 = True If the strings is equal.
- String1! = string2 = True If the strings is not equal.
- !expr = True If the expr evaluates to false.
- Expr1–a EXPR2 = True if both Expr1 and Expr2 is true.
- Expr1–o EXPR2 = True is either EXPR1 or EXPR2 is true.
The judgment expression of the Linux command