How to pack a folder in tar.gz?

How to pack a folder in tar.gz?

In order to create an archive in linux you need to go to the folder you want to pack in the command line (terminal):

cd ./folder

Next, create an archive from the contents of the folder by running the command:

tar -czpf archive-name.tar.gz *

 The archive-name.tar.gz archive will be created inside the folder.

Or create the tar.gz archive a little differently:

tar -czpf path/archive-name.tar.gz /path/to/anyfolder

As a result, an archive will be created along the path: path/archive-name.tar.gz, in which the archived directory anyfolder will lie.

Note: in this case, the archive will contain the full structure of the tree from the root. All directories in the archive before anyfolder will be empty. And in anyfolder will be the contents of the folder.

Therefore, a more beautiful archive without an extra path can be obtained in the first way.

Well, if you have 20 subdirectories in the directory and you want to pack each of them into a separate file, what needs to be done?

You can do this:

ls /path/folder | while read bakdir; do tar zcpfv $bakdir.tar.gz /path/folder/$bakdir

So, we examined the possibilities of creating an tar.gz archive in Linux in all variants.

Вас заинтересует / Intresting for you:

Increasing SSH Session Time in...
Increasing SSH Session Time in... 272 views Андрей Васенин Mon, 22 Jun 2020, 07:28:28