1

I have multiple .gz file in a folder and I want to unzip it in other folder through gunzip without deleting parent file. Please help.

1 Answer 1

7

Do you mean something like gunzip -c folder1/myfile.gz > folder2/myfile? With the -c option, gunzip keeps the original files unchanged.

If you want to do it for all .gz files in folder1, you could use

cd folder1; for f in *.gz ; do gunzip -c "$f" > ../folder2/"${f%.*}" ; done
5
  • Hi Anthon, I am trying to do the same thing what I did from unzip method: " unzip folder1/'*.gz' -d folder2 " I want to do the same thing through gunzip. May 15, 2013 at 16:26
  • 1
    gunzip does not have an option that is equivalent to unzip's -d. You have to write the loop yourself. Alternatively, copy all .gz files to the target directory and uncompress them there using gunzip *.gz.
    – Uwe
    May 15, 2013 at 16:32
  • I tried above command and I got " folder2/file: No such file or directory " error May 15, 2013 at 16:39
  • Does folder2 exist already? Otherwise you have to create it using mkdir before you start the loop.
    – Uwe
    May 15, 2013 at 16:46
  • Its working now, Thanks Uwe for your help. I was trying to create folder2 outside of folder1 while unzipping the file. May 16, 2013 at 4:50

You must log in to answer this question.

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