To check if a file exists on the filesystem using a bash shell script, we can use the test command with the -f option. Below is an example of how we might use this command to check if a file called "file.txt" exists: if test -f "file.txt"; then
echo "File exists"
else
echo "File does not exist"
fi Alternatively, we can use the [ -f "file.txt" ] syntax to achieve the same result.  Below is an example of how we might use this command in a script:  #!/bin/bash
if [ -f "file.txt" ]; then
echo "File exists"
else
echo "File does not exist"
fi This script will check for the existence of a file called "file.txt" and will print "File exists" if the file exists or "File does not exist" if the file does not exist.  We can also use the -d option to check for the existence of a directory or the -e option to check for the existence of either a file or a directory. This is also one of the most frequently asked Shell Scripting questions.