I'm trying to write a makefile rule to copy a directory, maintaining its structure, and since all the other rules in our makefiles use install, I wanted to be consistent.

In the manpage, it says:


   install [OPTION]... [-T] SOURCE DEST
   install [OPTION]... SOURCE... DIRECTORY
   install [OPTION]... -t DIRECTORY SOURCE...
   install [OPTION]... -d DIRECTORY...

   -d, --directory
          treat all arguments as directory names; create all components of
          the specified directories

OK, that sounds like what I need... but the flags don't make sense. How do you specify the destination directory to install to?

I tried doing a basic test by making an arbitrary directory structure on my local hard disk:

~>tree test
├── a
│   └── b
│       └── c
│           └── e.txt
└── d

4 directories, 1 file

And then running install -d and looking at what was created:

~>install -d test test2
~>tree test2

0 directories, 0 files

Nothing happened!

Can anyone point me in the right direction? Googling "gnu install -d flag" isn't bringing me much.

3 Answers 3


It looks like the install -D command is actually what I want.


-D create all leading components of DEST except the last, then copy SOURCE to DEST

Works great, except you have to specify every file individually.

  • 9
    I was excited right up until the end, "you have to specify every file individually". Guess I'll stick with cp -r
    – dtmland
    Commented Jul 8, 2015 at 20:11
  • 9
    Does the install command have an equivalent to cp -r?
    – Alexander
    Commented Jul 8, 2016 at 10:53
  • Thanks for explaining how -D worked for you. I found the man page description confusing never having used this utility before.
    – aaaaaa
    Commented Dec 3, 2023 at 16:23

install -d is just used to create directories. You told it to create two directories, test and test2. test already existed, so all it needed to do was make test2. I don't think install supports copying entire directory trees; it's normally used on files. You probably need to use cp

  • 8
    Basically, install -d is the same as mkdir except that you can specify the mode, owner, SELinux context, and group all at once. Commented Aug 28, 2017 at 19:40
  • 3
    I would say install -d is like mkdir -p Commented Dec 17, 2019 at 6:58

Usually what you want is to install files at right folder, without repeating your self. You can use find and install to help to keep your installation scripts more DRY

find SOURCE/ -type f -exec install -vDm 755 {} THERE/{} \;
  • Wy not hust cp -r? Commented Mar 28, 2021 at 9:59
  • 1
    With install you can control mode and there are more options that cp doesn't
    – geckos
    Commented Mar 30, 2021 at 3:37
  • With the command as-is, a SOURCE/foo.txt file will be copied to THERE/SOURCE/foo.txt, which may not be what you want?
    – baltakatei
    Commented Apr 15, 2022 at 9:05
  • 2
    This command can be made to behave like cp -r if you change the working directory to SOURCE/ before running find on it and make THERE/ an absolute path: SOURCE=some_dir/; THERE=some_other_dir/; THERE="$(readlink -f "$THERE")"; pushd "$SOURCE"; find ./ -type f -exec install -vDm 0755 {} "$THERE"/{} \; ; popd;.
    – baltakatei
    Commented Apr 15, 2022 at 9:32

You must log in to answer this question.

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