-4

I just ordered a new root server 18.04 Ubuntu with Plesk. I log in as root and want to create a folder for example:

mkdir /usr/local/myfolder/hello

I get the error:

mkdir: cannot create directory ‘/usr/local/myfolder/hello’: No such file or directory

It only works, when I use mkdir -p. I can only create 1 folder ahead, when I am in the directory, not a path.

For me this is not normal, how can I fix this? Also my scripts dont run because of this.

Thanks

zer02
  • 95

1 Answers1

5

mkdir only creates one single directory when called without -p.

A directory in the path /usr/local/myfolder/ is missing, this is why you get the error. If you call mkdir -p, the missing path is created as well.

Another effect of using the -p option is that mkdir -p does not complain when the directory already exists. This is why this variant is frequently used in scripts.

schily
  • 19,173
  • Thanks the reason why I ask this. Is because I want to install antmedia server using the create_app.sh and it says mkdir cannot create path even as root! Then if I manually create it, it says file already exists abort. This never happened to me. – zer02 Sep 02 '20 at 10:17
  • @zer02 since mkdir -p does not complain when the target directory already exists, it is frequently used from inside shell scripts. – schily Sep 02 '20 at 10:29