Howto pipe: cp | tar | gzip without creating intermediary files?
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
It depends on your version of tar
If you have the version that supports member transforms (--transform or --xform) then you can simply do
tar -c --transform=s/A/B/ A | gzip -9 > B.tar.gz
the | gzip -9 >B.tar.gz can be avoided if your tar supports the -z option
tar -zcvf B.tar.gz --transform=s/A/B/ A
If your version of tar doesn't support --transform then you will have to just copy the file first eg
cp A B && tar -zcvf B.tar.gz B
However if you are only compressing one file why not skip the tar part all together and just do
cat A | gzip -9 > B.gz