GNU Gzip examples
Last updated:Table of Contents
Compress file
$ gzip my-file.txt
Archive file is created and the original file is removed.
$ ls
file.txt.gz
Extract gz file
gunzip
is installed along with gzip
:
$ gunzip file.txt.gz
The file is extracted in the current directory and the archive file is removed:
$ ls
file.txt
Extract gz file and keep original
Use gunzip -c
$ gunzip -c file.txt.gz > file.txt
The file is extracted and the original is kept:
$ ls
file.txt.gz file.txt
Extract file to another directory
Use $ gunzip file.gz -c > path/to/extracted/file
$ gunzip file.txt.gz > foo/bar/extracted-file.txt
The original archive file is kept (showing output with tree
):
$ tree
.
├── file.txt.gz
└── foo
└── bar
└── extracted-file.txt