As not everything comes with a manual, or many times it is difficult for us to find documentation for some users, especially if it is a new operating system, such is the case of Linux. If you know how to use it, the console is a very powerful tool for any user, and you don't necessarily need to be an expert, we just need to know some commands or the basics, such as the commands to compress and decompress entire directories including all the files and folders that are within these.
This applies to any Linux distribution, it could be Debian, Ubuntu, CentOS, etc.
To compress an entire directory with everything and files
We use the command:
tar -zcvf file-2080-04-01.tar.gz /home/user/folder
The resulting file will be compressed and located in the directory in which we are, for example, if we enter with the root user from the terminal, and immediately execute the previous command, the file archivo-2080-04-01.tar.gz will remain in the directory /root, which is the default directory in which we are when accessing as root user.
In order to compress a directory and choose the location we have two options:
1. The first is to navigate with the command cd
towards the directory in which we want the file to be created.
2. The second option is to change the path of the file, placing the command in the following way, using absolute paths:
tar -zcvf /home/user/file-2080-04-01.tar.gz /home/user/file
To decompress a file .tar.gz previously generated
We use the following command, from the directory where the file is located .tar.gz:
tar -zxvf file-2080-04-01.tar.gz
To choose a custom path where the files are going to be decompressed we add the parameter -C
:
tar -zxvf archivo-2080-04-01.tar.gz -C /tmp/folder
Although we can also navigate to the destination directory, and execute for example:
tar -zxvf /home/user/file-2080-04-01.tar.gz
With this all the contents of the archive will be decompressed in the current directory, regardless of whether the .tar.gz
file is elsewhere.
If you are interested, I base myself on this guide: https://www.cyberciti.biz/faq/how-do-i-compress-a-whole-linux-or-unix-directory/
Inicia sesión para comentar