Skip to content

Q&A · Answered

How to compress and extract tar.gz files on Linux

asked 9 months, 2 weeks ago 1874 views 1 answer
15

How do I create and extract .tar.gz archives on Linux from the command line?

1 Answer

One accepted
23

Accepted answer

Not confirmed since it was written, 9 months, 2 weeks ago

Create archives

# 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 archives

# 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.gz

Your answer

Say what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.

Shown beside your answer and never checked, so it cannot be a name someone already has here.

No account needed to answer. Sign in instead and it carries your name and earns reputation.