This is by far the most used compression tool on Linux, and is famously difficult to use:
This may have something to do with the huge range of options available and the fact that some
tar implementations only support short options like
-t which lis_t_s (!) files within a tarball, resulting in obtuse shorthands like
tar -zxvf. Fortunately the long option names are obvious, so you’ll be disarming nukes in no time.
To create a tarball:
tar --create --file=./backup.tar.gz --gzip ./project
--createis the flag to create a new archive.
--file=FILEis the key/value option to set the archive file we’re working with.
.tar.gzis the conventional extension, since the resulting file is a tarball contained within a gzip archive.
--gzipspecifies that the file is to be compressed — this is not the default!
To add other files and directories to the tarball, simply enter them after
./backup.tar.gz will contain the
project directory and all the files in it, recursively.
As you can see,
tardoesn’t have bareword subcommands like Git’s
pull— subcommands are just another set of flags. The main purpose of
tarisn’t actually compression, but rather creating tarballs, an evocative name for a collection of files placed back–to–back within another file.