Mícéal Gallagher in Bash 1 minutes

Bash - Check if a file or directory exists

Checking for a directory can be done as follows:

```shif [ -d /home/micealGallagher/Documents/Project ] ; then

The folder exists

fi


If you want to check if the directory does NOT exist:

```shif [ ! -d /home/micealGallagher/Documents/Project ] ; then
# The folder does NOT exist
fi

Now if you would like to see if a file exists:

```shif [ -e /home/micealGallagher/Documents/file1.txt ] ; then

The file exists

fi ```

And I think you can guess the code at this point for the file not existing.