0% found this document useful (0 votes)
41 views

Copy Files and Change Ownership Permissions at The Same Time

The install command can be used to copy files and change ownership and permissions at the same time. It is a convenient replacement for separate cp, chmod, and chown commands. Usage is simple, with options like -C to compare files before copying, -m to set file permissions, -u to set the user owner, and -g to set the group owner. For example, install can copy a file, set its permissions to 770, owner to root, and group to staff in one command.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Copy Files and Change Ownership Permissions at The Same Time

The install command can be used to copy files and change ownership and permissions at the same time. It is a convenient replacement for separate cp, chmod, and chown commands. Usage is simple, with options like -C to compare files before copying, -m to set file permissions, -u to set the user owner, and -g to set the group owner. For example, install can copy a file, set its permissions to 770, owner to root, and group to staff in one command.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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/

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.

-u Set User ownership

-g (–group=GROUP) Set group ownership, instead of process’ current group

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

You might also like