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 the 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