To make a tar file from the directory homework1
$ tar czf homework1.tgz homework1
To check the contents of a tar file called homework1.tgz
$ tar tzf homework.tgz
To extract the contents of a tar file called homework1.tgz
$ tar xzf homework1.tgz
tar or the Tape ARchive utility is a program that is used for combining multiple files into a single file. This is the format that is used to transfer multiple files in the majority of open source project.
Tar files are frequently used to transfer the contents of a directory. The examples on this page assume that you want to transfer all of the files in a directory called homework1 . Further assume the contents of this directory are two files, hello.cpp and Makefile .
$ ls Makefile hello.cpp
Files created with tar frequently have the extension .tar. The file homework1.tar is the conventional name used for a tar file containing the directory homework1.
Tar is frequently used in conjunction with compression utilities. GNU zip (gzip) is a common choice for this. A tar file which has been compressed with gzip will frequently have the extension .tgz or even .tar.gz. In this case homework1.tgz or homework1.tar.gz are the conventional names for a tar file containing the directory homework1 which has been compressed with gzip.
This page is a summary, there are other ways that tar can be employed.
The best practice is to work on each project in a folder or directory. For this example the code for a project is located in the directory homework1.
$ ls homework1
$ tar cvzf homework1.tgz homework1
In the following example the user types ls to show that the directory homework1 exists. After that, the tar command to create a tar file is issued. This command is run in verbose mode so each file or directory is listed as it is added to the tar file. The example concludes with a listing of the directory showing that the tar file homework1.tgz has been created.
$ ls homework1 $ tar cvzf homework1.tgz homework1 homework1/ homework1/Makefile homework1/hello.cpp $ ls homework1 homework1.tgz
To check the contents of a tar file use the following command in the directory containing the tar file.
$ tar tzf homework1.tgz
Note that in this command c has been replaced with t which means table of contents.
$ ls homework1 homework1.tgz $ tar tzf homework1.tgz homework1/ homework1/Makefile homework1/hello.cpp
To extract the contents of a tar file
In the tar command, c should be replaced with x , which tells tar to extract the contents of the file.
$ tar xzf homework1.tgz
In the following example
$ ls homework1.tgz $ tar xvzf homework1.tgz homework1/ homework1/Makefile homework1/hello.cpp $ ls homework1 homework1.tgz $ ls -r homework1 hello.cpp Makefile
WinSCP has the ability to deal with tar files.
To create a tar file of a directory