Duration: 2 hours (≈ 12 min per command). Audience: System administrators, DevOps engineers, and developers who routinely package or backup data on Linux.
gzip, bzip2, xz, lz4, zstd, and pigz.tar, zip, 7z, and ar.# Compress a single file gzip -c largefile.txt > largefile.txt.gz # Decompress gzip -d -c largefile.txt.gz > largefile-decompressed.txt # Show compression ratio gzip -l largefile.txt.gz
/var/log/syslog and note the size before/after.tar -czf (see tar below).# Compress bzip2 -k myfile.txt # -k keeps the original # Decompress bunzip2 myfile.txt.bz2 # View info bzip2 -l myfile.txt.bz2
bzip2 -9 (max compression) and compare speed vs gzip.tar -cjvf and inspect with tar -tvf.# Compress xz -z -k -9 file.txt # Decompress xz -d -k file.txt.xz # Show stats xz -l file.txt.xz
xz -9 and compare with gzip.tar -Jcvf to create an .tar.xz archive of a source tree.# Compress lz4 -k file.txt # Decompress lz4 -d file.txt.lz4 -o file-decompressed.txt # Benchmark time lz4 -k largefile.txt time gzip -k largefile.txt
lz4 -9 and measure speed vs gzip.tar --use-compress-program=lz4 -cvf to archive a directory.# Compress zstd -k -19 file.txt # Decompress unzstd -k file.txt.zst # Inspect zstd --list file.txt.zst
zstd -19 and benchmark against xz..tar.zst archive with tar --use-compress-program=zstd -cvf.# Compress using all CPUs pigz -k file.txt # Decompress pigz -d -k file.txt.gz # Compare performance time pigz -k file.txt time gzip -k file.txt
csv) with pigz and note speed improvements.pigz into a tar command: tar -cf - dir/ | pigz -c > dir.tar.gz.# Create a gzip archive tar -czvf project.tar.gz project/ # Create an xz archive tar -cJvf project.tar.xz project/ # List contents tar -tvf project.tar.gz # Extract specific file tar -xvf project.tar.gz path/to/file.txt
/etc directory and extract only hostname.tar -cvf - dir/ | split -b 100M - dir.tar.# Recursive zip zip -r archive.zip src/ docs/ # Add files zip archive.zip readme.md # List zipinfo archive.zip # Extract unzip archive.zip -d extracted/
public/) and verify that only files with .html and .css are present.zip -j to create a ZIP that contains only the file names, no paths.# Create archive with 7z 7z a -tzip -mx=9 archive.zip folder/ # Add encrypted file 7z a -pMySecret -mem=AES256 secure.7z secret.txt # List contents 7z l archive.zip # Extract 7z x archive.zip -oextracted/
-m0=BCJ2 -mx=9 and observe the size.# Create an object file gcc -c foo.c -o foo.o # Build a static lib ar rcs libfoo.a foo.o # List archive contents ar -t libfoo.a # Extract a file ar -x libfoo.a foo.o
ar -d can delete an object from the archive.# Split a large file into 50 MB pieces split -b 50M largefile.bin part_ # Reassemble cat part_* > largefile-assembled.bin # Split an archive tar -cvf - data/ | split -b 200M - data.tar.part_ # Reconstruct & extract cat data.tar.part.* | tar -xvf -
Students will write a Bash script backup.sh that:
backups/YYYYMMDD-HHMMSS.tar with -I pigz -c to archive /var/www and /etc, storing the archive as www.tgz and etc.tgz..gz archive for each log file in /var/log using gzip -9.7z a -tzip -mx=9 to produce a single backup.zip.restore.sh that can extract the archive and restore files to their original locations.Deliverables: backup.sh, restore.sh, README.md explaining the workflow, and a video demo.
/etc/nginx with tar -cJvf, splits it into 100 MB pieces, and later reassembles it.Score sheet (out of 35 points):
| Task | Points |
|---|---|
| gzip benchmark | 5 |
| bzip2 vs xz ratio comparison | 5 |
| tar archive with pigz | 5 |
| zip/unzip with filtering | 5 |
| 7z encrypted archive | 5 |
| ar static lib | 5 |
| Split & reassemble | 5 |
| Backup/restore script | 5 |