What is the purpose of the 'install' command?
install
not only copies files but also changes its ownership and permissions and optionally removes debugging symbols from executables. It combines cp
with chown
, chmod
and strip
. It's a convenient higher-level tool to that accomplishes a common sequence of elementary tasks.
An advantage of install
over 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.
install
is a BSD command (added in 4.2BSD, i.e. in the early 1980s). It has not been adopted by POSIX.
¹ “Text file busy”. In this context, “text file” means “binary executable file”, for obscure historical reasons.
It provides a standardized way of manipulating a file's or directory's ownership and permissions while copying the file or creating the directory, in a single command.
With 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