Compress files and folders in Linux: all the ways

Install the necessary programs

Although some distributions may come with software to work with compressed files installed as standard, it is possible that, when trying to access them, they are not installed on the PC. Therefore, before starting to work with this type of file, we are going to see how we can install the most used programs for this task.


The first of the tools that we are going to see is ZIP. This is a tool specially designed to be used from the terminal, so in order to work with it, we must have some knowledge of how to execute commands within a Linux operating system. To install it on a Debian or Ubuntu-based distro, we will have to execute the following command:

sudo apt install zip

If what we want is to use it in CentOS or Fedora, then the command will be:

sudo yum install zip

En Arch Linux o Manjaro:

sudo pacman -S zip

And finally, in OpenSUSE, we will execute:

sudo zypper install zip

And it is possible that, to unzip, we have to install an additional tool, unzip, which we can also download from the main software repositories in the following way (adjusting the command to our distro and our package manager):

sudo apt install unzip


The format RAR, Roshal Archive, is also another of the most popular formats that we can find when downloading and opening all kinds of compressed files on the Internet. This format stands out for having better security measures and an algorithm that allows us to reduce the size of the files even more. To install it on a Debian or Ubuntu-based distro, what we must do is execute the following commands:

sudo apt install rar sudo apt install unrar

In any other distro, we must download the package from the WinRAR website and run the following commands to compile and install it:

gzip -dc rarlinux-X.X.X.tar.gz | tar -xvf - cd rar make install cd .. rm -R rar


And, of course, we couldn’t forget about another of the best tools for working with compressed files: 7Zip. This completely free and open source compressor will allow us to easily work with all kinds of compressed files without any problem. To install it, we must execute the following command in our terminal:

sudo apt install p7zip-full p7zip-rar

Or, if we use a different distro not based on Debian or Ubuntu, we will use the corresponding package manager.

How to compress files

To compress files on Linux using the zip tool, what we must do is launch it, with the “-r” parameter, first specifying the name of the output file (that is, the name we want the compressed file to have) and, immediately afterwards, the files or folders we want to include inside that package. The format of the command that we must execute will be the following:

zip -r archivo_comprimido carpeta1 carpeta 2 archivo1

If, after “-r” we add the parameter “-Z” we will be able to specify the compression method that we want to use. For example, to compress a file using “bzip2”, the command would be as follows:

zip -r -Z bzip2 archivo_comprimido carpeta1 carpeta 2 archivo1

And we will also be able to adjust, if we want, the level of data compression. The higher this level, the smaller the files will take up (although they will take longer to compress and extract). This level is valued from 0 to 9 (0 being only packed, without compression, 6 being the standard value, and 9 being the maximum compression) and the command would be as follows:

zip -9 -r archivo_comprimido carpeta1 carpeta 2 archivo1

In the case of use RAR in Linux, the command that we must execute in our system is the following, using the letter “a” as a parameter, specifying the name of the output file, and the files or folders that we want to include:

rar a archivo_comprimido.rar archivo1

And, if we want to compress all the files inside a folder or directory in a package, then what we have to do is execute the following:

rar a archivo_comprimido.rar *

Third, if the program we want to use is the 7zip compressor, the process is practically the same. We simply have to specify the “a” parameter, followed by the name of the file that we want to generate and, finally, the files that we want to include. Thus, we will have the following:

7z a archivo_comprimido archivo1 carpeta1 archivo 2

Unzip files on Linux

Just like to compress we use the command “zip”, to unzip we will have to do it with the “unzip” command. This command is used in a very simple way, and it is that, to extract all the files that are inside a package, it will be enough to execute this command, followed by the file in question, so that the tool takes care of copying them to the current directory:


In case we have opted for RAR, specifically the decompression part UNRAR, the command that we will have to execute to be able to extract the files inside a RAR file (or in any other compatible format) will be the following:

unrar x archivo.rar

And we can also specify the path where we want to unzip the files by adding it to the end as follows:

unrar x archivo.rar /ruta/ruta/ruta

If the program we have installed is 7Zip, then the command that we must execute to extract these files will be the following (changing the name of the file by its corresponding name):

7z e archivo.7z

If we prefer, we can also use the graphical interface of this program to decompress the files without having to execute commands on our system.

And with graphical interface?

If we don’t finish defending ourselves well with commands, we will also be able to compress and decompress files using different graphical interfaces. In the case of Ubuntu, on the desktop GNOME, we will be able to compress files by selecting all of them, right-clicking, and choosing the compress option. And, to decompress, we will simply have to double click on the ZIP file to open it and be able to extract the data.

In the case of 7ZIP, the interface will be the typical one that we can find in other operating systems, allowing us to both open files from this interface and create our own compressed files quickly and easily.

Finally, indicate that RAR, for its part, does not have a graphical interface in Linux.

Leave a comment

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