This directory of Linux commands is from Linux in a Nutshell, 5th Edition.
Click on any of the 687 commands below to get a description and list of available options. All links in the command summaries point to the online version of the book on Safari Bookshelf.
Buy it now, or read it online on Safari Bookshelf.
Evaluate an expression and, if its value is true, return a zero exit status; otherwise, return a nonzero exit status. In shell scripts, you can use the alternate form [expression] . This command is generally used with conditional constructs in shell programs. Also exists as a built-in in most shells.
The syntax for all of these options is test option file. If the specified file does not exist, they return false. Otherwise, they test the file as specified in the option description.
Is the file block special?
Is the file character special?
Is the file a directory?
Does the file exist?
Is the file a regular file?
Does the file have the set-group-ID bit set?
Does the file have the sticky bit set?
Is the file a symbolic link?
Is the file a named pipe?
Is the file readable by the current user?
Is the file nonempty?
Is the file a socket?
Is the file associated with file-descriptor (or 1, standard output, by default) connected to a terminal?
Does the file have the set-user-ID bit set?
Is the file writable by the current user?
Is the file executable?
Is the file owned by the process's effective user ID?
Is the file owned by the process's effective group ID?
The syntax for file comparisons is test file1 option file2. A string by itself, without options, returns true if it's at least one character long.
Is file1 newer than file2? Check modification date, not creation date.
Is file1 older than file2? Check modification date, not creation date.
Do the files have identical device and inode numbers?
The syntax for string tests is test option string or test string1 [!] = string2.
Is the string 0 characters long?
string1 = string2
Is the string at least 1 character long?
string1 != string2
Are the two strings equal?
Are the strings unequal?
Note that an expression can consist of any of the previous tests.
Is the expression true?
expression -a expression
Is the expression false?
expression -o expression
Are the expressions both true?
Is either expression true?
The syntax for integer tests is test integer1 option integer2. You may substitute -l string for an integer; this evaluates to string's length.
Are the two integers equal?
Are the two integers unequal?
Is integer1 less than integer2?
Is integer1 less than or equal to integer2?
Is integer1 greater than integer2?
Is integer1 greater than or equal to integer2?