Monthly Archives: March 2009

Tar Cheat Sheet

Tar Segmentation

With today's increased flash storage sizes, there may not be many occasions where you need to split files. However, when you do need to do so, I find tar to be a good tool for that task (this hint is also useful if you want to split an archive before burning to DVDs).

The following use of bash's brace expansion makes creating multi-volume tar files easy. To create a multi-file archive of a given length, use this:

tar --tape-length=102400 -cMv file=tar_archive.{tar,tar-{2..100}} [files to tar]

To extract from the archive:

tar -xMv --file=tar_archive.{tar,tar-{2..100}} [files to extract]

To create DVD-sized volumes, use --tape-length=4588544. In the above examples, replace [files to tar] and [files to extract] with the location(s) of the file(s) you wish to segment.

Copying a directory

tar cf - * | ( cd /target; tar xfp -) 

Tar via ssh

tar -czf - {source-dir} | ssh {host} "(cd {target-dir}; tar xzf -)"