Compress / Decompress files

0. Requirement packages

apt install tar zip unzip gzip

1. Compress

  • Compress single file into .tar.gz

tar -zcvf telegraf-legacy.log.tar.gz telegraf.log --totals --verbose
  • Compress a directory into .tar.gz

tar -zczf monit-5.26.0.tar.gz monit-5.26.0/ --totals --verbose

After that if you want remove original file then use with option --remove-files

  • Compress single file into .gz

# From tocdo.log --> tocdo.gz (dropped original file)

gzip tocdo.log 
  • Compress single file into .zip

# From tocdo.log --> tocdo.zip (dropped original file)

zip x tocdo.log

2. Decompress

tar -xzf foo.tar.gz --totals --verbose
unzip -a x.zip

Last updated