Copy and chmod/chown at the same time

I have a log file owned by root that I want to copy into a directory owned by another user for him to analyse it (it must be uncompressed first).

Currently I'd have to

# cp log.xz /home/user/Documents
# chown user:user /home/user/Documents/log.xz

Is there a way to issue both commands at the same time, perhaps with one or more cp options?


Solution 1:

The cp man page does not list any options that would allow you to do this just with the CP command. If you are wanting to just issue a command and "walk away", you can put the 2 commands on 1 line separated by a ; to automatically execute the commands in sequence.

cp log.xz /home/user/Documents ; chown user:user /home/user/Documents/log.xz

Solution 2:

You might want to look at install:

install -g user -o user log.xz /home/user/Documents

install has other options suitable for installing. e.g. set mode or preserve directory structure.

Solution 3:

see map page of cp command

--preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps), if possible addi- tional attributes: context, links, xattr, all