If you're copying a file on a Unix / Linux / OS X operating system, use the
cp command. Use
cp -r to copy a directory and
all its contents - the
-r means "recursive". If you use the
cp command to copy files that you have read access to, but do not own, then you'll be made the owner of the new copies; for the command to do otherwise would have security implications.
So what if you need to copy whole directory structure and
retain the current user and group assignments? First, you'll need to log in as the system administrator (root). Use the
su - command and be careful!
Once you're logged in as root, change to the directory that's above the one you wish to copy, and copy via the
tar command. For example, to copy everything in /home to /second/home:
cd /
mkdir /second
tar cpf - home | (cd second; tar xpf -)
The tar utility is more often used to make an archive file containing all of the information in a directory or series of directorys.
• Specified with the
c parameter, tar
creates an archive and with the
x parameter, it e
xtracts from an archive
• With the
f - option, tar is instructed to write to
stdout or read from
stdin.
• The
p option preserves ownerships on extraction, to prevent all of the files being changed to the ownership of the person running the command ... and for reasons of inter-user security, this only works for root.
(written 2006-04-28 08:53:01)
Associated topics are indexed under
A162 - Web Application Deployment - Backups and File System ManagementA101 - Web Application Deployment - Linux -An Introduction For Users
Some other Articles
A story of goldfishMay day awayDisc PartitioningErin Brent - rest in peaceCopying files and preserving ownershipIterators - expressions tha change each time you call themMinature Cyclists only - limited headroomAs I walked in to OxfordExtremes costs of getting on lineCatch up weekend