Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a directory with plenty of .txt.gz files (where the names do not follow a specific pattern.)

What is the simplest way to gunzip them? I want to preserve their original names, so that they go from whatevz.txt.gz to whatevz.txt

share|improve this question
add comment

1 Answer 1

up vote 9 down vote accepted

How about just this?

$ gunzip *.txt.gz

gunzip will create a gunzipped file without the .gz suffix and remove the original file by default (see below for details). *.txt.gz will be expanded by your shell to all the files matching.

This last bit can get you into trouble if it expands to a very long list of files. In that case, try using find and -exec to do the job for you.


From the man page gzip(1):

gunzip takes a list of files on its command line and  replaces  each  file
whose  name  ends  with  .gz, -gz, .z, -z, or _z (ignoring case) and which
begins with the correct magic number with an uncompressed file without the
original  extension.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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