tgz
Create compressed archive files
SYNOPSIS
tgz is a file format, not a direct command. It is handled by the tar utility.
To create a .tgz archive:
tar -czvf <archive_name>.tgz <files_or_directories_to_archive>...
To extract a .tgz archive:
tar -xzvf <archive_name>.tgz
To list contents of a .tgz archive:
tar -tzvf <archive_name>.tgz
PARAMETERS
-c, --create
Creates a new archive.
-x, --extract, --get
Extracts files from an archive.
-z, --gzip, --ungzip
Filters the archive through gzip. This is essential for .tgz files.
-v, --verbose
Verbously list files processed. Useful for seeing progress.
-f, --file=ARCHIVE
Specifies the archive file to work with. This option is typically required.
-t, --list
Lists the contents of an archive without extracting them.
-C, --directory=DIR
Change to directory DIR before performing operations. Useful for extracting to a specific location.
--exclude=PATTERN
Exclude files or directories matching PATTERN from the archive.
DESCRIPTION
The term tgz (or .tar.gz) is a common file extension for a tar archive that has been compressed using gzip. It combines the functionality of two separate tools:
tar (Tape Archive) for bundling multiple files and directories into a single archive file, preserving file permissions, ownership, and directory structures;
and gzip (GNU Zip) for compressing that archive to reduce its size. This combination is widely used in Linux and Unix-like systems for distributing software, backing up data, and packaging files for transfer. While tgz itself is not a command, it refers to the file format, and the tar command with the appropriate options (specifically the -z or --gzip flag) is used to create, extract, list, and manage these archives.
CAVEATS
tgz is a file extension and format, not an executable command itself. Operations are performed using the tar command.
Requires the gzip utility to be installed on the system for compression/decompression, though it is standard on most Linux distributions.
Archives can become very large for extensive data sets, and operations can be time-consuming.
By default, tar preserves file permissions, ownership, and timestamps. When extracting as a regular user, ownership might not be restored correctly unless extracted by `root`.
CREATING A .TGZ ARCHIVE (EXAMPLE)
To archive a directory named `my_project` into `my_project.tgz`:
tar -czvf my_project.tgz my_project/
This command will create a compressed archive in the current directory, showing the files as they are added.
EXTRACTING A .TGZ ARCHIVE (EXAMPLE)
To extract `my_project.tgz` into the current directory:
tar -xzvf my_project.tgz
To extract it into a specific directory, e.g., `/tmp/extracted_data`:
tar -xzvf my_project.tgz -C /tmp/extracted_data
This will decompress and unpack the archive, typically recreating the directory structure within.
LISTING CONTENTS OF A .TGZ (EXAMPLE)
To view the files and directories inside `my_project.tgz` without extracting:
tar -tzvf my_project.tgz
This is useful for inspecting an archive's contents before full extraction.
HISTORY
The tar utility dates back to the early days of Unix in the 1970s, originally designed for writing data to sequential I/O devices like magnetic tape drives. Its ability to bundle multiple files and directories into a single stream made it ideal for archiving and backup.
The gzip compression utility was developed by Jean-loup Gailly and Mark Adler, and first released in 1992. It became the standard compression utility in the GNU project. The combination of tar for archiving and gzip for compression quickly became a popular and efficient way to package files on Unix-like systems, leading to the widespread adoption of the .tar.gz or shorthand .tgz file format.