Tools‎ > ‎Ubuntu/Linux server‎ > ‎

gzip & tar.gz


# decompress single .gz file (compressed .gz file will be removed after decompression)
gzip -d sample.fastq.gz

# to view the content of a .gz file, and
zcat sample.fastq.gz

# pass content into a unix pipe (views the first 20 lines)
zcat sample.fastq.gz | head -20 

# decompress .tar.gz files
tar -zxvf samples.tar.gz

# to decompress into a pipe, extract files to standard output (option -O)
tar -zxOf samples.tar.gz | head -20   # views the first 20 lines


# compress single file gzip (original file will be removed after compression)
gzip sample.fastq

# tar archive - compress complete directory

tar -zcvf samples_compressed.tar.gz /path/to/sample/directory/

# to change gzip level used in tar archive (default compression level is 6, max level is 9)
# a) providing the compression command by option -I
tar -I 'gzip -9' -cvf samples_compressed.tar.gz /path/to/sample/directory/
# b) combine tar and gzip using a unix pipe

tar cvf - /path/to/sample/directory/  | gzip -9 > samples_compressed.tar.gz

Extract single file from tar archive

# list content (all files) of a .tar.gz archive
tar -tf samples.tar.gz

# extract selected file from .tar.gz archive
tar -zxvf samples.tar.gz sample_1.fastq