(compression)

CIS241

System-Level Programming and Utilities

Compression

Erik Fredericks, frederer@gvsu.edu
Fall 2025

Based on material provided by Erin Carrier, Austin Ferguson, and Katherine Bowers

CIS241 | Fredericks | F25 | 11-compression

How to squish (compress) a file

Windows compatible (by default) ... usually

zip file.zip files_to_compress

unzip file.zip

  • Note, not all distributions come with zip/unzip installed!
CIS241 | Fredericks | F25 | 11-compression

Compressing - Linux edition

gzip - fastest

  • gzip file
    • gunzip file.gz

bz2 - old standard, better compression

  • bzip2 file
  • bunzip2 file.bz2

xz - new standard, may not be installed

  • xz file
  • unxz file.xz
CIS241 | Fredericks | F25 | 11-compression

Compressing - directories!

Zip can handle by default

  • Others work on single files only!

So, let's tar it

  • tar -cvf name.tar file1 file2
    • Files can be directories here!

Can extract:

  • tar -xvf name.tar

Or view its table of contents:

  • tar -tvf name.tar
CIS241 | Fredericks | F25 | 11-compression

But more commonly, tar + compression!

Let's automatically compress/decompress!

  • -z for gzip
  • -j for bzip2
  • -J for xz

Ex (compress): tar -zcvf name.tar.gz dir1 dir2 file1

  • Note: toss on the common extension to tell others what type of compression is used

Ex (decompress): tar -zxvf name.tar.gz

CIS241 | Fredericks | F25 | 11-compression

mkdir newdir && tar -zxvf file.tar.gz -C newdir