What's the difference between `mkdir -p` and `install -d`?











up vote
3
down vote

favorite
2












What, precisely, is the difference in what is being performed by mkdir -p and install -d, in terms of what changes the two commands are doing to the system?










share|improve this question




















  • 1




    install -d might not be POSIX, but don't quote me on that.
    – phk
    Jan 25 '17 at 23:13






  • 1




    At least in busybox by comparing mkdir.c and install.c you see that there is some difference when it comes to handling file modes, in latter (install) the folders are apparently first created with a hardcoded file mode of 0755 and only later set to a different value. (Some sort of workaround for certain GNU coreutils versions? Can someone more knoledgable please explain?) Also in latter the user and group ID can be specifically set. I ignored SELINUX.
    – phk
    Jan 25 '17 at 23:28












  • Does it trouble you that there might be more than one way of doing the same thing in UNIX/Linux?
    – mdpc
    Jan 26 '17 at 1:03










  • @mdpc, No, I just want to learn the difference, if any. Do they really do the exact same thing?
    – Alexander
    Jan 26 '17 at 1:23















up vote
3
down vote

favorite
2












What, precisely, is the difference in what is being performed by mkdir -p and install -d, in terms of what changes the two commands are doing to the system?










share|improve this question




















  • 1




    install -d might not be POSIX, but don't quote me on that.
    – phk
    Jan 25 '17 at 23:13






  • 1




    At least in busybox by comparing mkdir.c and install.c you see that there is some difference when it comes to handling file modes, in latter (install) the folders are apparently first created with a hardcoded file mode of 0755 and only later set to a different value. (Some sort of workaround for certain GNU coreutils versions? Can someone more knoledgable please explain?) Also in latter the user and group ID can be specifically set. I ignored SELINUX.
    – phk
    Jan 25 '17 at 23:28












  • Does it trouble you that there might be more than one way of doing the same thing in UNIX/Linux?
    – mdpc
    Jan 26 '17 at 1:03










  • @mdpc, No, I just want to learn the difference, if any. Do they really do the exact same thing?
    – Alexander
    Jan 26 '17 at 1:23













up vote
3
down vote

favorite
2









up vote
3
down vote

favorite
2






2





What, precisely, is the difference in what is being performed by mkdir -p and install -d, in terms of what changes the two commands are doing to the system?










share|improve this question















What, precisely, is the difference in what is being performed by mkdir -p and install -d, in terms of what changes the two commands are doing to the system?







c coreutils






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 27 at 17:31

























asked Jan 25 '17 at 23:03









Alexander

5,78822043




5,78822043








  • 1




    install -d might not be POSIX, but don't quote me on that.
    – phk
    Jan 25 '17 at 23:13






  • 1




    At least in busybox by comparing mkdir.c and install.c you see that there is some difference when it comes to handling file modes, in latter (install) the folders are apparently first created with a hardcoded file mode of 0755 and only later set to a different value. (Some sort of workaround for certain GNU coreutils versions? Can someone more knoledgable please explain?) Also in latter the user and group ID can be specifically set. I ignored SELINUX.
    – phk
    Jan 25 '17 at 23:28












  • Does it trouble you that there might be more than one way of doing the same thing in UNIX/Linux?
    – mdpc
    Jan 26 '17 at 1:03










  • @mdpc, No, I just want to learn the difference, if any. Do they really do the exact same thing?
    – Alexander
    Jan 26 '17 at 1:23














  • 1




    install -d might not be POSIX, but don't quote me on that.
    – phk
    Jan 25 '17 at 23:13






  • 1




    At least in busybox by comparing mkdir.c and install.c you see that there is some difference when it comes to handling file modes, in latter (install) the folders are apparently first created with a hardcoded file mode of 0755 and only later set to a different value. (Some sort of workaround for certain GNU coreutils versions? Can someone more knoledgable please explain?) Also in latter the user and group ID can be specifically set. I ignored SELINUX.
    – phk
    Jan 25 '17 at 23:28












  • Does it trouble you that there might be more than one way of doing the same thing in UNIX/Linux?
    – mdpc
    Jan 26 '17 at 1:03










  • @mdpc, No, I just want to learn the difference, if any. Do they really do the exact same thing?
    – Alexander
    Jan 26 '17 at 1:23








1




1




install -d might not be POSIX, but don't quote me on that.
– phk
Jan 25 '17 at 23:13




install -d might not be POSIX, but don't quote me on that.
– phk
Jan 25 '17 at 23:13




1




1




At least in busybox by comparing mkdir.c and install.c you see that there is some difference when it comes to handling file modes, in latter (install) the folders are apparently first created with a hardcoded file mode of 0755 and only later set to a different value. (Some sort of workaround for certain GNU coreutils versions? Can someone more knoledgable please explain?) Also in latter the user and group ID can be specifically set. I ignored SELINUX.
– phk
Jan 25 '17 at 23:28






At least in busybox by comparing mkdir.c and install.c you see that there is some difference when it comes to handling file modes, in latter (install) the folders are apparently first created with a hardcoded file mode of 0755 and only later set to a different value. (Some sort of workaround for certain GNU coreutils versions? Can someone more knoledgable please explain?) Also in latter the user and group ID can be specifically set. I ignored SELINUX.
– phk
Jan 25 '17 at 23:28














Does it trouble you that there might be more than one way of doing the same thing in UNIX/Linux?
– mdpc
Jan 26 '17 at 1:03




Does it trouble you that there might be more than one way of doing the same thing in UNIX/Linux?
– mdpc
Jan 26 '17 at 1:03












@mdpc, No, I just want to learn the difference, if any. Do they really do the exact same thing?
– Alexander
Jan 26 '17 at 1:23




@mdpc, No, I just want to learn the difference, if any. Do they really do the exact same thing?
– Alexander
Jan 26 '17 at 1:23










2 Answers
2






active

oldest

votes

















up vote
5
down vote













For starters, mkdir -p is POSIX, install is not. Then, we have this from the GNU install documentation:




If the --directory (-d) option is given, install creates each
directory and any missing parent directories. Parent directories are created with mode ‘u=rwx,go=rx’ (755), regardless of the -m option
or the current umask. See Directory Setuid and Setgid, for how
the set-user-ID and set-group-ID bits of parent directories are
inherited.




And:




-d

--directory

Create any missing parent directories, giving them the default
attributes. Then create each given directory, setting their owner,
group and mode as given on the command line or to the defaults.




So:




  1. For GNU install, the permissions of the parent directories could be different.


  2. install lets you set the ownership of the leaf directory.






share|improve this answer



















  • 1




    Point 2 should be ownership. After all, mkdir has an -m option.
    – JdeBP
    Jan 26 '17 at 7:47


















up vote
5
down vote



accepted










The main difference between mkdir -p and install -d is that if the directory already exists, only install -d will try to set the ownership and file mode bits.





  • install -d will call make_dir_parents with preserve_existing set to false


  • mkdir -p will call make_dir_parents with preserve_existing set to true.


If preserve_existing is true and the directory already exists, the function will not attempt to set the ownership and file mode bits.



mkdir -p and install -d in coreutils call the exact same make_dir_parents function.



Coreutil sources:




  • mkdir.c

  • install.c






share|improve this answer























  • Your answer is backwards. The sources you linked show preserve_existing to be the other way around and I have confirmed that by trying it out.
    – Chewi
    Nov 21 at 17:05










  • Thank you! Corrected the answer.
    – Alexander
    Nov 21 at 18:45











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f340169%2fwhats-the-difference-between-mkdir-p-and-install-d%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote













For starters, mkdir -p is POSIX, install is not. Then, we have this from the GNU install documentation:




If the --directory (-d) option is given, install creates each
directory and any missing parent directories. Parent directories are created with mode ‘u=rwx,go=rx’ (755), regardless of the -m option
or the current umask. See Directory Setuid and Setgid, for how
the set-user-ID and set-group-ID bits of parent directories are
inherited.




And:




-d

--directory

Create any missing parent directories, giving them the default
attributes. Then create each given directory, setting their owner,
group and mode as given on the command line or to the defaults.




So:




  1. For GNU install, the permissions of the parent directories could be different.


  2. install lets you set the ownership of the leaf directory.






share|improve this answer



















  • 1




    Point 2 should be ownership. After all, mkdir has an -m option.
    – JdeBP
    Jan 26 '17 at 7:47















up vote
5
down vote













For starters, mkdir -p is POSIX, install is not. Then, we have this from the GNU install documentation:




If the --directory (-d) option is given, install creates each
directory and any missing parent directories. Parent directories are created with mode ‘u=rwx,go=rx’ (755), regardless of the -m option
or the current umask. See Directory Setuid and Setgid, for how
the set-user-ID and set-group-ID bits of parent directories are
inherited.




And:




-d

--directory

Create any missing parent directories, giving them the default
attributes. Then create each given directory, setting their owner,
group and mode as given on the command line or to the defaults.




So:




  1. For GNU install, the permissions of the parent directories could be different.


  2. install lets you set the ownership of the leaf directory.






share|improve this answer



















  • 1




    Point 2 should be ownership. After all, mkdir has an -m option.
    – JdeBP
    Jan 26 '17 at 7:47













up vote
5
down vote










up vote
5
down vote









For starters, mkdir -p is POSIX, install is not. Then, we have this from the GNU install documentation:




If the --directory (-d) option is given, install creates each
directory and any missing parent directories. Parent directories are created with mode ‘u=rwx,go=rx’ (755), regardless of the -m option
or the current umask. See Directory Setuid and Setgid, for how
the set-user-ID and set-group-ID bits of parent directories are
inherited.




And:




-d

--directory

Create any missing parent directories, giving them the default
attributes. Then create each given directory, setting their owner,
group and mode as given on the command line or to the defaults.




So:




  1. For GNU install, the permissions of the parent directories could be different.


  2. install lets you set the ownership of the leaf directory.






share|improve this answer














For starters, mkdir -p is POSIX, install is not. Then, we have this from the GNU install documentation:




