file test operators

Test operators that ask about a path: -e exists, -f regular file, -d directory, -s not empty, -r, -w and -x readable, writable and executable.

In more detail

They work in both [ ] and [[ ]]. Testing before acting is only a hint, because the file can change between the test and your command, so still check the command's own status.

Example

[ -d "$work" ] && echo "still there"

Related terms

Taught in

References