With the terminal: Compress and decompress files

When working with servers, many times you need to compress or decompress files remotely using the terminal, and in many cases we don't know (or we remember) how to do it. I bring you an article that I published some time ago in my old blog, and that explains in detail how to do it.

Before compressing and decompressing with any of the following formats, make sure you have installed the compressor corresponding to the format with which we are going to work.

Tar files

Package: tar -cvf archivo.tar /dir/a/comprimir/
Unpack: tar -xvf archivo.tar
See content: tar -tf archivo.tar

Gz files

Compress: gzip -9 fichero
Decompress: gzip -d fichero.gz

Bz2 files

Compress: bzip fichero
Decompress: bzip2 -d fichero.bz2

gzip ó bzip2 they only compress files [not directories, that's why tar exists]. To compress and archive at the same time you have to combine the tar and gzip or bzip2 As follows:

Tar.gz files

Compress: tar -czfv archivo.tar.gz ficheros
Decompress: tar -xzvf archivo.tar.gz
See content: tar -tzf archivo.tar.gz

Tar.bz2 files

Compress: tar -c ficheros | bzip2 > archivo.tar.bz2
Decompress: bzip2 -dc archivo.tar.bz2 | tar -xv
See content: bzip2 -dc archivo.tar.bz2 | tar -t

Zip files

Compress: zip archivo.zip ficheros
Decompress: unzip archivo.zip
See content: unzip -v archivo.zip

Lha files

Compress: lha -a archivo.lha ficheros
Decompress: lha -x archivo.lha
See content: lha -v archivo.lha
See content: lha -l archivo.lha

Arj files

Compress: arj -a archivo.arj ficheros
Decompress: unarj archivo.arj
Decompress: arj -x archivo.arj
See content: arj -v archivo.arj
See content: arj -l archivo.arj

Zoo files

Compress: zoo -a archivo.zoo ficheros
Decompress: zoo -x archivo.zoo
See content: zoo -L archivo.zoo
See content: zoo -v archivo.zoo

Rar files

Compress: rar -a archivo.rar ficheros
Decompress: rar -x archivo.rar
See content: rar -l archivo.rar
See content: rar -v archivo.rar


6 comments, leave yours

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.   Thirteen said

    I don't know in the distros dedicated to servers, but in the desktop distributions, the packages associated with each type of compression (rar, jar, for example) are not always installed.

    If this is the case, before compressing or decompressing, install all the packages corresponding to each type of compression file.

    Greetings.

    1.    elav <° Linux said

      This is what I clarify at the beginning of the post 🙂

      1.    Thirteen said

        It's true, heh.

    2.    will crash said

      I tried various methods found on the WWW to extract a file or multipart zip file (multiple zip files) from a Google Drive download but they didn't work (well).

      I finally got it easily from the terminal like this:

      unzip filename01.zip
      when I finish extracting that part the same with the following:
      unzip filename02.zip
      and so on …

      Another way:

      7z x filename01.zip
      when I finish extracting that part the same with the following:
      7z x filename02.zip
      and so on …

      Source: https://www.lawebdelprogramador.com/foros/Linux/1720854-Como-extraer-un-fichero-zip-multiparte.html

  2.   Roberto said

    How could I unzip multiple * .tar files at the same time?

    Greetings and thanks.

  3.   camel36 said

    How could I unzip multiple * .tar files at the same time?

    Greetings and thanks.?

    run the following command

    for FILE in * .tar.gz; do tar xzvf $ FILE; done

    !!!!! free linux HONDURAS!!!