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
link|improve this question
why would you like to pipe cp A B ? – Dor Aug 5 '11 at 11:30
rename is mv. – yi_H Aug 5 '11 at 11:44
feedback

migrated from stackoverflow.com Aug 20 '11 at 2:04

This question came from our site for professional and enthusiast programmers.

1 Answer

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
link|improve this answer
I've used cp as you did in your example but rename is mv – Bob Vale Aug 5 '11 at 11:45
feedback

Your Answer

 
or
required, but never shown