📅  最后修改于: 2023-12-03 15:20:28.514000             🧑  作者: Mango
tar.gz
is a compressed archive file format commonly used in Linux and Unix systems. It is a combination of two utilities: tar
and gzip
. tar
is a utility used to combine multiple files into a single archive file, while gzip
is used to compress the archive file.
Using tar.gz
files can save a lot of space while transferring or storing data. In addition, it also simplifies the process of backing up and restoring data.
In this guide, we will look at how to create, extract, and manipulate tar.gz
files using shell-bash commands.
To create a tar.gz
file, you need to use the tar
and gzip
commands together.
tar -czvf archive.tar.gz /path/to/directory/
This command will create a compressed archive file named archive.tar.gz
in the current working directory.
The -c
flag tells tar
to create a new archive file. The -z
flag tells tar
to use gzip
compression. The -v
flag is used for verbose output, which shows the progress of the operation.
To extract a tar.gz
file, you can use the following command:
tar -xzvf archive.tar.gz
This command will extract the archive file to the current working directory.
The -x
flag tells tar
to extract files from an archive. The -z
flag tells tar
to decompress the file using gzip
. The -v
flag is used for verbose output.
You can add files to an existing tar.gz
archive using the following command:
tar -czvf archive.tar.gz /path/to/new/file
This command will add the new file to the existing tar.gz
file.
To view the contents of a tar.gz
archive file, you can use the following command:
tar -ztvf archive.tar.gz
This command will display a list of files and directories included in the archive.
The -t
flag tells tar
to list the contents of the archive. The -z
flag tells tar
to decompress the file using gzip
. The -v
flag is used for verbose output.
tar.gz
files are a popular way to store and transfer files in Linux and Unix systems. Using the tar
and gzip
commands, you can create, extract, and manipulate tar.gz
files easily. It is an essential skill for any Linux or Unix system administrator or developer.