Linux provides various utilities to compress and combine files, with the
tar command being one of the most commonly used.
tar stands for "tape archive", and is a versatile utility for creating and manipulating compressed archive files. It is a powerful tool that can be used for a variety of tasks, from creating backups of important files to compressing multiple files into a single archive.
The basic syntax of the tar command is as follows:
tar [options] archive_name files_or_directories
options are the various flags that can be used to modify the behavior of the command, such as
-c for creating a new archive,
-x for extracting files from an archive, and
-z for compressing or decompressing an archive using gzip.
archive_name is the name of the archive file that will be created or operated on, and
files_or_directories is a list of one or more files or directories that will be included in the archive.
For example, to create a new tarball of a directory called
my_folder, you could use the following command:
tar -czvf my_folder.tar.gz my_folder/
-c flag indicates that a new archive should be created, the
-z flag specifies that the archive should be compressed with gzip, the
-v flag enables verbose output so that the user can see which files are being added to the archive, and the
f flag specifies the name of the archive file.
To extract the contents of the tarball, you can use the following command:
tar -xzvf my_folder.tar.gz
-x flag indicates that the files should be extracted from the archive, and the other flags have the same meanings as before.
tar command is a versatile and powerful tool that is essential for managing and manipulating archive files in Linux.
# Create archive.tar from files foo and bar. tar -cf archive.tar foo bar # List all files in archive.tar verbosely. tar -tvf archive.tar # Extract all files from archive.tar. tar -xf archive.tar # Compress directory baz into archive.tar.gz tar -czvf archive.tar.gz baz/
--create create a new archive
--list list the contents of an archive
--get extract files from an archive
--verbose verbosely list files processed
--file=ARCHIVE use archive file or device ARCHIVE
--ungzip use the gzip compression format
tar file is a file format in itself designed for tape archives. This format can then be compressed using (for example)
bzip2 compression formats. When you extract a compressed
tar file, you effectively uncompress it, then extract the original files from the uncompressed
zip tool is a completely different thing. It takes a bunch of files and combines them into a single compressed file. With totally different algorithms.
tar tool is just combining several files into a single file without any compression.
gzip tool is just compressing a single file.
If you want to have both, you just combine both tools resulting in a
For more info:
Visit the man page for
tar on your shell: