Tar Archive

From KevinWiki

(Difference between revisions)
Jump to: navigation, search
(Tar Archive)
Line 17: Line 17:
$ tar -xzvf tar_file_name.tar.gz -C /directory/destination_directory
$ tar -xzvf tar_file_name.tar.gz -C /directory/destination_directory
</pre>
</pre>
 +
 +
=== Create and Split Tar File into Several Files ===
 +
* create archives
 +
<pre>
 +
$ tar cz large_file_1 large_file_2 | split -b 1024MiB - result_files.tgz_
 +
</pre>
 +
* uncompress
 +
<pre>
 +
$ cat result_files.tgz_* | tar xz
 +
</pre>
 +
 +
* This solution avoids the need to use an intermediate large file when (de)compressing.
 +
* Use the tar -C option to use a different directory for the resulting files.
 +
 +
----
 +
 +
 +
* If only one file needs to be splited, tar with a single source file is still fine but in this case, gzip can be used as well.
 +
*  create archives
 +
<pre>
 +
$ gzip -c one_large_file | split -b 1024MiB - result_files.gz_
 +
</pre>
 +
* uncompress
 +
<pre>
 +
$ cat result_files.gz_* | gunzip -c > one_large_file
 +
</pre>
 +
=== List Files Inside Tar File ===
=== List Files Inside Tar File ===

Revision as of 03:21, 8 February 2014

Contents

Tar

Tar is both a file format and the programme to handle that file.

Create GZipped Tar File

$ tar -czvf tar_file_name.tar.gz input_file_or_directory_1 input_file_or_directory_2 ...

Extract GZipped Tar File

$ tar -xzvf tar_file_name.tar.gz

To extract file to a specific directory, use this.

$ tar -xzvf tar_file_name.tar.gz -C /directory/destination_directory

Create and Split Tar File into Several Files

  • create archives
$ tar cz large_file_1 large_file_2 | split -b 1024MiB - result_files.tgz_ 
  • uncompress
$ cat result_files.tgz_* | tar xz 
  • This solution avoids the need to use an intermediate large file when (de)compressing.
  • Use the tar -C option to use a different directory for the resulting files.


  • If only one file needs to be splited, tar with a single source file is still fine but in this case, gzip can be used as well.
  • create archives
$ gzip -c one_large_file | split -b 1024MiB - result_files.gz_
  • uncompress
$ cat result_files.gz_* | gunzip -c > one_large_file


List Files Inside Tar File

$ tar -tzf tar_file_name.tar.gz

Create GZipped Tar with NOT GNU Tar

$ tar -cvf - input_file_or_directory_1 input_file_or_directory_2 | gzip > tar_file_name.tar.gz

-If gzip is not available, use compress instead.

Extract GZipped Tar with NOT GNU Tar

gunzip -c tar_file_name.tar.gz | tar -xvf -

-If gunzip is not available, user uncompress instead.

Personal tools