File

DevOps Ubuntu Shell Script: File

File exist

#!/bin/sh
 
if [ -f "/path/to/dir/filename" ]; then
    echo "File /path/to/dir/filename exists."
else
    echo "File /path/to/dir/filename does not exists."
fi

File not exist and touch new file

#!/bin/sh
[ ! -f /path/to/dir/not-exist-file.txt ] && touch /path/to/dir/not-exist-file.txt

Reference