"Tar " is the most common file archiver used in Linux systems. Tar itself is not an archiver in the usual sense of the word, because it does not use compression on its own. At the same time, many archivers (e.g., Gzip or bzip2) do not compress multiple files, but work with a single file or input stream only. Therefore these programs are most often used together. tar creates an uncompressed archive in which the selected files and directories are placed while preserving some of their attributes (such as access rights). The resulting .tar file is then compressed with an archiver such as gzip. That is why archives usually have the extension .tar.gz or .tar.bz2* (for gzip and bzip2 archivers respectively). The whole process is started with a single console command.
How to pack tar.gz and tar.bz2
tar cfvz archive.tar.gz *.php
where tar - command, cfvz - keys, archive.tar.gz - name of the future archive, ** .php* - list of files to be archived.
The list can be replaced by the directory to be packed as a whole, to do this, specify the path to it, absolute or relative
tar cfvz archive.tar.gz /forpack
Read more about keys:
-c is the command which means "create archive"
-f - command to pack files and directories into a single archive file
-v - enables the visual display of the archiving process
-z - use GZip for compression
You can also use BZip2 for compression. To do this you need to use -j key instead of -z.
In this case, the tar.bz2 packer command will look like this
tar cfvj archive.tar.bz2 /forpack
Other archivers can be used instead of GZip and BZip2, you just need to pick the appropriate key.
How to unpack tar.gz and tar.bz2 archives
To unpack tar.gz or tar.bz2 archives, replace -c in the command with -x key and specify the path to the archive, absolute or relative
The command to unpack the archive to the current directory looks like this
tar xfvz archive.tar.gz
You can use -C key to specify the path to decompress the archive
tar xfvj archive.tar.bz2 -C /var/www
Viewing tar archives in Linux
You can use the -t key to view the contents of the archives
tar -tf archive.tar.bz2
A list of files and directories in the archive will be output. If the -v switch is added, detailed service information about permissions, file sizes, etc. will also be output.
tar provides a lot of useful features. For example, you can specify files and directories that will not be included in the archive, add files to an existing archive, take a list of objects to be packed from a text file and much more
The variety of options will, as always, help you to understand