snipplets.dev/code/Bash/file_folder_exists.sh

26 lines
375 B
Bash
Raw Normal View History

2023-08-08 23:06:21 +03:00
#!/bin/sh
# Check file exists
FILE=/etc/resolv.conf
if [ -f "$FILE" ]; then
echo "$FILE exists."
else
echo "$FILE does not exist."
fi
2023-09-10 01:13:40 +03:00
# OR
2023-08-08 23:06:21 +03:00
[ -f /etc/resolv.conf ] && echo "/etc/resolv.conf exists."
# Check directory exists
DIR=/etc/docker
if [ -d "$DIR" ]; then
echo "$DIR is a directory."
fi
2023-09-10 01:13:40 +03:00
# OR
2023-08-08 23:06:21 +03:00
[ -d /etc/docker ] && echo "/etc/docker is a directory."