Introduction to file systems

Modern operating systems have a file manager program, which provides a grapical interface to manipulate the file system. In windows, this is the Windows Explorer. There are too many such managers available on UNIX systems to list here -- I use Konqueror on my LINUX install at home. However, when we are programming in java, we need to invoke the program from the command line, and we need to know how to navigate the file system without using these file manager programs.

A quick overview of the Windows file tree

Using your mouse, right click on the start button and select "Explore" from the list that pops up. This will bring up the Windows Explorer. In the left pane of the window that appears, you will see a Tree like structure. This is your windows file system tree. Note that the root of the tree is the Desktop icon. Under that you should see "My Documents", "My Computer", "My Network Places" and some other things. If there is a + sign next to "My computer" click on it. This will expand the branch of the tree rooted at "My Computer". If there isn't a + sign, then that branch is already expanded. Once you've expanded this branch, you should see a listing of all storage devices installed in your computer. Most systems will have an a: (floppy), c: (hard disk). If you have more than one hard disk, or have partitioned a hard drive, you will see extra letters d:, e: etc, as needed. Following the hard drives come the CD-Rom and CD-RW and other devices, using the next available letters in the sequence. (I: and O: are usually not used as they can be confused with ones and zeros.) For example, my system at home has the following structure: a: (floppy), c: (Windows 98 partition), d: (Windows 2000 partition), e: (partition for file storage) f: (partition for music/videos) and g: (CD-Rom). There are also Linux partitions, but Windows cannot read them, so they don't appear. If I add a CD-RW, it would appear as h:. In the CLAS labs, the drives are a: (floppy), c: (hard drive), d: (CD-ROM), e: (CD-RW), and following these physical devices, there are many more network drives, starting with your personal space at f:.

Expand the C: branch of the tree if this is not already done. You should see a bunch of folders, and maybe some files. Each of these folders is the root, or parent of another subtree, or branch, and may have other child folders and files beneath it. Use explorer to explore the file system of your computer for a few minutes.

One of the drawbacks of the Windows file system, is that the user is required to know which physical device on which a particular file is stored. In Explorer, this isn't much of a problem, but it can be when we start using the console (DOS prompt)
 

Introduction to DOS

Click the "Start" button. Click the word "Run" from the list that pops up. In the text box that appears type the word "command" (Win2k and XP users can abbreviate this to "cmd".) A window should appear and you should see something like "c:\Windows\Desktop >" or "c:\Documents and Settings\Username > " ( NOTE: Some browsers will display the backslash character as a W with a dash through it.) What this tells us is that the current active directory is the Desktop folder, located in the Windows folder, which is physically located on the c: drive. Note that when we are using a file manager interface, they are called folders. In DOS and UNIX, we call them Directories. Type the command DIR to view what is in this directory. If it goes by too fast, type DIR /p which will display the listing one screen at a time. Anything that appears with the word DIR after it in the list, is another directory. Everything else is a file. With the exception of the top directory (c:\) everytime you type DIR the top two directories shown are always. and .. (single dot and double dot.) These are not really directories, but they are symbols used to refer to the CURRENT directory, and the PARENT directory respectively. (More on this later.)

Useful Commands

A: C: D: etc
-- Changes the drive that we are currently using. If I want to see what is on a floppy disk, I would type A: and then use the DIR command. To get back to the C: drive, I would type C:
DIR
-- Displays the contents of the current directory.
DIR /p
-- Displays the contents of the current directory one page at a time.
MKDIR name
-- Creates a directory inside the current directory with the given name.
RMDIR name
-- If there is a directory with the given name inside the current directory, then it is removed. The directory to be removed must be empty first.
DEL name
-- Remove the file with the specified name. You can also use "wildcards" DEL *.class will remove all files ending in class. DEL test?.java will remove (e.g.) test1.java, test2.java, testx.java etc. If you want to remove all files in a directory, type DEL *.* (This is dangerous!).
COPY name1 name2
-- Makes a copy of the file named name1, and calls it name2. The original file still exists. This is useful to make backups: COPY RockScissorsPaper.java RSP.java. Now I can edit the original, and restore it if I mess it up too much.
RENAME name1 name2
-- Renames the file name1 to name2. This is useful to restore a backup to the original filename. For example, I have completely screwed up RockScissorsPaper.java, and I want to restore the backup. First I will remove the file that I no longer want: DEL RockScissorsPaper.java. Then, I will rename the backup to the original filename: RENAME RSP.java RockScissorsPaper.java. Of course, I could always use copy to restore as well.
cd name
-- Changes the directory to the directory named. CD . (CD dot) will do nothing, as we are already in the CURRENT directory. CD .. (CD Dot Dot) will climb us up the tree one level, to the parent directory. CD javaProgs will take me to the directory named javaProgs IF javaProgs is a child directory of the CURRENT directory. If I want to get to the root (top of the tree on this particular drive) I can use the command CD \ (CD Backslash).
EDIT name
-- A simple text editor. Useful for quick edits to a text file, but Edit+ is prefered.
HELP command
-- used to get help on a DOS command. This doesn't always work on some versions of DOS. You can also try getting help on a command using the switch /? after the command name. For example, to get help on the DIR command, I could try either HELP DIR or DIR /?

Using Paths

So far, we have just used RELATIVE path names. That is, we have only refered to files in relation to their location to the CURRENT directory. However, each file has an absolute path as well. Suppose a file called Prog1.java is located in a folder called Programs which is on the desktop. I could reach this file from C:\ by typing the following commands: CD WINDOWS, CD DESKTOP, CD Programs, and then I could read the file. However, I could also get to that directory by typing in the complete path: CD \Windows\Desktop\Programs and get there in one step. Suppose I have been working in the CLAS lab, and have been using the above directory as a temporary working directory. Now, I want to save all my files to a directory on my F: drive, called Assignment1. I can do this from ANY location on the computer by using the absolute paths in the copy command COPY c:\Windows\Desktop\Programs\*.java f:\Assignment1\. This will copy all files ending in .java to the target directory. Since I didn't specify target filenames, the original filenames are used. However, If my CURRENT Directory was already C:\Windows\Desktop\Programs, I could abbreviate the command to COPY *.* F:\Assignment1\. Or, If my CURRENT was F:\Assignment1, I could use the . (dot) to indicate that I want to copy the files here, i.e. Copy C:\Windows\Desktop\Programs .

Introduction to UNIX

Everything that we discussed in DOS is still valid, except for the actual command names, and in UNIX, there are no drive letters. Paths in UNIX work the same way as they do in DOS except that we use the frontslash / instead of the backslash. The dot, and the dot dot directories work the same way as well. We also need to pay attention to the Case of the commands. In UNIX, commands are usually lower case. In DOS, it doesn't matter.

Commands that work the same in UNIX

A table that maps UNIX commands to their DOS Equivalent

Unix Command DOS Equivalent Description
rm DEL Remove the file
cp COPY Copies a file
ls DIR Lists the files and directories in the current directory
mv RENAME Moves a file from one name to another

Other useful unix commands

pwd
-- Displays the path of the PRESENT WORKING DIRECTORY (the Current directory)
cd ~
-- ~ is symbol used to indicate your HOME directory. On unix.aml.yorku.ca, your home directory is usually /home/username. This is a good way to get to your home directory if you go off exploring and get lost.
pico
-- pico is a text editor. It is useful for quick fixes, but you are better off to use Edit+ on your home machine.
exit or logout
-- closes the connection with the machine.