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 have several txt.gz files in a directory that I would like to decompress all in one go to a bunch of .txt files without getting rid of the originals. BUT I don't want them in standard output - as would be accomplished with the -c option. Rather I want them as files in the same directory, just with file.txt type name (as might be done with gunzip -c file.txt.gz > file.txt). Might anyone have any suggestions? Thanks!!

share|improve this question

Use a simple for loop:

 for i in *.txt.gz; do zcat "$i" > "${i%.*}"; done

zcat is equivalent to gunzip -c, but shorter.

The variable $i takes the names of all *.txt.gz files in the current directory (one after the other). ${i%.*} strips the extension (.gz) from the file's name.

Note: This is bash syntax.

share|improve this answer
1  
Well, this wouldn't restore the saved mtime. If you wants that, instead allocate a temp directory and then copy the .txt.gz there and then decompress with gzip -d and then move the .txt back, repeat for each .txt.gz and then when done remove the temp directory. – Dan D. Mar 12 '13 at 19:07
    
Thank you both! – Paulina Mar 12 '13 at 19:24
2  
@DanD.: Using touch -r is much simpler. – Dennis Mar 12 '13 at 19:28

You can use p7zip instead of gunzip, it will keep your original archive files.

7za e original.txt.gz

To decompress multiple files, see @mpy's answer.


Update

As per @Dennis's comment, wrap wildcard with double quotation mark, p7zip will extract all .txt.gz files.

7za e "*.txt.gz"
share|improve this answer
1  
If you're already using 7-Zip, just do 7za e "*.txt.gz". – Dennis Mar 12 '13 at 22:26
    
@Dennis, good to know that. – LiuYan 刘研 Mar 13 '13 at 7:48

You must log in to answer this question.

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