CMPSC 311, General Instructions

Accessing Information -- How to get the source code from CS:APP

If you just want to see the individual programs, and don't care about saving them, go to

Here is how to get your own copy of the source code from CS:APP, to be used on a Unix system with the GNU tools installed (this includes Linux, Mac OS X, and Solaris at PSU CSE).  We assume you are using a Web browser where right-clicking on a link gets you a menu of choices; on Mac OS X, use control-click instead.  We also assume you have read and printed this page on some not-necessarily-Unix system, because we're going to start from the beginning.

Login, and open a terminal window.  You should now be in your home directory.  Try these commands just to be sure.

When used as part of a command, the symbol ~ (tilde) is shorthand for the name of your home directory.  The environment variable HOME gives the same information.
  echo ~
  echo $HOME

Create a directory to hold all your projects for the course.  For example,
  mkdir ~/cmpsc311

Verify that the directory was created.

Create a subdirectory to hold the code from CS:APP.  For example,
  mkdir ~/cmpsc311/csapp

The commands to follow will create a subdirectory of csapp.

Open a Web browser.  For example,
  firefox &

Go to   (right-click to open in a new tab or window, so you don't lose this one).

Right-click on the word tarfile in the first bullet.  Then "Save Link Target as ..." the file code.tar in your cmpsc311/csapp directory, or on the desktop.  If you saved the file on the desktop, then move it to cmpsc311/csapp .
Now you need to unpack the source code files.  We will add some extra commands to see the effect of archiving and file compression.

First, change to your new directory.
  cd ~/cmpsc311/csapp

The command tar (which originally meant "tape archive") bundles files and directories into one file, called a tar file or tar archive for obvious reasons.  The filename ends in .tar as a reminder.  tar also unbundles a tar file.  It's usually a good idea to see what is in the tar file before un-tar'ing it.
  tar tvf code.tar

Note that tar does not use the modern convention for options, which would have been something like "tar -t -v -f code.tar".  The function letter t means "Table of Contents", so you get a listing.  The function modifier v means "Verbose" so you get a long listing (file size and original date, along with the name from the default listing).  The function modifier f means "File" so you can specify which tar file to read for its contents.

To extract the contents of the tar file,
  tar xvf code.tar

Now check to see what you have:
  ls -l

You can safely delete the file code.tar, since you know how to recover it from the web site, and since its contents are now available as individual files and subdirectories.
  rm code.tar

To see everything in the file tree,
  ls -lR

Navigating through the code directory should be obvious once you see its subdirectories and file names.  Use the command
  cd subdir
to change to the subdirectory subdir, and the command
  cd ..
to change to the parent directory (one level upward in the file system), or the command
to change to your home directory.

Later we'll come back to the description of how to compile and run these programs.

You could repeat all this with the file code-all.tar from the second tarfile link.  It expands to a directory code-all.

The file code-all.tar is pretty large if you are short on space, or if your connection is slow.  It's often useful to compress large files.  Here is something that could have been done, but wasn't.

The command gzip compresses a file, and gunzip uncompresses it.  The compressed file name often ends in .gz as a reminder.  The program names begin with g to indicate that they are from the GNU collection, but that isn't a foolproof or absolute rule.

   % ls -l
  total 69184
  drwx------  16 dheller  fcse       544 Feb 14  2010 code
  -rw-------   1 dheller  fcse  35420160 Aug 18 09:20 code-all.tar

  % gzip code-all.tar

  % ls -l
  total 18464
  drwx------  16 dheller  fcse      544 Feb 14  2010 code
  -rw-------   1 dheller  fcse  9451617 Aug 18 09:20 code-all.tar.gz

  % gunzip code-all.tar

  % ls -l
  total 69184
  drwx------  16 dheller  fcse       544 Feb 14  2010 code
  -rw-------   1 dheller  fcse  35420160 Aug 18 09:20 code-all.tar

Note that the date on the directory code is when it was originally created, not when we obtained code.tar.

Last revised, 19 Aug. 2010