Unix Directory Structures
(Examples are for the Computer Center File System) Often in the process of using unix, you are required to access files from places other than your account. This lab will explain to you how files are organized and how you can reference them, whether it would be copying, printing or whatever.HOW ARE FILES ORGANIZED?
Files are organized in a hierarchical structure. The top of the structure is called the "root". The root level of the directory is like the top of a hierarchical structure in an organization. For example at CNU we have a President, who has a Provost and other Vice-Presidents under him. All Deans report to the Provost and all Dept chairs report to the Deans PRESIDENT | --------------------------------------------------- | | | | PROVOST V.P. FINANCE V.P STUDENT AFFAIRS etc. | --------------------------------- | | | DEAN SCIENCE DEAN BUSINESS etc. | ------------------------------ | | | | Physics Biology Math etc. Well hopefully you see the idea. Here the files are organized similarly. / (ROOT) | ------------------------------ | | | home etc usr | --------------------------- | | student faculty | | ------------------------ ----------- | | | | | acct cpsc psyc apcs math | | ------------------------- ------- | | | | | bjones jsmith public dgame llambert | | | (1) (2) --------------- | | |... | 230 230L 231 others | ------------------------------ | | | program1 program2 overheads | (3)WHERE ARE MY FILES IN ALL OF THIS?
Assume that you are student "bjones". Your files are hanging off of the name with a (1) under it. When you log in, the system automatically places you there to work. When you create files, it puts them in your own subdirectory. The student "jsmith" would be located similarly in (2). Since student directories are positioned according to your major, an accounting student would be located under the "acct" branch. This is called your "home" directory and it is where you are positoned when you log in. Each student has a different home directory in which he/she can manage their own files. You can see the exact name of your "pathname" (where YOU are located in all of this) by typing "pwd" in unix. This stands for print-working-directory and tells you where you are located. Try it. This person (bjones) would see /home/student/cpsc/bjones Do you see why it is called a "PATHname"? It tells how to get to your account from the ROOT. It is called the root because the structure looks like a tree if you turn it upside down and this would correspond to the "root" of the tree.HOW DO I MOVE AROUND IN THIS STRUCTURE?
First of all, you probably have little need to access anything other than your own directory and the course public directory, but you can move to other directories with the unix "cd" command. This stands for change-directory. If you are this "bjones" student and wanted to move over to the public directory, you could type cd /home/student/cpsc/public/230 Try it! Now "ls" and see what files are there?WHAT CAN I DO NOW?
Not much! Unix allows us to assign permissions saying what you can do in these various accounts. This one has read permissions allowing you to look at (but not change) any of the files here. You can copy them into your account, print them, etc. You CAN NOT change them!HOW DO I GET BACK TO MY ACCOUNT?
The obvious command is cd /home/student/cpsc/bjones (for jones, but what about YOU?) There is also a shorthand notation. Just "cd" will take you back to your own "home" subdirectory. Other shorthand notations exist. Two (.. and .) are mentioned below: .. means the level above your current position and . means your current position (not used often except for the "cp" command) If you start your path with a "/", unix assumes you are going to describe the entire path from root. This is called an ABSOLUTE address. It works no matter where you are positioned. For example if you were in your own subdirectory and wanted to move to the public subdirectory you could type cd ../public/230 rather than cd /home/student/cpsc/public/230 This would work for bjones but NOT for an accounting major. WHY? It really doesn't make any difference which one you use. As you become more familiar with what is going on, you will make the appropriate decisions easily. There is another method which also is convenient employing RELATIVE path names. For example, consider the public/230 directory. It has some files (program1 and program2) and another directory (overheads). What if you wanted to visit the overheads directory? You could cd to it but how? 1. cd directly to it using an absolute path cd /home/student/cpsc/public/230/overheads 2. but if you had already "cd"ed to the 230 account (cd /home/student/cpsc/public/230) you could now use a RELATIVE path cd overheads NOTE that the "cd overheads" command did NOT start with a / This is an indication that the path you type will begin from where you are currently positioned in the directories rather than from the root.DO I USE PATHNAMES ANYWHERE ELSE?
Yes, lots of places. Basically it provides a mechanism to name a file anywhere in the system without moving there first. Assume that a file in the public directory (named xyz) has some info you want. You could move over to the directory and print it, e.g. cd /home/student/cpsc/public/230 lpr xyz OR you could print it from your own directory without moving there first if you tell unix enough info to know how to find it. lpr /home/student/cpsc/public/230/xyz Do you see how pathnames are really a convenience rather that a problem? You can also "ls" the public directory in a similar manner. Type ls /home/student/cpsc/public/230 rather than cd /home/student/cpsc/public/230 ls Lastly, you can copy files from the public directory by using the pathname in front of the file. From your home account: cp /home/student/cpsc/public/230/xyz .CONCLUSION
Understanding directory/subdirectory structures and how to name them is important to your ability to work in a unix operating system. The only new commands introduced were "cd" and "pwd". The most important part was to learn the proper use of path names. If you begin with a / it represents an absolute address and you have to describe the complete path from the root. If you do not start with a /, unix assumes you are using a relative path and it will move up or down (if at all) as described in your path.HAPPY TRAILS (or is it HAPPY PATHS?)!