How to mkdir only if a directory does not already exist?
Asked 07 September, 2021
Viewed 1.6K times
  • 47
Votes

I am writing a shell script to run under the KornShell (ksh) on AIX. I would like to use the mkdir command to create a directory. But the directory may already exist, in which case I do not want to do anything. So I want to either test to see that the directory does not exist, or suppress the "File exists" error that mkdir throws when it tries to create an existing directory.

How can I best do this?

16 Answer