Tar Archive

From KevinWiki

Jump to: navigation, search



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 specify a different directory for the resulting files.

  • If only one file needs to be split, 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