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