On one of our remote systems mkdir -p $directory
fails when the directory exists. which means it shows
mkdir: cannot create directory '$directory' : file exists
This is really puzzling, as I believed the contract of -p
was that is always succeed when the directory already exists. And it works on the other systems I tried.
there is a user test
on all of these systems, and directory=/home/test/tmp
.
mkdir WILL give you an error if the directory already exists. mkdir -p WILL NOT give you an error if the directory already exists. Also, the directory will remain untouched i.e. the contents are preserved as they were.
mkdir: cannot create directory – Permission denied The reason for this error is that the user you're running the mkdir as, doesn't have permissions to create new directory in the location you specified. You should use ls command on the higher level directory to confirm permissions.
This could be caused if there is already a file by the same name located in the directory.
Note that a directory cannot contain both a file and folder by the same name on linux machines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With