How to Create and Extract .tar.gz Files
The tar command comes preinstalled in almost every Linux distribution out there. So its naturally a utility of choice for many linux users to create compressed archives when moving files. But sometimes the additional options used to create the archive are hard to remember.
About tar (from Wiki)
In computing, tar is a computer software utility for collecting many files into one archive file, often referred to as a tarball, for distribution or backup purposes. The name is derived from “tape archive”, as it was originally developed to write data to sequential I/O devices with no file system of their own. The archive data sets created by tar contain various file system parameters, such as name, timestamps, ownership, file-access permissions, and directory organization.
Create an archive
To create a simple not compressed archive (.tar file) run:
tar -cf output_file.tar source_file
Where options:
c- stands forcreatef- is a destinationfile
Create compressed (gzip) archive
tar -czf output_file.tar.gz source_file
Additional option:
z- tells tar to use gzip
Unpack an archive
To unpack a compressed tarball run:
tar -xf source_file.tar.gz
Or if your file is not compressed:
tar -xf source_file.tar
Where options:
x- stands for extractf- is a sourcefile
You can also add -C to extract into a specific directory:
tar -xf source_file.tar -C ~/Downloads