Bash Tutorial · Linux System Skills · Lesson 27 of 30

Bash Archives, Compression and Checksums

Create and extract tar.gz archives, compress files, and verify downloads with checksums.

Create a free account to save this page, take notes and track your progress. Sign in

tar

  • Create: tar -czf backup.tar.gz dir/ (c=create, z=gzip, f=file)
  • List: tar -tzf backup.tar.gz
  • Extract: tar -xzf backup.tar.gz -C target/
tar.gz round trip
mkdir -p site/css
echo "<h1>Home</h1>" > site/index.html
echo "body{}" > site/css/app.css
tar -czf site.tar.gz site
tar -tzf site.tar.gz | sort
mkdir restore && tar -xzf site.tar.gz -C restore
cat restore/site/index.html

Output

site/
site/css/
site/css/app.css
site/index.html
<h1>Home</h1>

Run this on your computer — see “Get Started” for setup.

Checksums

Verify that a download wasn't corrupted or tampered with by comparing its SHA-256 with the published value:

Verifying a checksum
echo "release 1.4.0" > app-1.4.0.bin
sha256sum app-1.4.0.bin > SHA256SUMS
sha256sum -c SHA256SUMS
echo "tampered" >> app-1.4.0.bin
sha256sum -c SHA256SUMS 2>/dev/null || echo "checksum mismatch detected"

Output

app-1.4.0.bin: OK
app-1.4.0.bin: FAILED
checksum mismatch detected

Run this on your computer — see “Get Started” for setup.

Test yourself

Which command extracts archive.tar.gz?

  1. tar -czf archive.tar.gz
  2. tar -xzf archive.tar.gz
  3. unzip archive.tar.gz
  4. gzip archive.tar.gz
Show answer

Answer: tar -xzf archive.tar.gz

Was this page helpful?