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.

Is it possible to use gzip to decompress a gzipped file, without the gz extension, and without moving the file?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You can pass the -S option to use a suffix other than .gz.

gunzip -S .compressed file.compressed

If you want the uncompressed file to have some other name, run

gzip -dc <compressed-file >uncompressed-file
gunzip <compressed-file >uncompressed-file

(these commands are equivalent).

Normally unzipping restores the name and date of the original file (when it was compressed); this doesn't happen with -c.

If you want the compressed file and the uncompressed file to have the same name, you can't do it directly, you need to either rename the compressed file or rename the uncompressed file. In particular, gzip removes and recreates its target file, so if you need to modify the file in place because you don't have write permission in the directory, you need to use -c or redirection.

cp somefile /tmp
gunzip </tmp/somefile >|somefile

Note that gunzip <somefile >somefile will not work, because the gunzip process would see a file truncated to 0 bytes when it starts reading. If you could invoke the truncation, then gunzip would feed back on its own output; either way, this one can't be done in place.

share|improve this answer
add comment

You can, do something like:

gzip -d - < gzippedfilewithnoextention > ungzippedfile

Now you can't do that and uncompress to the same filename. You'll need to rename the uncompressed file afterwards (i.e. you can't in-place uncompress that way).

share|improve this answer
1  
or just "gunzip -c gzfile > ungzfile" –  Chris Card Feb 28 '12 at 15:45
    
Surprisingly enough, some OS installs have gzip but not gunzip... –  Mat Feb 28 '12 at 15:48
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.