How to compress files using the Linux terminal

The Linux terminal

In the next article I will show you the main Linux commands for compress and decompress files in the different most used formats.

Surely some other user or follower of the blog, thinks that using the terminal having programs or ways to do it graphically or assisted, is a real backwardness, but as Knowledge does not take place, and I like to know what I am doing and check different ways of doing things, here are the main commands to compress and decompress files in Linux based in Debian.

Gz files

To compress a file in gz format we will use the following command:

  • gzip -9 file

Where file is the name of the file to compress

To unzip it we will use this:

  • gzip -d file.gz

Bz2 files

This compressed extension is only capable of compressing / decompressing individual files, so don't try it with folders.

To compress we will use:

  • bzip file

To unzip:

  • bzip2 -d file.bz2

Tar.gz files

To compress a file or directory to this extension we will use the following line:

  • tar -czfv archive.tar.gz files

To unzip:

  • tar -xzvf file.tar.gz

To view the content of a file in tar.gz format:

  • tar -tzf file.tar.gz
The Linux terminal

Tar.bz2 files

To compress to this format we will use:

  • tar -c files | bzip2> file.tar.bz2

To unzip:

  • bzip2 -dc file.tar.bz2 | tar -xv
To view the content:
  • bzip2 -dc file.tar.bz2 | tar -t


Zip files

This is one of the most widespread formats in use, to compress a file to this extension from the terminal we will use the following command line:

  • zip archive.zip files
To unzip:
  •  unzip file.zip
To view the content:
  • unzip -v file.zip

Rar files

This is the most generalized and used other format or extension, to compress a file or directory to this format we will use:

  • rar -a archive.rar files
To unzip:
  • rar -x file.rar
To view the content:
  • rar -l file.rar

West:

  • rar -v file.rar

As you can see, it is not so difficult to use the terminal to do some little things from time to time, and thus while we learn, we keep the gray matter in shape.

More information - Some useful keyboard shortcuts for Ubuntu


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Shaah said

    Good article thanks I like the terminal

  2.   AyosinhoPA said

    Very interesting article. I always wondered how some packages were unzipped. Thanks and best regards.

  3.   Alex said

    Hello

    The command to compress in tar gz is tar -czvf (not tar -czfv) otherwise it fails.