When does `mkdir -p /path/to/dir` exist with nonzero status?
Clash Royale CLAN TAG#URR8PPP
up vote
-1
down vote
favorite
mkdir -p /path/to/something
when does the above command exit with nonzero exit status?
Does it happen, if and only if /path/to/something
doesn't exist as any file (or as a directory?) before running the command and the command fails to create it as a directory?
man mkdir
says
-p, --parents
no error if existing, make parent directories as needed
Thanks.
mkdir
add a comment |Â
up vote
-1
down vote
favorite
mkdir -p /path/to/something
when does the above command exit with nonzero exit status?
Does it happen, if and only if /path/to/something
doesn't exist as any file (or as a directory?) before running the command and the command fails to create it as a directory?
man mkdir
says
-p, --parents
no error if existing, make parent directories as needed
Thanks.
mkdir
Trymkdir -p /dev/i/am/a/hacker
as non-root and see it fail. If you don't have permissions it will fail and return a non-zero value.
â cylgalad
May 8 at 7:25
add a comment |Â
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
mkdir -p /path/to/something
when does the above command exit with nonzero exit status?
Does it happen, if and only if /path/to/something
doesn't exist as any file (or as a directory?) before running the command and the command fails to create it as a directory?
man mkdir
says
-p, --parents
no error if existing, make parent directories as needed
Thanks.
mkdir
mkdir -p /path/to/something
when does the above command exit with nonzero exit status?
Does it happen, if and only if /path/to/something
doesn't exist as any file (or as a directory?) before running the command and the command fails to create it as a directory?
man mkdir
says
-p, --parents
no error if existing, make parent directories as needed
Thanks.
mkdir
asked May 8 at 2:46
Tim
22.6k63222401
22.6k63222401
Trymkdir -p /dev/i/am/a/hacker
as non-root and see it fail. If you don't have permissions it will fail and return a non-zero value.
â cylgalad
May 8 at 7:25
add a comment |Â
Trymkdir -p /dev/i/am/a/hacker
as non-root and see it fail. If you don't have permissions it will fail and return a non-zero value.
â cylgalad
May 8 at 7:25
Try
mkdir -p /dev/i/am/a/hacker
as non-root and see it fail. If you don't have permissions it will fail and return a non-zero value.â cylgalad
May 8 at 7:25
Try
mkdir -p /dev/i/am/a/hacker
as non-root and see it fail. If you don't have permissions it will fail and return a non-zero value.â cylgalad
May 8 at 7:25
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
5
down vote
To elaborate on the previous answer with a few examples.
It could be when trying to create folders inside system folders:
ubuntu:~$ mkdir /proc/test
mkdir: cannot create directory âÂÂ/proc/testâÂÂ: No such file or directory
ubuntu:~$ mkdir -p /dev/null/test
mkdir: cannot create directory âÂÂ/dev/nullâÂÂ: Not a directory
Or when you don't have permission to the previous folder:
ubuntu:~$ mkdir -p /root/test
mkdir: cannot create directory âÂÂ/rootâÂÂ: Permission denied
It will also fail if there is a file by the same name in the folder:
ubuntu:~$ touch /tmp/test
ubuntu:~$ mkdir -p /tmp/test
mkdir: cannot create directory âÂÂ/tmp/testâÂÂ: File exists
add a comment |Â
up vote
2
down vote
From https://www.gnu.org/software/coreutils/manual/html_node/mkdir-invocation.html#mkdir-invocation:
An exit status of zero indicates success, and a nonzero value indicates failure.
Failure is when the directories need to be created but the operation fails.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
To elaborate on the previous answer with a few examples.
It could be when trying to create folders inside system folders:
ubuntu:~$ mkdir /proc/test
mkdir: cannot create directory âÂÂ/proc/testâÂÂ: No such file or directory
ubuntu:~$ mkdir -p /dev/null/test
mkdir: cannot create directory âÂÂ/dev/nullâÂÂ: Not a directory
Or when you don't have permission to the previous folder:
ubuntu:~$ mkdir -p /root/test
mkdir: cannot create directory âÂÂ/rootâÂÂ: Permission denied
It will also fail if there is a file by the same name in the folder:
ubuntu:~$ touch /tmp/test
ubuntu:~$ mkdir -p /tmp/test
mkdir: cannot create directory âÂÂ/tmp/testâÂÂ: File exists
add a comment |Â
up vote
5
down vote
To elaborate on the previous answer with a few examples.
It could be when trying to create folders inside system folders:
ubuntu:~$ mkdir /proc/test
mkdir: cannot create directory âÂÂ/proc/testâÂÂ: No such file or directory
ubuntu:~$ mkdir -p /dev/null/test
mkdir: cannot create directory âÂÂ/dev/nullâÂÂ: Not a directory
Or when you don't have permission to the previous folder:
ubuntu:~$ mkdir -p /root/test
mkdir: cannot create directory âÂÂ/rootâÂÂ: Permission denied
It will also fail if there is a file by the same name in the folder:
ubuntu:~$ touch /tmp/test
ubuntu:~$ mkdir -p /tmp/test
mkdir: cannot create directory âÂÂ/tmp/testâÂÂ: File exists
add a comment |Â
up vote
5
down vote
up vote
5
down vote
To elaborate on the previous answer with a few examples.
It could be when trying to create folders inside system folders:
ubuntu:~$ mkdir /proc/test
mkdir: cannot create directory âÂÂ/proc/testâÂÂ: No such file or directory
ubuntu:~$ mkdir -p /dev/null/test
mkdir: cannot create directory âÂÂ/dev/nullâÂÂ: Not a directory
Or when you don't have permission to the previous folder:
ubuntu:~$ mkdir -p /root/test
mkdir: cannot create directory âÂÂ/rootâÂÂ: Permission denied
It will also fail if there is a file by the same name in the folder:
ubuntu:~$ touch /tmp/test
ubuntu:~$ mkdir -p /tmp/test
mkdir: cannot create directory âÂÂ/tmp/testâÂÂ: File exists
To elaborate on the previous answer with a few examples.
It could be when trying to create folders inside system folders:
ubuntu:~$ mkdir /proc/test
mkdir: cannot create directory âÂÂ/proc/testâÂÂ: No such file or directory
ubuntu:~$ mkdir -p /dev/null/test
mkdir: cannot create directory âÂÂ/dev/nullâÂÂ: Not a directory
Or when you don't have permission to the previous folder:
ubuntu:~$ mkdir -p /root/test
mkdir: cannot create directory âÂÂ/rootâÂÂ: Permission denied
It will also fail if there is a file by the same name in the folder:
ubuntu:~$ touch /tmp/test
ubuntu:~$ mkdir -p /tmp/test
mkdir: cannot create directory âÂÂ/tmp/testâÂÂ: File exists
answered May 8 at 3:23
Mikael Kjær
43638
43638
add a comment |Â
add a comment |Â
up vote
2
down vote
From https://www.gnu.org/software/coreutils/manual/html_node/mkdir-invocation.html#mkdir-invocation:
An exit status of zero indicates success, and a nonzero value indicates failure.
Failure is when the directories need to be created but the operation fails.
add a comment |Â
up vote
2
down vote
From https://www.gnu.org/software/coreutils/manual/html_node/mkdir-invocation.html#mkdir-invocation:
An exit status of zero indicates success, and a nonzero value indicates failure.
Failure is when the directories need to be created but the operation fails.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
From https://www.gnu.org/software/coreutils/manual/html_node/mkdir-invocation.html#mkdir-invocation:
An exit status of zero indicates success, and a nonzero value indicates failure.
Failure is when the directories need to be created but the operation fails.
From https://www.gnu.org/software/coreutils/manual/html_node/mkdir-invocation.html#mkdir-invocation:
An exit status of zero indicates success, and a nonzero value indicates failure.
Failure is when the directories need to be created but the operation fails.
answered May 8 at 2:53
dsstorefile1
1,516212
1,516212
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f442442%2fwhen-does-mkdir-p-path-to-dir-exist-with-nonzero-status%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Try
mkdir -p /dev/i/am/a/hacker
as non-root and see it fail. If you don't have permissions it will fail and return a non-zero value.â cylgalad
May 8 at 7:25