Check if a directory exists
This page was last updated on April 4, 2012.
- Use this Bash script to check if a directory exists, let you know if it exists, and create it if it doesn’t:
-
#!/bin/bash echo "Checking for mystuff directory"; if [ -d $HOME/mystuff ]; then echo "Directory exists"; else mkdir $HOME/mystuff; echo "Created $HOME/mystuff directory"; fi;
Obligatory Happy Ending
And they all lived happily ever after. The end.
