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:

Deploying Linux Servers in the...
Deploying Linux Servers in the... 1056 views Mike Thu, 11 Feb 2021, 20:02:23
Understanding Linux security: ...
Understanding Linux security: ... 448 views Zero Cool Sat, 17 Jul 2021, 06:52:25
Understanding the differences ...
Understanding the differences ... 1146 views Mike Sun, 07 Feb 2021, 18:50:31
Understanding SELinux modes: d...
Understanding SELinux modes: d... 245 views Zero Cool Sat, 17 Jul 2021, 07:11:59
Log in to comment