Linux Tar Files: Difference between revisions

From Dev Wiki
Jump to navigation Jump to search
(Create page)
 
(Update page for .xz formats)
 
Line 1: Line 1:
Tar is one form of file compression commonly used on Linux machines.
Tar is one form of file compression commonly used on Linux machines.
== Compression Types ==
There are two common forms of tar compression, {{ic | .gz}} and {{ic | .xz}}.
The {{ic | .gz}} compression format is handled by {{ic | gzip}} algorithms. Gzip was made in the 90's and has been around longer.
Meanwhile, the {{ic | .xz}} is a newer compression format that tends to compress files to smaller sizes.
Generally speaking, new files should be compressed to the {{ic | .xz}} format, while {{ic | .gz}} is still around for compatibility.


== Compress a File ==
== Compress a File ==
To compress a file, use the command:<br>
To compress a file, one of the following commands (First one is .xz format, second is gzip format.):<br>
<code>tar -czvf <name_of_archive> <path_to_file_or_directory></code><br>
{{ bc | tar -cJpvf <name_of_archive> <path_to_file_or_directory> }}
{{ bc | tar -czpvf <name_of_archive> <path_to_file_or_directory> }}
Where:
Where:
* <code><name_of_archive></code> is the name of the compressed file you'll create.
* <code><name_of_archive></code> is the name of the compressed file you'll create.
* <code><path_to_file_or_directory></code> is the path to the file or directory you wish to compress.
* <code><path_to_file_or_directory></code> is the path to the file or directory you wish to compress.
* <code>czvf</code> stands for:
* Provided flags stands for:
** c - Creates an archive (compressed file).
** c - Creates an archive (compressed file).
** J - Compresses using xz format.
** z - Compresses using gzip format.
** z - Compresses using gzip format.
** p - Preserves file permissions.
** v - Displays progress in terminal while compressing.
** v - Displays progress in terminal while compressing.
** f - Allows specification of archive name.
** f - Allows specification of archive name.
Line 15: Line 29:
== Extract a File ==
== Extract a File ==
To extract a compressed file, use the command:<br>
To extract a compressed file, use the command:<br>
<code>tar -xzvf <name_of_archive> -C <location_to_decompress_to></code>
{{ bc | tar -xvf <name_of_archive> -C <location_to_decompress_to> }}
Where:
Where:
* <code><name_of_archive></code> is the name of the compressed file you'll create.
* <code><name_of_archive></code> is the name of the compressed file you'll create.
* <code><location_to_decompress_to></code> is the path you wish to extract contents to.
* <code><location_to_decompress_to></code> is the path you wish to extract contents to.
* <code>xzvf</code> stands for:
* Provided flags stands for:
** c - Extracts an archive (compressed file).
** x - Extracts an archive (compressed file).
** z - Compression is in gzip format.
** v - Displays progress in terminal while compressing.
** v - Displays progress in terminal while compressing.
** f - Allows specification of archive name.
** f - Allows specification of archive name.
For extracting, you usually don't need to specify the compression type as it can normally determine for you. In instances where you must specify compression type, add one of the following flags:
** J - Extracts using xz format.
** z - Extracts using gzip format.

Latest revision as of 16:58, 23 May 2020

Tar is one form of file compression commonly used on Linux machines.

Compression Types

There are two common forms of tar compression, .gz and .xz.


The .gz compression format is handled by gzip algorithms. Gzip was made in the 90's and has been around longer.

Meanwhile, the .xz is a newer compression format that tends to compress files to smaller sizes.


Generally speaking, new files should be compressed to the .xz format, while .gz is still around for compatibility.

Compress a File

To compress a file, one of the following commands (First one is .xz format, second is gzip format.):

 tar -cJpvf <name_of_archive> <path_to_file_or_directory> 
 tar -czpvf <name_of_archive> <path_to_file_or_directory> 

Where:

  • <name_of_archive> is the name of the compressed file you'll create.
  • <path_to_file_or_directory> is the path to the file or directory you wish to compress.
  • Provided flags stands for:
    • c - Creates an archive (compressed file).
    • J - Compresses using xz format.
    • z - Compresses using gzip format.
    • p - Preserves file permissions.
    • v - Displays progress in terminal while compressing.
    • f - Allows specification of archive name.

Extract a File

To extract a compressed file, use the command:

 tar -xvf <name_of_archive> -C <location_to_decompress_to> 

Where:

  • <name_of_archive> is the name of the compressed file you'll create.
  • <location_to_decompress_to> is the path you wish to extract contents to.
  • Provided flags stands for:
    • x - Extracts an archive (compressed file).
    • v - Displays progress in terminal while compressing.
    • f - Allows specification of archive name.

For extracting, you usually don't need to specify the compression type as it can normally determine for you. In instances where you must specify compression type, add one of the following flags:

    • J - Extracts using xz format.
    • z - Extracts using gzip format.