Search code examples
linuxcentos

How to gunzip without delete?


How to unzip .gz all archives without delete in specified folder?

I tried: gunzip *.gz /folder


Solution

  • Can be done with some bash scripting using gzip --stdout option and compute the uncompressed name with bash substitution:

    for i in *.gz
    do
       echo unzipping $i to /folder/${i/.gz}
       gunzip --stdout "$i" > "/folder/${i/.gz}"
    done
    

    the current implementation fails with filenames containing spaces.