In this tutorial, we are going to learn about how to check if a given file exists or not in Bash.
To check if a file exists or not in bash, we can use the logical not operator (
!) in the
Here is an example:
if [ ! -f /tmp/songs.txt ]; then echo "File does not exits" else echo "File exists" fi
-f option is used to check for a regular files.