Extract a .tar.gz archive to a specific location in Ubuntu 12.04

How to extract a .tar.gz file to a specific folder and vice versa (create a .tar.gz file from a folder) using the ‘tar’ command from Ubuntu 12.04 command-line terminal.

 Posted April 12, 2016

To extract .tar.gz:

Usage: tar -zxvf <filename>
Usage: tar -zxvf <filename> -C <folder>

  • -z : filter the archive through gzip
  • -x : extract files from an archive
  • -v : verbosely list files processed
  • -f filename : use archive file or device ARCHIVE

Examples:

Or, to do the opposite (create .tar.gz archive from a folder):

  • -z : filter the archive through gzip
  • -c : create a new archive
  • -v : verbosely list files processed
  • -f  filename : use archive file or device ARCHIVE

To exclude specific filetypes from either of the above, you can use –exclude … the following example excludes all .mp3 and .tar.gz files:

Example to create a .tar (non .gz) file  in the current folder named test.tar, archiving the folder /home/jamesc/test

Tar usage (output of “tar –help”)

 

Leave a Reply

Your email address will not be published. Required fields are marked *