Copy Files and Change Ownership Permissions at The Same Time
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 :-
Option:-
-C (–compare) Compare each pair of source and destination files, and if the
destination has identical content and any specified owner, group,
permissions, then do not modify the destination at all.
-m (-mode=MODE) Set the file mode bits for the installed file or directory to MODE,
which can be either an octal number, or a symbolic mode as in
`chmod’. The default mode is `u=rwx,go=rx,a-s’–read, write, and
execute for the owner, read and execute for group and other.
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.
-Ashutosh