For example, here is how you might copy a directory's contents from one disk to another, while preserving the dates, modes, owners and link-structure of all the files therein. In this case, the transfer medium is a pipe, which is one a Unix redirection mechanism:
$ cd sourcedir; tar -cf - . | (cd targetdir; tar -xf -)
Friday, November 18, 2005
Notable tar Usages
From the gnu.org site:
Here's a sample:
sudo tar cvzf /media/MyBook500-ext3/Volume/home-2007-10-20.tgz /home/
Copying Directory Trees with (tar | tar)
The
tar command isn't just for tape archives. It can copy files from disk to disk, too. And even if your computer has cp -r there are advantages to using tar.
Copy a Directory using tar
Another way to copy directory hierarchies is to use the tar utility, described in section 6.3.7. The following sequence of commands copies a structure from the source directory to the destination directory:
% cd source_dir; tar cf - . | (cd destination_dir; tar xfBp -)
The "-" is used for the name of the tar file (argument to the f option) so that tar writes to the standard output or reads from the standard input, as appropriate.
Subscribe to:
Posts (Atom)