【 Compress Files on Linux Console 】 Step by Step Guide ▷ 2022

File compression is a great useful in reducing the space they occupy and others documents. In this way, although all the information is preserved, the size is reduced.

This happens thanks to the fact that the software in charge of this task, performs a search for repetitions within codes of each element, to later store only this series together with the times it is repeated. For example, if it appears “PPPPPPPP” (6 bytes), I would change it to 6P (2 bytes).

For his part, has since its inception, a compression tool called Tar. Over time, other software with similar functions have appeared. Yet all of them can be managed from the console. To learn more about this, we recommend the following post.

What are the benefits of compressing files with the Linux console?

As we mentioned before, all the programs created to compress files, developed for Linux perform similar functions. In addition to this, each one has own graphical interfaces where the user can interact and control the functions. There are even other tools capable of handling all of them from a single window.

However, one of the peculiarities of this system, and that makes it so interesting for users, is the ability to perform actions from the command line. This option is the most convenient for save the resources that occupy the interfaces of the programs. In the same way, considerable time can be saved, since the commands are quite simple.

Learn step by step how to compress files and folders from the Linux console

See also  【DIFFERENCES between Linux vs Windows】▷ Which is better? ▷ 2022

The programs most used by users to compress individual files are gzip, bzip2, p7zip among others. The disadvantage of many of them is that are not able to perform work on entire files. It is because of that Tar It is so important. Since it is the perfect complement to achieve this goal.

We will see below how to perform compression in both cases:

individual files

The command syntax It is very similar in all the programss of this type. For example, if we use Bzip2, to compress a file in a standard way we should write the following command. “bzip2 example.txt” Being example.txt the name of the document. This will create a new file .bz2 and will delete the original. In the case of wanting to compress different files from the same command, it is enough to name them all as follows “bzip2 example1.txt example2.txt example3.txt”.

Other possible configurations for this program are made by adding the following values ​​in the command after “bzip2”:

  • Values ​​between “-1” Y “-9” indicate the degree of compression. Being 1 the smallest. If none are added, the default value is 5.
  • “-F” overwrites the archive with the same name if it exists.
  • “-c” create the .bz2 in the standard location.
  • “-q” blocks the totality of the notifications issued by the program.
  • “-t” make a verification of the file before compressing it.
  • “-k” prevents it from being removed the original document after creating the zip.
  • “-h” opens the menu with all Available options.

complete files

The best tool to achieve this is Tar, but together with some of the others that we mentioned before. Depending on this factor, the extensions of the compressed files can be “.tar.gz(.tgz)”, “.tar.bz2 (.tbz2)”, etc. What happens in this process is that Tar It is in charge of joining all the files of the selected file without modifying them, to later compress it in the usual way by the specific program.

See also  【 Recover Deleted Emails in GMAIL 】 Step by Step Guide ▷ 2022

That is to say, if we did not use the second software, Tar it would just create an uncompressed package. To perform this action, just write the command “tar -cf filename.tar example1.txt example2.txt”.

Steps to unzip a file from the Linux console

To be able to decompress a file, it is only necessary change some values.

As we will see below:

Individual files|

Continuing with the example of bzip2it is necessary to add “-d” to command. In this way it would remain “bzip2 -d example1.txt”.

complete files

Similarly, to unpack an entire file, you need to replace “c” by “x” inside the command. So that the syntax is as follows “tar -xf filename.tar”.

Loading Facebook Comments ...
Loading Disqus Comments ...