Checking If A File Or Directory Exists In Bash
February 2013
Check For Files (multi-line)
if [; then
Check For Files (single line)
if [; then ; Using an else
if [; then
else
Using the "not" operator
if [; then
Checking For Directories
To check if a directory exists in a shell script you can use the following:
if [; then
Or to check if a directory doesn't exist:
if [; then
Symbolic links can cause issues. See the stack overflow question below for some ways to deal with that
end of line