Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Unix Guru Says: Use xtar' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Unix Guru Says: Use xtar
Authored by: forman on Apr 14, '04 07:08:09PM

By default "cp" will follow or dereference symbolic links. That is, a "cp -R" will copy the file that the link points to instead of the link. Some versions of "cp" allow the "-d" or "--no-dereference" flag to prevent this, however I got in the habit of using "tar" instead years ago:

To copy a directory I simply do this:

tar cvf - directory/ | (cd /new/location; tar xvf - )

"cvf -" means compress the directory verbosely into the file called - (standard out). The standard out is then piped ("|") into a compound command surrounded by parentheses, which first changes directories and then extracts data from standard in ("-").

What's interesting is, now that Unix and MacOS have merged, the same problem exists with resource forks being omitted by "cp -R". Thus to recursively copy a directory, preserving all links and resource forks, one can use the above command, substituting "xtar" for "tar".

To copy directories between machines, this command is exceptionally useful (substitute "xtar" if resource forks are present):

tar cvf - directory/ | ssh user@host '(cd /some/path; tar xvf - )'

Instead of all those GUI "ssh" programs, I run this from the command line daily to move files between different machines.

Michael.

[ Reply to This | # ]
Minor nit [Re: Unix Guru Says: Use xtar]
Authored by: ubi on Apr 15, '04 11:26:03PM

The -c option of tar doesn't stand for Compress, but rather for Create. Normally, tar is used for lisTing the contents of (-t), eXtracting from (-x), or Creating (-X) a tar (Tape ARchive) file. The compression flags are -z for gZip or -j for bzip2 (go figure).



[ Reply to This | # ]