What 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?

  • 1
    install -d might not be POSIX, but don't quote me on that.
    – phk
    Jan 25, 2017 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, 2017 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, 2017 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, 2017 at 1:23

2 Answers 2


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:


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.


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.


  1. For GNU install, the permissions of the parent directories could be different.
  2. install lets you set the ownership of the leaf directory.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .