Archiving and extracting with Tar & Gzip Print

  • tar, extract, gzip, archiving
  • 0

Tar is the best tool to pack an archive and Gzip is the most widely used archive type when using Linux and this is a short tutorial on how to do it.


Creating a tar.gz archive


tar pczf archive.tar.gz /home/document

This command would create archive.tar.gz from all the files in found in /home/document.
p - preserving the attributes of the files
c - creating the archive
z - using gzip
f - using a file name


Extracting a tar.gz archive


tar xzf archive.tar.gz -C /home/document

This command would extract archive.tar.gz to the document folder.
x - extract command
z - extract using gzip
f - file name mentioned
C - the directory in which it should be extracted. Not adding it would make it extract it in the current directory.

Adding v (verbose) would list all the files and directories getting extracted during the process as well.

If you want to extract just one file out of the archive, you just need to add it at the end:

tar xzfv archive.tar.gz file.txt


Was this answer helpful?

« Back