Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am creating a tar file and then I am gzipping the tar file. So I am getting a .tgz file and now I want to delete the previous tar file.

${gzipExe} -f --rsyncable $tarname.TAR --stdout >> $tarname.TGZ
share|improve this question

migrated from stackoverflow.com Apr 6 '10 at 21:04

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

2  
Did you try rm or del? – WhirlWind Apr 6 '10 at 20:13
3  
I suggest zipping it at the same time you tar it (e.g, $ tar -cvzf filename.tar.gz) – MJB Apr 6 '10 at 20:16
    
@WhirlWind i would like to delete the tar file from the statement i use to gzip it. – superstar Apr 6 '10 at 20:25
1  
What system are you on? On any system I've used, gzip file doesn't leave the original file. – jemfinch Apr 6 '10 at 20:38
1  
@superstar Are you redirecting standard in/standard out with < and > or are your just passing the filename to gzip? – Alexandre Jasmin Apr 6 '10 at 21:00
up vote 3 down vote accepted

I usually zip the file at the same time by using the 'z' parameter with the tar command:

tar czvf allmyfiles.tar.gz *

The above command creates a new archive file called allmyfiles.tar.gz that contains all the files in the current folder, and zips it.

Otherwise, just delete the .tar file with the next command:

$rm $tarname.TAR

Note that .tar.gz is more commonly used than .tgz.

share|improve this answer

You have a couple of options. Assuming you need that --rsyncable option:

  • Compress and tar in one step (without an intermediate tar file):
REM I think you are on Windows so...
set GZIP=--rsyncable
tar czf file.tar.gz files
  • Pipe the output of tar into gzip (without an intermediate tar file)
tar c files | gzip --rsyncable > file.tar.gz
  • Archive and compress in two steps.
tar -cf file.tar files
gzip -f --rsyncable file.tar

If you simply run gzip file.tar instead of gzip --stdout file.tar > file.tar.gz gzip will delete the tar file for you.

Also note that using gzip --stdout file.tar >> file.tar.gz as in your question will actually append the new gziped contents to file.tar.gz which is probably not what you want.

share|improve this answer
    
did you intend to make this post Community Wiki? – quack quixote Apr 9 '10 at 6:37
    
@quack I know that a post becomes community wiki after the 8th edit and I was unsatisfied with the 7th. So basically yes. I did it on purpose. Feel free to edit it further ;-) – Alexandre Jasmin Apr 9 '10 at 23:17
    
i actually wasn't aware until recently that it was 8-edits-by-the-owner that made a question CW; i thought the threshold was higher. just commented to make sure there wasn't a problem. carry on! :) – quack quixote Apr 9 '10 at 23:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .