Link to home
Start Free TrialLog in
Avatar of Edgar Cole
Edgar ColeFlag for United States of America

asked on

Copying a Directory on a UNIX System

I've always preferred using the tar command instead of the cp command to copy the content of a directory on a UNIX system. That's because I found that using the cp command was unpredictable and unreliable. I know there are those who are fond of cpio. Anyway, I was just wondering whether my misgivings about the cp command are justified.
Avatar of xterm
xterm

I only encounter one real issue when using cp vs. tar, and that is that if your source directory has the same name as the destination, it will end up inside the destination directory.

So for jobs that I do repetitively, I prefer:

(cd /source/directory && tar cpf - dir1 dir2 dirX ) | (cd /dest/directory && tar xvfp -)

over:

cp -Rv /source/directory /dest/directory

But to answer your question, misgivings are much the same as preferences which means you don't have to "justify" them per se - you should use what gets the job done and poses the least stress or risk to you.
Avatar of Edgar Cole

ASKER

Hmm. I'm wondering whether tar is faster than cp.
No, tar isn't any faster - from a system standpoint, they're doing virtually the identical thing.
Avatar of phoffric
>> unpredictable and unreliable
How is it unpredictable?
How is it unreliable?
Curious - are you using NFS?

For performance considerations, if the cp is over a network and if you have 1000's of files being copied, then transmitting a tar archive, a single file, incurs less overhead than transmitting many files.
ASKER CERTIFIED SOLUTION
Avatar of Anacreo
Anacreo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial