Organization of Information under Unix


Files are simply a place to store information on the computer's disks. I like to think of them as a collection of paper stapled together. I include an unspecified number of pages of paper because files can have any length. They are given names so that we can easily find them. We will primarily use files in 5 ways. Although you don't think about it, most commands that you enter at your terminal simply cause the CPU to execute machine instructions stored in a file with the command's name (try the command "ls /bin" to see some of these files). Each Fortran program that we write to perform some calculation will be stored in a file. We create the file with a text editor such as "vi". When we compile the file the resulting instructions that can be used by the CPU are stored in a separate file. We tell the machine to execute the commands in that file to do the calculation. For some projects we will create files that contain data to be used in a program. We will also create programs that put their results in specific files for later use.

Files are organized on Unix, and most other operating systems under a "Directory Structure". Directories are simply a way of maintaining order and ownership of files on disks. You don't want to see every file on a disk, and don't necessarily want everyone to look at all of your files. The way of visualizing Directories on an Apple computer (it didn't originate with them) or under MS Windows is one of the easiest ways of thinking of Directory Structures. You see a collection of icons on the screen. Some may look like papers, representing files. Other icons look like the file folders that you would use to organize your papers in a file drawer. In Unix terms these file folders are "directories" or "subdirectories" (the terms are often used interchangeably to keep you confused). Each file folder has a name on it. Each Unix subdirectory has a name associated with it. Lets discuss a file folder (or Unix subdirectory) named "My-Stuff". To look at the contents of "My-Stuff" on a Mac or Windows, we double click on the folder icon. A new window opens with more file and folder icons. To look at the contents of "My-Stuff" in Unix, I can type "ls My-Stuff", or I shift my current directory location to "My-Stuff" by typing "cd "My-Stuff". I can then look at the contents of "My-Stuff" by typing the command "ls".

Any file on a Unix diff can be uniquely specified by listing file name preceded by the string of directories you passed through to "see" it directly. This long form of the file name contains all of the subdirectory names in order, separated by "/", and ends with the short filename. For instance if might have a program called "test.f", located in a subdirectory called "programs", under "My-Stuff". The full name for this file would be:

/afs/psu.edu/users1/jhm/My-Stuff/programs/test.f

Where did the "/afs/psu.edu/users1/jhm/" come from? I was dumped down through that string of directories when I first logged into the computer. It is called my "home directory". In Unix I can abbreviate the string "/afs/psu.edu/users1/jhm/" by "~/" if I am the user named "jhm", or by "~jhm/" if I'm not.

If my analogy to file folders didn't help, try thinking of the disk as a building. You enter the front door and might find a few signs to read (files that can be viewed with utilities such as "more"), and in the elevator you see numbered buttons on the wall ("ls" provides you with eyes on the computer) and punch a labeled button to go to a selected floor (use "cd" to move to a subdirectory or file folder in a disk file system). When you step out of the elevator you see a few more signs posted and see numbered doors to rooms (a lower level of subdirectories). Some of the rooms may be locked. If a room belongs to you (check "ls -alF" to see if it is yours), you can lock out or grant access to others with "chmod". You enter a room ("cd" again), find more notices on the wall to read, and a pen ("vi" editor) on a desk that you can use to leave your own notes in the room. You can protect these notes from prying eyes with "chmod". You might call the maintenance crew to clear all the useless notices off of the wall ("rm") or ask them to remodel and give you some connecting rooms (mkdir). If there are connecting rooms that you no longer want, the maintenance crew can get rid of them for you. An empty room can be removed with the command "rmdir". If the room has any contents you can yell "rm -r (room name)", but may regret the wanton destruction.

Back / Home


Maintained by John Mahaffy : jhm@cac.psu.edu