If the --directory (-d) option is given, install creates each
directory and any missing parent directories. Parent directories are created with mode ‘u=rwx,go=rx’ (755), regardless of the -m option
or the current umask. See Directory Setuid and Setgid, for how
the set-user-ID and set-group-ID bits of parent directories are
inherited.




And:




-d

--directory

Create any missing parent directories, giving them the default
attributes. Then create each given directory, setting their owner,
group and mode as given on the command line or to the defaults.




So:




  1. For GNU install, the permissions of the parent directories could be different.


  2. install lets you set the ownership of the leaf directory.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 26 '17 at 7:50

























answered Jan 26 '17 at 1:31









muru

35.2k581155




35.2k581155








  • 1




    Point 2 should be ownership. After all, mkdir has an -m option.
    – JdeBP
    Jan 26 '17 at 7:47














  • 1




    Point 2 should be ownership. After all, mkdir has an -m option.
    – JdeBP
    Jan 26 '17 at 7:47








1




1




Point 2 should be ownership. After all, mkdir has an -m option.
– JdeBP
Jan 26 '17 at 7:47




Point 2 should be ownership. After all, mkdir has an -m option.
– JdeBP
Jan 26 '17 at 7:47












up vote
5
down vote



accepted










The main difference between mkdir -p and install -d is that if the directory already exists, only install -d will try to set the ownership and file mode bits.





  • install -d will call make_dir_parents with preserve_existing set to false


  • mkdir -p will call make_dir_parents with preserve_existing set to true.


If preserve_existing is true and the directory already exists, the function will not attempt to set the ownership and file mode bits.



mkdir -p and install -d in coreutils call the exact same make_dir_parents function.



Coreutil sources:




  • mkdir.c

  • install.c






share|improve this answer























  • Your answer is backwards. The sources you linked show preserve_existing to be the other way around and I have confirmed that by trying it out.
    – Chewi
    Nov 21 at 17:05










  • Thank you! Corrected the answer.
    – Alexander
    Nov 21 at 18:45















up vote
5
down vote



accepted










The main difference between mkdir -p and install -d is that if the directory already exists, only install -d will try to set the ownership and file mode bits.





  • install -d will call make_dir_parents with preserve_existing set to false


  • mkdir -p will call make_dir_parents with preserve_existing set to true.


If preserve_existing is true and the directory already exists, the function will not attempt to set the ownership and file mode bits.



mkdir -p and install -d in coreutils call the exact same make_dir_parents function.



Coreutil sources:




  • mkdir.c

  • install.c






share|improve this answer























  • Your answer is backwards. The sources you linked show preserve_existing to be the other way around and I have confirmed that by trying it out.
    – Chewi
    Nov 21 at 17:05










  • Thank you! Corrected the answer.
    – Alexander
    Nov 21 at 18:45













up vote
5
down vote



accepted







up vote
5
down vote



accepted






The main difference between mkdir -p and install -d is that if the directory already exists, only install -d will try to set the ownership and file mode bits.





  • install -d will call make_dir_parents with preserve_existing set to false


  • mkdir -p will call make_dir_parents with preserve_existing set to true.


If preserve_existing is true and the directory already exists, the function will not attempt to set the ownership and file mode bits.



mkdir -p and install -d in coreutils call the exact same make_dir_parents function.



Coreutil sources:




  • mkdir.c

  • install.c






share|improve this answer














The main difference between mkdir -p and install -d is that if the directory already exists, only install -d will try to set the ownership and file mode bits.





  • install -d will call make_dir_parents with preserve_existing set to false


  • mkdir -p will call make_dir_parents with preserve_existing set to true.


If preserve_existing is true and the directory already exists, the function will not attempt to set the ownership and file mode bits.



mkdir -p and install -d in coreutils call the exact same make_dir_parents function.



Coreutil sources:




  • mkdir.c

  • install.c







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 at 18:45

























answered Jan 26 '17 at 10:26









Alexander

5,78822043




5,78822043












  • Your answer is backwards. The sources you linked show preserve_existing to be the other way around and I have confirmed that by trying it out.
    – Chewi
    Nov 21 at 17:05










  • Thank you! Corrected the answer.
    – Alexander
    Nov 21 at 18:45


















  • Your answer is backwards. The sources you linked show preserve_existing to be the other way around and I have confirmed that by trying it out.
    – Chewi
    Nov 21 at 17:05










  • Thank you! Corrected the answer.
    – Alexander
    Nov 21 at 18:45
















Your answer is backwards. The sources you linked show preserve_existing to be the other way around and I have confirmed that by trying it out.
– Chewi
Nov 21 at 17:05




Your answer is backwards. The sources you linked show preserve_existing to be the other way around and I have confirmed that by trying it out.
– Chewi
Nov 21 at 17:05












Thank you! Corrected the answer.
– Alexander
Nov 21 at 18:45




Thank you! Corrected the answer.
– Alexander
Nov 21 at 18:45


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f340169%2fwhats-the-difference-between-mkdir-p-and-install-d%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Morgemoulin

Scott Moir

Souastre