Compressing and decompressing files

Linux Command Line Quick Reference

1 min read

Published Aug 18 2026


19
0
0
0

CLILinuxUbuntu

tar combines files into an archive. Compression can then be applied with gzip, bzip2 or xz. A .tar.gz file is therefore a tar archive compressed with gzip.

Create and extract tar archives

bash
tar -cf archive.tar directory/tar -xf archive.tartar -czf archive.tar.gz directory/tar -xzf archive.tar.gztar -cJf archive.tar.xz directory/tar -xJf archive.tar.xztar -tf archive.tar.gz

-c creates, -x extracts, -t lists contents and -f says the following argument is the archive filename. -z uses gzip and -J uses xz. -v can be added for verbose output.

To compress a single file directly:

Other compression formats

bash
gzip file.loggzip -k file.loggunzip file.log.gzxz file.logunxz file.log.xzzip -r archive.zip directory/unzip archive.zip

gzip normally replaces the source with the compressed file. -k keeps the original. ZIP support is provided by the zip and unzip packages.

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact
Linux Command Line Quick Reference | Compressing and decompressing files | SimpleSteps.guide