Course Links

Exercises

Resources

External

Good file organization can be a big help in keeping track of your work. By the end of the course, you will have written enough code that keeping it all in one directory would be very confusing. If you start with good habits right away, you won't need to spend a lot of time cleaning up later.

Note: the commands described below are described in the Basic Unix document, along with some other useful commands. You might wish to make a printout for future reference.

Smith Unix Account Structure

Unix course accounts at Smith are set up with several directories (aka folders already created. Your home directory is called ~ (the tilde character). This directory contains configuration files (such as the .emacs file you use to configure the emacs editor) and other essentials; it will also hold all the directories where you will actually store your files. You should not store any of your work at this level.

Every account is set up with a subdirectory called public_html. Files and directories within the public_html directory may be visible through a web browser depending upon how their access permission levels are set. Because most of the programming assignments for this course will be web applets, you should store your work inside this directory. However, you must be careful to set the correct permissions on your source code to avoid inadvertently sharing your work with others before it is turned in (which would be a violation of the Honor Code).

Creating a Working Directory

You should create a directory within ~/public_html to store all of your work in this course. Inside that, each project or assignment you work on should also have its own working directory, where all its files are stored. For example, by the end of this course you should have working directories entitled assign1, assign2, assign3, etc., not to mention lab1, lab2, etc. Each of these will contain the files for the corresponding assignment or lab.

As an example, we'll create the course directory and then put a working directory called lab0 as an example. At the unix command prompt (represented by the $ below) enter the following series of commands:

$ cd ~/public_html
$ mkdir lab0
$ chmod 755 lab0
$ cd lab0
$ pwd

The first of these makes sure you are starting in your public_html directory. The second and third commands create the working directory for lab0 and set its permissions to be readable and accessible. Next we set the newly created directory to be active. Finally, the pwd ("present working directory") command tells you where you are in the directory tree structure. The string of characters returned should end in something like /112a-xx/public_html/lab0. All your actions (file creation, deletion, etc.) will now take place in the new directory, which is presently empty. If you want to create another new working directory, or move to a previously existing one, you should move back up to the ~/public_html/csc112 directory first. (Otherwise, the newly created directory would appear inside the lab0 directory, which would be confusing.) Two commands will accomplish this: cd ~/public_html/csc112 will take you there directly. This is very useful if you ever get confused about where you are. Alternately, cd .. will move you one level up in the directory structure. Either one should get you back from where you are now. To make sure, you can use pwd again.

File Management

Occasionally, once you have your working directories established, you'll want to manage the way they're set up. This section presents some useful commands for moving files around and making backup copies.

Let's say you've been working within the lab0 directory, and have created a few program files, called part1.java, part2.java, and part3.java. (You might want to create files with these names so you can try the examples for yourself -- it doesn't matter what's in them.) Now suppose you want to change part1.java, but you're not sure if the change will work and you want to be able to go back to the original version if necessary. You should make a backup copy first using cp:

$ cp part1.java part1copy.java

Now let's say the changes didn't work out, and you want to go back to the old version. You can replace the (modified) part1.java with the older copy by renaming the copy as part1.java. (The system will probably ask you if you wish to overwrite the existing file.)

$ mv part1copy.java part1.java

If you're going to make changes to all the files in the project, you can apply the same principle working with directories instead of files. The example below creates copies of all the files ending in .java in a subdirectory (i.e., directory within the lab0 directory) called checkpoint1. The * in the second line is called a "wildcard"; it matches against any combination of characters -- hence *.java matches any file ending in .java.

$ mkdir checkpoint1
$ cp *.java checkpoint1

Later on, if you want to go back to the files you had saved, you can copy them all back to the current working directory (represented by a period). This will overwrite any files with the same name, so be careful!

cp checkpoint1/* .

Cleaning Up

Usually it's not a problem to leave a few extra files around, as long as they're clearly named. But if things are getting messy and you want to tidy up, you can remove files or directories with the rm command. Just be careful not to remove anything you still might need!

rm part1copy.java
rm -r checkpoint1