File Test Operators
These unary operators take one argument, either a filename or a filehandle, and test the associated file to see if something is true about it. If the argument is omitted, they test $_ (except for -t, which tests STDIN). If the special argument _ (underscore) is passed, they use the information from the preceding test or stat call. File test operators can be stacked, e.g., -r -w -x file.
See also the filetest pragma in page 19.
| File is readable/writable/executable by effective uid/gid. |
| File is readable/writable/executable by real uid/gid. |
| File is owned by effective/real uid. |
| File exists/has zero size. |
| File exists and has nonzero size. Returns the size. |
| File is a plain file/a directory. |
| File is a symbolic link/a socket/a named pipe (FIFO). |
| File is a block/character special file. |
| File has setuid/setgid/sticky bit set. |
| Filehandle (default |
| File is a text/nontext (binary) file. These tests return true on an empty file, or a file at EOF when testing a filehandle. |
| Returns the modification/access/inode-change time of the file. The value is relative to the time the program started and expressed in fractional days. See also |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access