← All commands
THE COMMAND REFERENCE

install

Copy files and set their permissions, or create directories.

Last updated

GNU

Implementation-level reference; examples are not certified for every installed version.

Overview

install copies a file to a place and sets its permission bits in the same step, and can create directories. It is what build scripts use to put programs into place. Unlike cp, it can set the mode with -m in one command, and with -d it makes directories.

Background

The install utility appeared in 4.2BSD, according to the macOS manual. Today the name covers GNU install, the install that macOS ships, and the install applet in BusyBox. They agree on -m for the mode and -d for directories.

Examples

Copy a file and give it the mode 644, which is read and write for the owner and read for others:

install -m 644 notes.txt copy.txt && ls -l copy.txt | cut -c1-10

Copy a program and make it executable with the mode 755:

install -m 755 notes.txt run.sh && ls -l run.sh | cut -c1-10

Create a directory and its missing parents with -d:

install -d x/y && ls -d x/y

Create a directory that only its owner can use:

install -d -m 700 pv && ls -ld pv | cut -c1-10

Options

-m
Set the permission bits of the installed file or directory, as in -m 755.

-d
Create the named directories, with any missing parents, instead of copying files.

-D
Create all missing parent directories of the destination before copying.

Common mistakes

install replaces an existing destination. The default mode is 755 even for a plain file, so give -m 644 for data. Owner and group options such as -o and -g usually need administrator rights. Unlike cp -p, install does not keep the original times unless you ask with -p.

Portability

Only -m with a file and -d are in the Common examples. GNU -D creates missing parent folders of the destination, which macOS does not do with the same option. The Common examples were executed on GNU coreutils 9.11, macOS system tools, and BusyBox 1.37.0 (see the development guide for the exact check).

About GNU install

GNU install is part of GNU coreutils, and this page's checks ran coreutils 9.11. -D creates every missing parent directory of the destination.

GNU examples

Copy a file into a folder that does not exist yet with -D:

install -D notes.txt q/r/n.txt && ls q/r

References

Original explanations, with upstream documentation for further reading. FreeBSD references are comparison material, not a claim of Apple version equivalence.