You can compress and decompress files using the terminal or a GUI. In this tutorial I will show you several programs to do this.

Table of Contents

tar

With tar you can compress and decompress files with the “tar”, “tar.gz” and “tar.xz” formats. The difference between “tar” and others is “tar” is not a compress format, but an “archive” (like a folder). Depending on the version of tar, you can add the parameters without a hyphen (tar cf instead of tar -cf).

  • Create a tar archive file
    tar -cf <filename>.tar <files>
    
    tar -cf test.tar image.jpg
    tar -cf folder.tar folder/
    
  • Extract a tar file
    tar -xf <filename>.tar
    
  • Extract only one file from a tar archive.
    tar -xf <filename>.tar file
    
  • Create a tar.gz file
    tar -czf <filename>.tar.gz <files>
    
  • Extract a tar.gz file
    tar -xzf <filename>.tar.gz
    
  • Create a tar.xz file
    tar -cJf <filename>.tar.xz <files>
    
  • Extract a tar.xz file
    tar -xJf <filename>.tar.xz
    
  • List contents inside a tar file
    tar -tf <filename>.tar
    

More parameters:

  • --one-top-level: when extracting a file, create a folder for extracted files (with the name of the file).
  • -p: preserve files permissions (use it when creating and extracting a tar)

zip

Compress files with the “zip” format.

zip <filename>.zip <files>
# or
zip <filename> <files>
# Compress more
zip -9 <filename>.zip <files>

More parameters:

  • -r: recursive, go into directories.

unzip

Decompress “zip” files:

unzip <filename>.zip

Options for unzip:

  • -l: list files in compressed file.
  • -d <folder>: extract files in the specified folder (it will create the folder if it doesn’t exist).

gzip, gunzip

Compress a file:

gzip file

Decompress a file:

gzip -d file.gz
# or
gunzip file.gz

xz

Compress a file:

xz file

Decompress a file:

xz -d rootfs.xz

iso-info and iso-read (extract files from ISO)

List ISO contents:

iso-info -i file.iso -f

Extract a file:

iso-read -i file.iso -e /images/rootfs.xz -o rootfs.xz

File Roller (GUI)

Default Archive Manager for GNOME (package name is file-roller).

File Roller window

Ark (GUI)

Default KDE app for archiving.

Ark window

Test with this online terminal:

If you have any suggestion, feel free to contact me via social media or email.