Save space by compressing files and folders in Linux

0
198

Surely more than once we have worked with compressed files or folders on our computer. A compressed file is a “package” within which several files are stored, making it much easier to share it over the Internet, and also considerably reducing its overall size. All operating systems are compatible with this type of file, although we will need the appropriate tools to be able to operate with them. And so, today we are going to see how we can work with this type of file from any Linux distro.

In Linux there are several ways to work with compressed files. The first, and one of the most used, is to open them from a terminal console. But we can also work with them from the desktop interface if we prefer. Likewise, there are several programs to be able to operate with these files, each of which is specialized in a file format (ZIP, RAR, 7Z, etc) so that, depending on the format with which we want to work, we can use one or other.

Next, we are going to see how we can work with these files, step by step.

compress files

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.

zip

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

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 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 to our package manager):

sudo apt install unzip

RAR

The RAR format, 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 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

7Zip

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 in Linux using the Zip tool, what we must do is launch it, with the “-r” parameter, specifying first the name of the output file (that is, the name we want the compressed file to have) and, act followed by the files or folders that we want to include in 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 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 (with 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 using RAR on Linux, the command that we must execute on 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 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 as we use the “zip” command to compress, we will have to do it with the “unzip” command to decompress. 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:

unzip archivo.zip

In case we have opted for RAR, specifically the UNRAR decompression part, 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 that 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 for 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 GNOME desktop, 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.

Compress files in Linux GNOME

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.

Previous articleLatest Linux Kernel Not Working Right? So you can go back
Next articleDo you have a Linux server? Protect it with these programs