Skip to content

tar/gzip/zstd🔗

Back

tar (tape archive)🔗

used to bundle files into a single archive

Basic Usage🔗

1. Create and Archive🔗

tar -cvf archive.tar file1 file2
  • -c: create archive
  • -v: verbose output
  • -f: specify archive filename

2. Extract an Archive🔗

tar -xvf archive.tar
  • -x: Extract files
  • files are extracted into current directory by default

3. List Archive Contents🔗

tar -tvf archive.tar

Common Scenarios🔗

  1. Extract to a Specific Directory

    tar -xvf archive.tar -C /path/to/dir
    
  2. Create and archive from a Directory

    tar -cvf archive.tar /path/to/dir
    
  3. Exclude file

    tar -cvf archive.tar --exclude="*.log" /path/to/dir
    
  4. Extracting only txt files

    tar -xvf archive.tar --wildcards "*.txt"
    
  5. Combine with find archive specific files

    find . -name "*.txt" | tar -cvf archive.tar -T -
    

gzip🔗

Compress files using .gz format

Basic Usage🔗

1. Compress a file🔗

gzip file.txt

2. Decompress a file🔗

gzip -d file.txt.gz

3. Compress and Archive🔗

tar -czvf archive.tar.gz file1 file2

4. Extract .tar.gz🔗

tar -xzvf archive.tar.gz

5. View Compressed files without extraction🔗

zcat file.txt.gz
  • Use gunzip as an alias for gzip -d

Zstd (Z Standard)🔗

A modern compression tool with better speed and ratios

Basic Usage🔗

1. Compress a File🔗

zstd file.txt

2. Decompress a File🔗

zstd -d file.txt.zst

3. Compress and Archive🔗

tar -cvf archive.tar.zst --zstd file1 file2

4. Extract .tar.zst🔗

tar -xvf archive.tar.zst --zstd

You can adjust compression level : zstd -19 file.txt

Use unzstd as alias for zstd -d

Comparison between gzip and zstd🔗

Tool Speed Compression Ratio Common Use Cases
gzip Medium Good General-purpose
zstd Fast Excellent Modern systems, large data

Notes🔗

  • take a look at pigz (parallel implementation of gzip)