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.


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
  • 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. – Sandeep Singh May 15 '13 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 '13 at 16:32
  • I tried above command and I got " folder2/file: No such file or directory " error – Sandeep Singh May 15 '13 at 16:39
  • Does folder2 exist already? Otherwise you have to create it using mkdir before you start the loop. – Uwe May 15 '13 at 16:46
  • Its working now, Thanks Uwe for your help. I was trying to create folder2 outside of folder1 while unzipping the file. – Sandeep Singh May 16 '13 at 4:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.