Is mkdir -p totally safe when creating folder already exists
Clash Royale CLAN TAG#URR8PPP
up vote
7
down vote
favorite
Say I have a folder:
./folder/
Inside it there are many files and even sub-directories.
When I execute:
mkdir -p folder
I won't see any errors even warnings. so just want to confirm, is there anything lost or changed in result of this command?
mkdir
add a comment |Â
up vote
7
down vote
favorite
Say I have a folder:
./folder/
Inside it there are many files and even sub-directories.
When I execute:
mkdir -p folder
I won't see any errors even warnings. so just want to confirm, is there anything lost or changed in result of this command?
mkdir
2
The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
â Marco
Nov 14 '15 at 13:29
add a comment |Â
up vote
7
down vote
favorite
up vote
7
down vote
favorite
Say I have a folder:
./folder/
Inside it there are many files and even sub-directories.
When I execute:
mkdir -p folder
I won't see any errors even warnings. so just want to confirm, is there anything lost or changed in result of this command?
mkdir
Say I have a folder:
./folder/
Inside it there are many files and even sub-directories.
When I execute:
mkdir -p folder
I won't see any errors even warnings. so just want to confirm, is there anything lost or changed in result of this command?
mkdir
mkdir
asked Nov 14 '15 at 13:14
AGamePlayer
1,881102942
1,881102942
2
The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
â Marco
Nov 14 '15 at 13:29
add a comment |Â
2
The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
â Marco
Nov 14 '15 at 13:29
2
2
The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
â Marco
Nov 14 '15 at 13:29
The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
â Marco
Nov 14 '15 at 13:29
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
9
down vote
accepted
mkdir -p
would not give you an error if the directory already exists and the contents for the directory will not change.
Manual entry for mkdir
1
This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
â Aaron Cicali
Jul 19 '16 at 2:35
in error, you could check for the code like thisif(err.code == 'EEXIST')
this condition will get true if the directory already exists.
â user403173
Aug 2 at 6:53
add a comment |Â
up vote
11
down vote
A portable script will rely upon POSIX, which says of mkdir
's -p
option:
Each dir operand that names an existing directory shall be ignored without error.
and if there are no errors reported, the -p
option has done its job:
Create any missing intermediate pathname components.
add a comment |Â
up vote
3
down vote
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.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
9
down vote
accepted
mkdir -p
would not give you an error if the directory already exists and the contents for the directory will not change.
Manual entry for mkdir
1
This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
â Aaron Cicali
Jul 19 '16 at 2:35
in error, you could check for the code like thisif(err.code == 'EEXIST')
this condition will get true if the directory already exists.
â user403173
Aug 2 at 6:53
add a comment |Â
up vote
9
down vote
accepted
mkdir -p
would not give you an error if the directory already exists and the contents for the directory will not change.
Manual entry for mkdir
1
This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
â Aaron Cicali
Jul 19 '16 at 2:35
in error, you could check for the code like thisif(err.code == 'EEXIST')
this condition will get true if the directory already exists.
â user403173
Aug 2 at 6:53
add a comment |Â
up vote
9
down vote
accepted
up vote
9
down vote
accepted
mkdir -p
would not give you an error if the directory already exists and the contents for the directory will not change.
Manual entry for mkdir
mkdir -p
would not give you an error if the directory already exists and the contents for the directory will not change.
Manual entry for mkdir
edited Aug 26 at 14:05
Communityâ¦
1
1
answered Nov 14 '15 at 13:39
ARG
95978
95978
1
This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
â Aaron Cicali
Jul 19 '16 at 2:35
in error, you could check for the code like thisif(err.code == 'EEXIST')
this condition will get true if the directory already exists.
â user403173
Aug 2 at 6:53
add a comment |Â
1
This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
â Aaron Cicali
Jul 19 '16 at 2:35
in error, you could check for the code like thisif(err.code == 'EEXIST')
this condition will get true if the directory already exists.
â user403173
Aug 2 at 6:53
1
1
This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
â Aaron Cicali
Jul 19 '16 at 2:35
This answer does not seem to be correct. mkdir indeed emits an error if the directory exists, unless using the -p flag.
â Aaron Cicali
Jul 19 '16 at 2:35
in error, you could check for the code like this
if(err.code == 'EEXIST')
this condition will get true if the directory already exists.â user403173
Aug 2 at 6:53
in error, you could check for the code like this
if(err.code == 'EEXIST')
this condition will get true if the directory already exists.â user403173
Aug 2 at 6:53
add a comment |Â
up vote
11
down vote
A portable script will rely upon POSIX, which says of mkdir
's -p
option:
Each dir operand that names an existing directory shall be ignored without error.
and if there are no errors reported, the -p
option has done its job:
Create any missing intermediate pathname components.
add a comment |Â
up vote
11
down vote
A portable script will rely upon POSIX, which says of mkdir
's -p
option:
Each dir operand that names an existing directory shall be ignored without error.
and if there are no errors reported, the -p
option has done its job:
Create any missing intermediate pathname components.
add a comment |Â
up vote
11
down vote
up vote
11
down vote
A portable script will rely upon POSIX, which says of mkdir
's -p
option:
Each dir operand that names an existing directory shall be ignored without error.
and if there are no errors reported, the -p
option has done its job:
Create any missing intermediate pathname components.
A portable script will rely upon POSIX, which says of mkdir
's -p
option:
Each dir operand that names an existing directory shall be ignored without error.
and if there are no errors reported, the -p
option has done its job:
Create any missing intermediate pathname components.
edited Nov 14 '15 at 13:52
answered Nov 14 '15 at 13:43
Thomas Dickey
50.2k587157
50.2k587157
add a comment |Â
add a comment |Â
up vote
3
down vote
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.
add a comment |Â
up vote
3
down vote
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.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
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 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.
answered Jul 27 '17 at 14:44
Tushar Vazirani
1311
1311
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%2f242995%2fis-mkdir-p-totally-safe-when-creating-folder-already-exists%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
2
The help of mkdir says that the directories are only created when they are not present. This implies to me that when the directory exists there is nothing done.
â Marco
Nov 14 '15 at 13:29