Compress and decompress files on Linux

To compress and decompress files and folders in Linux, without having to install any additional package, one simple way is to use tar.

Compress files or folder

Simply type:

tar -zcvf <archive-name>.tar.gz <source-directory-name>

Where the arguments mean:

  • z option tells tar to compress the resulting archive using gzip, which is a commonly used compression algorithm
  • c option tells tar to create a new archive (compress)
  • v option enables verbose output, so that tar will display the names of the files as it processes them
  • f option allows you to specify the name of the resulting tar archive

Decompress a tar archive

To decompress an archive, type:

tar -xf <archive-name>.tar.gz


  • x option tells tar to extract (or unpack) the contents of the specified tar archive
  • f option specifies the name of the tar archive that should be extracted

It’s important to note that the f option must be the last option specified, and the name of the tar archive must be the last argument to the tar command.