How Do I Write a Script to Test if a File Exists?

Problem scenario
You want a script to test if a file is in a specific location or not. You are using Linux. What should you do?

Use this script (but modify "/path/to/file" to be the path and name of the file you are searching for):

if [ -f "/path/to/file" ]
echo "file exists"
echo "file does not exist"

Leave a comment

Your email address will not be published. Required fields are marked *