15
How do I create and extract .tar.gz archives on Linux from the command line?
Loading...
Q&A · Answered
How do I create and extract .tar.gz archives on Linux from the command line?
Accepted answer
# Create tar.gz archive
tar -czvf archive.tar.gz /path/to/directory
# Create tar.bz2 (better compression)
tar -cjvf archive.tar.bz2 /path/to/directory
# Exclude files
tar -czvf archive.tar.gz --exclude='*.log' /path/to/dir
# Extract tar.gz
tar -xzvf archive.tar.gz
# Extract to specific directory
tar -xzvf archive.tar.gz -C /destination/path
# List contents without extracting
tar -tzvf archive.tar.gzSay what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.