Usage
FILE=/etc/passwd
if test -f "$FILE"; then
echo "$FILE exist"
fi
if [ -f "$FILE" ]; then
echo "$FILE exist"
fi
if [[ -f $FILE ]]; then
echo "$FILE exist"
fi
test -f "$FILE" && echo "$FILE exist"
[ -f "$FILE" ] && echo "$FILE exist"
[[ -f $FILE ]] && echo "$FILE exist"
Operator | Description |
---|---|
-a FILE | True if FILE exist |
-b FILE | True if FILE exists and is a block special file |
-c FILE | True if FILE exists and is a special character file |
-d FILE | True if FILE exists and is a directory |
-e FILE | True if FILE exists and is a file, regardless of type (node, directory, socket, etc.) |
-f FILE | True if FILE exists and is a regular file (not a directory or device) |
-G FILE | True if FILE exists and has the same group as the user running the command |
-g FILE | True if FILE exists and has set-group-id (sgid) bit set |
-h FILE | True if FILE exists and is a symbolic link |
-k FILE | True if FILE exists and has a sticky bit bit set |
-L FILE | True if FILE exists and is a symbolic link |
-N FILE | True if FILE exists and has been modified since it was last read |
-O FILE | True if FILE exists and is owned by the user running the command |
-p FILE | True if FILE exists and is a pipe (FIFO) |
-r FILE | True if FILE exists and is readable |
-S FILE | True if FILE exists and is socket |
-s FILE | True if FILE exists and has nonzero size |
-u FILE | True if FILE exists and set-user-id (suid) bit is set |
-w FILE | True if FILE exists and is writable |
-x FILE | True if FILE exists and is executable |