Distributing a project as a tarball¶
The tar utility is to unix what zip archives are to Windows. It gives us a way to bundle multiple files together into one file, and typically compress them as well. The name ‘tar’ is an abbreviation of ‘tape archive’, which is a hint at its age but it works just fine even if you don’t have any tape drives around.
Any project you work on that contains more than one file should go in
its own directory, named after the project. In that directory, you put
all of your source code, your Makefile
, etc. When you want to
share your work, you bundle it all up into a tar archive and
compress it into a tarball.
To create a tarball, go to the parent directory that contains your
project directory. Typically I put my project directories directly in
my home directory, so that means I would go to my home directory with
cd. You should be able to run ls project
and see
a list of your project’s files, and only your project’s files. Now
run tar -c -f project.tar project
. The -c
is for
‘create’; the -f project.tar
specifies the name of the
archive file to create, which should be the same name as the directory
but with the .tar
suffix; and lastly, you give the name of the
project directory to bundle up.
Once it is created, compress it by running gzip project.tar
.
The gzip compression program will replace your .tar
file with a .tar.gz
file, and that is what you will pass around.
If you want, you can skip the explicit compression step by passing the
-z
option to tar.
You can extract the contents of a tarball by giving tar
the -x
option instead of -c
(you can list the contents
without extracting them with -t
instead).