Using UNIX tar utility

Programming assignments are to be submitted as a single tarfile using the cs35handin program.

You must first tar up all of your Java source files (.java files), your Makefile, and your README file containing you and your partners name and information on how to run your program. In addition, if your program uses an input file, you should include that in the tar file as well.

The Unix tar command archives and extracts files to and from a single file called a tarfile. Below is an example of how to use the UNIX tar command:

% ls
Circle.java Main.java Makefile README Shape.java Square.java

% tar cvf prog2.tar Circle.java Main.java Makefile README Shape.java Square.java
Circle.java 
Main.java 
Makefile 
README 
Shape.java 
Square.java

% ls
Circle.java Main.java Makefile README Shape.java Square.java prog2.tar

In this example, the Java source files (.java files, the README file and the Makefile are combined into a tarfile named prog2.tar (the file to turn in using cs35handin).

WARNING: be sure to include the destination tarfile name argument to tar (in this example it is the prog2.tar argument), otherwise tar will overwrite the contents of one of the source file arguments with the tarfile. In fact, before you create a tarfile, it is a good idea to create copies of these files in another directory. One way to do this is to create a subdirectory "temp" and copy the files there before taring:

        % mkdir temp
        % cp * temp/.
Next, create a tarfile. If something goes wrong with tar, and you overwrite application source files with garbage, you will still have copies of these files in your temp subdirectory, so you can copy them in to your working directory and try tar again.

Another alternate is to tar the entire contents of a directory rather than listing each individual file as an argument to tar. For example, create a hw2turnin directory, cp the files to turn-in into this directory and tar up the file:

        % mkdir hw2turnin
        % cp *.java hw2turnin/.
        % cp Makefile hw2turnin/.
        % cp README hw2turnin/.
        % tar cvf hw2.tar hw2turnin

To extract files from a tar file, use the xvf command line arguments to tar:

	% tar xvf prog2.tar 
For more information look at the man page for tar: % man tar