Linux tar Guide - ryzendew/Linux-Tips-and-Tricks GitHub Wiki
Linux tar Guide
Complete beginner-friendly guide to tar on Linux, covering Arch Linux, CachyOS, and other distributions including creating archives, extracting files, and compression.
Table of Contents
Understanding tar
What is tar?
tar (tape archive) creates and extracts archives.
Common uses:
- Backup: Create backups
- Distribution: Package files
- Compression: Combine with compression
File formats:
.tar: Uncompressed.tar.gzor.tgz: gzip compressed.tar.bz2: bzip2 compressed.tar.xz: xz compressed
Creating Archives
Basic Archive
Create tar:
# Create archive
tar -cf archive.tar files/
# Options:
# -c: Create
# -f: File name
Compressed Archives
With compression:
# gzip compression
tar -czf archive.tar.gz files/
# bzip2 compression
tar -cjf archive.tar.bz2 files/
# xz compression
tar -cJf archive.tar.xz files/
Extracting Archives
Extract Archive
Extract:
# Extract
tar -xf archive.tar
# Extract to directory
tar -xf archive.tar -C /path/to/directory
# Extract compressed
tar -xzf archive.tar.gz
List Contents
View archive:
# List contents
tar -tf archive.tar
# Verbose list
tar -tvf archive.tar
Compression Options
Compression Levels
gzip:
# Level 1 (fast)
tar -czf archive.tar.gz --use-compress-program="gzip -1" files/
# Level 9 (best)
tar -czf archive.tar.gz --use-compress-program="gzip -9" files/
Troubleshooting
Archive Errors
Check archive:
# Test archive
tar -tf archive.tar
# Extract with verbose
tar -xvf archive.tar
Permission Errors
Fix permissions:
# Extract preserving permissions
tar -xpf archive.tar
# Or extract as root
sudo tar -xf archive.tar
Summary
This guide covered tar usage, creating and extracting archives for Arch Linux, CachyOS, and other distributions.
Next Steps
- Compression Tools - Compression tools
- Backup and Restore - Backup strategies
- tar Documentation:
man tar
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.