Using Install to Copy Files and Change Ownership/Permissions at the Same Time

The little-known but still useful Install command is most commonly seen in makefiles when implementing the 'install' target (i.e., as the last part of the ubiquitous configure; make; make install sequence). You can use the install command as a convenient replacement for separate cp, chmod and chown commands in shell scripts, or just from the command line when you need to copy a file and change its ownership or permissions at the same time. It's a great tool to add to your shell-scripting arsenal.

Using Install

Usage is very simple, here is an example with some common options:

install -C -m 770 -u root -g staff backup.sh /usr/local/bin/

This will copy the file backup.sh from the current directory into /usr/local/bin, changing the permissions to 770, the owner to root, and the group to staff. The -C option compares the source file and supplied attributes (in this case permissions, owner and group) to the destination file, if it exists, and performs the copy only if they differ in some way. Note that -u implies that you are running the install command as root.

More Reading