There’s No Place Like Home
Every user has a home directory (sweet, isn’t it?) in which you store your personal stuff, mail, and so on. When you log in, UNIX starts you working in your home directory, where you work until you move somewhere else. Your home directory is your subdirectory in the /usr/home (or /home ) directory, so Zac Young’s home directory is /usr/home/zacyoung . (Although Zac is only 8 years old, he’s got plenty of stuff to put in his home directory.) Because most UNIX systems involve lots of people sharing hard drive space and files, UNIX has a security system to prevent people from reading each other’s private mail or blowing away each other’s work (accidentally, of course). Chapter 5 talks about the security system. In your home directory, you usually have the right to create, edit, and delete all the files and subdirectories. You can’t do that in someone else’s home directory unless the directory’s owner gives you permission.
I’ve been working in the directory
Whenever you use UNIX, the directory you are working in is the working directory. Some people call it the current directory, which also makes sense.When you first log in, your home directory is your working directory. Although you start in your home directory, you can move around. If you move to the /Budget directory, for example, the /Budget directory becomes the working directory. (Your home directory is still your home directory — it never moves.) If you forget where you are in the directory structure, you can ask UNIX. Type the following line to ask UNIX where you are:
pwd
This line is short for print working directory. UNIX doesn’t print the information on paper; it just displays it on-screen. You see something like this: /Budget/Year2004
When you use the ls command (or most other UNIX commands), UNIX assumes that you want to work with just the files in the working directory. The ls command lists just the files in the working directory unless you tell it to look somewhere else.
To move to another directory to do some work (if you’re tired of working on the budget and want to get back to that recipe for pumpkin soup, for example), you can change directories. To move from anywhere in the /Budget directory to the /Recipes directory, type this line:
cd /Recipes
Remember that cd is the change directory command. After the cd (and a space), you type the directory you want to go to. You can tell UNIX exactly which directory you want in two ways:
Type a full pathname, or absolute pathname (the pathname starting at the root, as you did earlier). In the /Recipes example, the slash at the beginning of the pathname indicates that the pathname starts at the root.
Type a relative pathname (the pathname starting from where you are now).
This stuff is confusing, we know, but UNIX has to know exactly which directory you want before it makes the move. Because the hard drive can have more than one directory called Recipes , UNIX has to know which one you want.When you type a full pathname starting at the root directory, the pathname starts with a / . When you type a relative pathname starting at the working directory, the pathname doesn’t start with a / . That’s how UNIX (and you) can tell which kind of path it is.If you are in the /Budget directory (on the /Budget branch of the directory tree) and want to go to the Year2004 subdirectory (a branchlet off the main /Budget branch), for example, just type cd Year2004. To go to a different branch or to move upward toward the root, you must type the slashes. To move from the /Budget/Year2004 branchlet back to the main /Budget branch, type cd /Budget. To move from the /Budget branch to the /Recipes branch, for example, type cd /Recipes.If you try to move to a directory that doesn’t exist or if you incorrectly type the directory name or pathname, UNIX says: Budegt: No such file or directory
(or whatever directory name you typed).
I want to go home!
If you move to another directory (/Oz , for example) and want to get back to your home directory (/Kansas , that is), you can do so as easily as clicking the heels of your ruby slippers three times. (Or were they glass slippers?) Just type this line:
cd
When you don’t tell UNIX where you want to go, it assumes that you want to go home.