Bash: test if file exists

By Eric Downing. Filed in Scripting, Shell, Utilities  |  
TOP del.icio.us digg

When you need to do some processing in bash and display if a file exists, the following is a simple script that takes the filename in the $testfile variable and reports if it exists or not.

if [ -f $testfile ]
then
  echo $testfile exists!
else
  echo $testfile does not exist
fi

Leave a Reply