Setting Up a Practice File Structure

This is to facilitate exercises about the Unix file structure. It sets up some files on your disk, in a file hierarchy for you to experiment with. These files are provided in a file called classifications.tar. A tar file is similar to a zip file. It contains a lot of other files bundled up inside. Just as you can "unzip" a zip file to extract the files it contains, similarly you can "untar" a tar file for the same purpose. When you do so, out come the files, onto your hard disk.

So what files does classifications.tar contain? To find out, let's untar it first. Please go to your home directory, then create a new subdirectory in which to put all these files. Let's call this subdirectory "taxonomy." The word taxonomy comes from the world of biology, referring to the classification system whereby all  the species of plants and animals are grouped (reptiles, mammals, insects, etc.). After you create the "taxonomy" subdirectory we'll fill it up with the stuff that's inside classifications.tar. Here's how. Please execute these commands while logged in:

cd
mkdir   taxonomy
cd   taxonomy
tar   -xvf   /var/ftp/pub/classifications.tar

The "cd" puts you into your home directory to start with. Each of you has a home directory. If your username is smith, your home directory would be /home/smith. Mine is /home/david, as david is my username. When you give the "cd" command, all by itself with no options or arguments, it puts you in your directory. That is, it makes your directory be the "current working directory." (You can always find out which directory is the current working directory by issuing the command "pwd." pwd stands for "print working directory.")

The "mkdir   taxonomy" command creates a new directory named "taxonomy." Where? In the current working directory. So it will end up being /home/smith/taxonomy, to name it in full (if your username is smith; of course, your username isn't smith, so substitute your real username when I talk about smith here).

The "cd   taxonomy" command changes the current working directory from /home/smith, to the new /home/smith/taxonomy. Taxonomy is empty at the moment. It was just created. (If you at this juncture give the "ls" command, which shows the files in the current working directory, you'll see that it shows none. But that's about to change.)

The "tar   -xvf   /var/ftp/pub/classifications.tar" command is the one that does the work. It opens the classifications.tar file, takes out copies of all the files in there, and deposits them in the current directory. There is some information about the tar command below. As it's used here, the -x option tells the tar command to extract from a tar file. The -v option says "be verbose," and put some information on the screen that indicates what it is doing. The -f option says "the tar file from which I want you to extract is the following." You end up with something like:

 

 

Examine the directory structure you just created. Try:

ls -l
ls -l animal
ls -l vegetable
ls -l mineral
ls -l animal/mammal


For Your Information: the tar Command

How do you use tar? The 3 main options are to create, extract, or view a tar file. The -c option creates, the -x option extracts, and the -t option just lets you look inside a tar file to see what files are inside.

tar -cvf <destinationfile.tar> <source directory>
–Executed from within parent directory of <source directory> 
–Captures whole subtree under <source directory>

tar -xvf <destinationfile.tar>
–Executed from within any directory 
–Creates thereunder a subdirectory <source directory> with whole contents and same name as the original 

tar -tvf <destinationfile.tar>
–View contents of a tar file