Howto pipe: cp | tar | gzip without creating intermediary files

gzippipetar

Can anyone tell me if it's possible to pipe | this without having to create a physical file anywhere between A and B.tar.gz?

This is what I'm trying to do:

  1. File A
  2. Rename A to B
  3. Tar B.tar
  4. gzip -9 B.tar.gz

So for example:

cp A B | tar cvf - B | gzip -9 B.tar.gz

Best Answer

The following examples can be used to avoid creating intermediary files:

tar with gzip:

tar cf - A | gzip -9 > B.tar.gz

gzip without tar:

gzip -9c A > B.gz

tar without gzip:

tar cf B.tar A

Renaming (moving) A to B first doesn't make sense to me. If this is intended, then just put a mv A B && before either of the above commands and exchange A with B there.

Example with tar and gzip:

mv A B && tar cf - B | gzip -9 > B.tar.gz

Related Question