The file system operators each take a single operand word. This first set all return 1 (true) or 0 (false).
| Operator | True if |
|---|---|
| -A |
Archive bit set |
| -C |
File or directory is compressed |
-D -d |
Directory |
| -H |
Hidden file or directory |
| -R |
Read-only file or directory |
| -S |
System file or directory |
| -e |
File or directory exists |
| -f |
Ordinary File |
| -o |
Ownership (Same as existence on a FAT file system) |
| -r |
Readable (Same as ordinary file on a FAT file system) |
| -w |
Writable (Not read-only and not a directory) |
| -x |
Executable (Has a .csh, .exe, .com or .cmd extension and, if it's an .exe or a .com file, appears to be a valid binary executable.) |
| -z |
Zero-length file |
The -t and -s operators return timestamps and sizes.
| Operator | Returns |
|---|---|
| -t |
Timestamp in the 24-hour local time formatted as a character string of the form, YYYY-MM-DD hh:mm:ss, e.g., 2012-11-25 17:35:26. If the operand doesn't exist or doesn't have a timestamp (as is the case for C:\), -t returns null; this is not an error. |
| -s |
Size in bytes if the operand exists and is a file, otherwise null. |
The file system operators are all prefix operators. Each takes a single operand, which is interpreted as a word, not an expression, and may involve wildcarding. If wildcarding produces more than one match, the test is done on the first one. For example:
Wildcarding
Expression operators
Tutorial: Words versus expressions
Tutorial: Wildcarding
Tutorial: Expressions