Tar files are package files that store multiple files inside itself.
You can think of them like Zip files, if you are aware of those. This
way, if a lab requires multiple files to be submitted, throw all of the
required files into a Tar and submit that one file instead.
How to package files up via Tar (In a nutshell)
Let's say I completed Lab 1, Part 1 (Prog1a, Prog1b, Prog1c) and I
want to submit it. The lab writeup states to only submit Prog1b.cpp
and Prog1c.cpp. So...
UNIX Command
UNIX> ls -la
total 24
drwxr-xr-x. 2 cnguyen graduate 89 Jan 15 19:24 .
drwxr-xr-x. 5 cnguyen graduate 48 Jan 12 05:20 ..
-rw-------. 1 cnguyen graduate 120 Jan 12 05:22 Prog1a.cpp
-rw-------. 1 cnguyen graduate 526 Jan 13 01:52 Prog1b.cpp
-rw-------. 1 cnguyen graduate 685 Jan 13 01:55 Prog1c.cpp
-rw-------. 1 cnguyen graduate 1056 Jan 13 01:58 Prog1d.cpp
-rwxr-xr-x. 1 cnguyen graduate 6352 Jan 12 05:21 prog1_ints
From the files above,
Prog1b.cpp
and
Prog1c.cpp
are what we want. Let's tar them into a single file called
lab1.tar
:
UNIX Command
UNIX> tar -cvf lab1.tar Prog1b.cpp Prog1c.cpp
This will create
lab1.tar
, including all files
specified after "lab1.tar" specified in the command. So it'll
include both
Prog1b.cpp
and
Prog1c.cpp
in it!
Because someone will be curious, the arguments "cvf" stand for:
-
"c" means "create". It's telling tar we are making a
tar file ("x" is for "extracting").
-
"v" means "verbose". It will tell you what files are
going into the tar file.
-
"f" means "file". The argument that comes after this
one is the filename of the tar that will be written to
(e.g. "lab1.tar").
MAKE SURE THE NAME OF THE TAR COMES AFTER -cvf!
Otherwise, you'll accidentally overwrite a file. Tar does not prompt
you to overwrite files. It just does it. If I did tar -cvf Prog1b.cpp Prog1c.cpp
,
then it'll obliterate Prog1b.cpp
and make it
into a tar file that only has Prog1c.cpp
in it. We
cannot help you if you accidentally overwrite your source code (IT
can though. They back up directories daily).
Check if your Tar file is valid (In a nutshell)
Method 1: You can use "tar -tf FILE" to check:
UNIX Command
UNIX> tar -tf lab1.tar
Prog1b.cpp
Prog1c.cpp
"t", for some reason, means "lis
t" in tar. It lists all
files packaged into the tar file.
Method 2:
-
If you're on Windows, just download 7zip and open the Tar
file with it.
-
If you're on a Mac, it has tar support embedded right in the OS.
You can just open the file.
-
If you're on Linux, it depends on what software packages
you have. But if you're on Linux, I'll assume you know what
you're doing.
Make sure you don't include a directory
Whenever you submit, please make sure you don't put the files in
a directory and tar the directory unless specified.
Let's use tar -tf
to show what I mean. This isn't
a valid submission:
UNIX Command
UNIX> tar -tf lab1.tar
lab/Prog1b.cpp
lab/Prog1c.cpp
The reason why is because, upon extraction, it will create lab
as a directory and then put files in that directory. You can tell by
the "lab/" before each file. It would extract to this:
File Structure
lab/
Prog1b.cpp
Prog1c.cpp