tar#

This is by far the most used compression tool on Linux, and is famously difficult to use:

`tar`

XKCD by Randall Munroe

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

  • --create is the flag to create a new archive.

  • --file=FILE is the key/value option to set the archive file we’re working with. .tar.gz is the conventional extension, since the resulting file is a tarball contained within a gzip archive.

  • --gzip specifies 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 ./project.

After running, ./backup.tar.gz will contain the project directory and all the files in it, recursively.

As you can see, tar doesn’t have bareword subcommands like Git’s commit or pull — subcommands are just another set of flags. The main purpose of tar isn’t actually compression, but rather creating tarballs, an evocative name for a collection of files placed back–to–back within another file.

 

This page is a preview of The newline Guide to Bash Scripting

No discussions yet