How do I copy a directory while preserving links, owner id, group id and timestamps?
The GNU copy command (cp) supports the -a (archive) option which preserves as much as possible of the structure and attributes of the original files in the copy. This includes: copying symbolic links as symbolic links rather than copying the files that they point to, preserving hard link relationships between source files in the copies, preserving the original files' owner, group, permissions, and timestamps, and copying directories recursively (copying all nondirectories as if they were regular files).
% cp -a SRC_DIR DEST_DIR
The Solaris 2.5 copy command (cp) supports the -p option which preserves the owner id and group id, permissions modes, modification, access time, and ACLs if applicable. WARNING: This command won't copy links as links it copies the information the link points to.
% cp -rp SRC_DIR DEST_DIR
Another way to preserve file information and soft links when copying is by using tar.
% mkdir DEST_DIR
% cd SRC_DIR
% tar -cf - . | ( cd DEST_DIR; tar -xvf - )
Note: This can be used on most Linux systems widely available. In 1997, Linux was no where near as popular as today, so most of my production machines were Solaris.
No comments:
Post a Comment