Save space by compressing files and folders on Linux

Install the necessary programs

Although some distributions may bring software to work with compressed files installed as standard, it is possible that, when trying to access them, these are not installed on the PC. Therefore, before starting to work with these types of files, let’s see how we can install the most used programs for this work.


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

On Arch Linux or Manjaro:

sudo pacman -S zip

And finally, in OpenSUSE, we will execute:

sudo zypper install zip

And it is possible that, to decompress, 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 over the Internet. This format stands out for having better security measures and an algorithm that allows us to further reduce the size of the files. To install it on a Debian or Ubuntu based distro, what we must do is run 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 execute 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 could not forget another of the best tools for working with compressed files: 7Zip. This compressor, totally free and open source, will allow us to easily work with all types 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 appropriate package manager.

How to compress files

To compress files in 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 then the files or folders we want to include inside said 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 will 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 less the files will occupy (although they will take longer to compress and extract). This level is valued from 0 to 9 (0 being only packed, without compression, 6 the standard value, and 9 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 on Linux, the command that we must execute in our system is the following, using the letter “a” as a parameter, specifying the output name of the 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 into 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 parameter “a”, followed by the name of the file we want to generate and, finally, the files we want to include. Thus, it will be as follows:

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 command «unzip». 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 is in charge 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 within 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 at 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 the 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 a graphical interface?

If we do not 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, clicking with the right button, 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 both to open files from this interface and to create our own compressed files quickly and easily.

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

Related Articles

Leave a Reply

Your email address will not be published.