Compressing and decompressing files
Linux Command Line Quick Reference
1 min read
This section is 1 min read, full guide is 20 min read
Published Aug 18 2026
19
Show sections list
0
Log in to enable the "Like" button
0
Guide comments
0
Log in to enable the "Save" button
Respond to this guide
Guide Sections
Guide Comments
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.zipgzip normally replaces the source with the compressed file. -k keeps the original. ZIP support is provided by the zip and unzip packages.