shell - How to mkdir only if a dir does not already exist? -
I'm writing a shell script on AIX to run under KornShell (ksh). I want to use the mkdir command to create a directory. But the directory may already exist, in that situation, I do not want to do anything. So I want to see that this directory does not exist, or suppresses the "file exists" error to suppress the error which tries to make an mkdir create an existing directory
Any ideas on how to do it best?
Try:
mkdir -p foo Note that this will also create any intermediate directory that does not exist; For example,
mkdir -p foo / bar / baz directory foo , will create foo / bar , and foo / bar / baz if they are not present.
If you want an error when the root directory does not exist, and the directory if it does not exist, you can first do it for the existence of the directory:
[-d foo] || Mkdir foo
Comments
Post a Comment