Showing results for 
Search instead for 
Did you mean: 

rcp keeping permisions

Go to solution
Occasional Advisor

rcp keeping permisions

how to copy directories/files from one host to another keeping the original owner&permissions on the destination host?

Thanks and regards,
john kingsley
Honored Contributor

Re: rcp keeping permisions

rcp -p
Trusted Contributor

Re: rcp keeping permisions

Hi Juan

Its same like cp

rcp -p -r /etc server2:/tmp

be careful if ur copying in /etc of server2 it will overwrite without warning

Necessity breaks iron
Honored Contributor

Re: rcp keeping permisions

Hi Juan,

You can use rcp -p option to preserve permission.

-p The -p option causes rcp to attempt to preserve (duplicate) in its
copies the modification times and modes of the source files, ignor-
ing the umask. By default, the mode and owner of file2 are pre-
served if it already existed; otherwise the mode of the source file
modified by the umask(2) on the destination host is used.

"A ship in the harbor is safe, but that is not what ships are built for"
A. Clay Stephenson
Acclaimed Contributor

Re: rcp keeping permisions

The -p option only preserves the mode and modification times; it does nothing to preserve ownership/group. Ownership/group of newly created files is determined by the effective UID/GID of the current user.

If you want to preserve all attributes then you should use a different mechanism (cpio; tar; or follow each copy with explicit commands).
If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: rcp keeping permisions

Hi Juan:

As usual, the manpages offer you the quickest, and often most complete, answer :-)


Honored Contributor

Re: rcp keeping permisions

Rcp is not going to do it, as said in a previous post, it will keep permissions, but not ownership. I generally use tar for this, you can use remsh (rsh), or even better ssh.

from source server:

cd /sourcedir
tar cvf - . | remsh destination_server "cd /destdir ; tar xvf - "

Better yet, through ssh (similar)
from source server:

cd /sourcedir
tar cvf - . | ssh destination_server "cd /destdir ; tar xvf - "

If you're on Linux, you can compress across the pipe easily...

cd /sourcedir
tar cvzf - . | ssh destination_server "cd /destdir ; tar xvzf - "

If you're on HPUX and you want to compress across the pipe...

cd /sourcedir
tar cvf - . | compress | ssh destination_server "cd /destdir ; uncompress | tar xvf - "

Your results with compression probably will vary, some things will be faster using it, while others wont. The big thing here is, using tar you will preserve your file ownerships, permissions, etc.

ONE MORE caveat - if you are sending over special files (e.g. device files), you'll need to use cpio, or perhaps gnu tar instead of HPUX tar.

We are the people our parents warned us about --Jimmy Buffett