A number of different file types (HTML, JSON, JS, TXT) falling into a funnel. At the bottom of the file is a single tar file, representing the compression process.
tutorials

How to create and extract tar.gz files via the command line

Compressed tar files are a mainstay of Drupal development. They enable you to easily compresss and share complex file directories via a single file; ideal for downloading and uploading modular components.

A vector drawing of Thomas Bishop's bearded and bespectacled face
Thomas
1 Oct 2018 · Drupal, command line interface
A number of different file types (HTML, JSON, JS, TXT) falling into a funnel. At the bottom of the file is a single tar file, representing the compression process.

Creating a tar.gz file

In order to create a tar.gz you will need to open up your terminal and make use of the following schema:

tar -czvf compressed-file-name.tar.gz /path/to/uncompressed/file

The flags stand for the following parameters:

-c
create an archive of the inputted file(s)
-z
compress the archive using (g)z(ip)
-v
execute in verbose mode, meaning that the terminal will display its progress in executing the command (this is an optional parameter but can prove helpful in case of error)
-f
implements the naming of the resultant file

Extracting a tar.gz file

If you are using a *nix based operating system, your tar.gz should extract automatically on opening. If not, you can use the following command which simply reverses the creation process:

tar -xzvf file.tar.gz

Here the parameters have the same meaning as above. The additional -x flag means 'extract'.


Category: tutorials Tag(s): Drupal, command line interface