I've seen the
install command used in a lot of Makefiles, and its existence and usage are kind of confusing. From the manpages, it seems like a knockoff of
cp with less features, but I assume it wouldn't be used unless it had some advantage over
cp. What's the deal?
install not only copies files but also changes its ownership and permissions and optionally removes debugging symbols from executables. It combines
strip. It's a convenient higher-level tool to that accomplishes a common sequence of elementary tasks.
An advantage of
cp for installing executables is that if the target already exists, it removes the target file and creates a new one. This gets rid of any current properties such as access control lists and capabilities, which can be seen both as an upside and as a downside. When updating executables, if there are running instances of this executable, they keep running unaffected. In contrast,
cp updates the file in place if there is one. On most Unix variants, this fails with the error EBUSY¹ if the target is a running executable; on some it can cause the target to crash because it loads code sections dynamically and modifying the file causes nonsensical code to be loaded.
¹ “Text file busy”. In this context, “text file” means “binary executable file”, for obscure historical reasons.
install command we can Copy file with desire permissions
Example which mostly use while setting up ldap
install -o ldap -g ldap /etc/openldap/DB_CONFIG_EXAMPLE /var/lib/ldap/DB_CONFIG
This save us doing
chown ldap. /var/lib/ldap/DB_CONFIG, if you copied using
cp then you also need to
chown in this scenario
See the man page for
$ man install
SYNOPSIS install [OPTION]... [-T] SOURCE DEST install [OPTION]... SOURCE... DIRECTORY install [OPTION]... -t DIRECTORY SOURCE... install [OPTION]... -d DIRECTORY... DESCRIPTION This install program copies files (often just compiled) into destination locations you choose. If you want to download and install a ready-to-use package on a GNU/Linux system, you should instead be using a package manager like yum(1) or apt-get(1). In the first three forms, copy SOURCE to DEST or multiple SOURCE(s) to the existing DIRECTORY, while setting permission modes and owner/group. In the 4th form, create all components of the given DIRECTORY(ies). Mandatory arguments to long options are mandatory for short options too.
Other useful things such as installing with specific ownership, permissions, and preserving the original files timestamps can also be achieved through the use of
-g, --group=GROUP set group ownership, instead of process' current group -m, --mode=MODE set permission mode (as in chmod), instead of rwxr-xr-x -o, --owner=OWNER set ownership (super-user only) -p, --preserve-timestamps apply access/modification times of SOURCE files to corresponding destination files