Getting around
In the last chapter we learned that the shell has a working directory. Let's have a look how we can change it. If you get lost you can simply enter:
cd
This brings you back to your home directory, which is also where a new terminal window will put you first. If you like to know where you are then you simply enter:
pwd
and the system will tell you your working directory (pwd probably stands for print working directory).
/Users/YourName
Let's see what kind of folders we have:
ls -p
Desktop/
Documents/
Library/
Movies/
Music/
Pictures/
Public/
Sites/
You might have more. Let's make the Desktop our working directory:
cd Desktop
If you type now:
pwd
you will see that the directory has inded been changed:
/Users/YourName/Desktop
Absolute and relatives paths
The location of a directory is also called a path. You tell the the cd a path. Basically where you would like to go. This you can do in two ways: If you start the path with a / then you specify an absolute path:
cd /Applications
will bring you to the /Applications directory, no matter where you where before.
Lets go back to the desktop:
cd
brings you 'home'.
cd Desktop
into your Desktop. Desktop is a relative path. You go there from your home directory.
Going up
You have gone 'down into the Desktop'. How can you go 'back up'? simple:
cd ..
The .. two dots are another name for the directory that contains the directory that you are in.
Desktop is in your home directory. Since it does not start with a / it is a relative path from where you are.
Let's go into your music folder:
cd Music
If you wanted to go into your Desktop you need to go up one and then down into the Desktop. You can do this in one step:
cd ../Desktop
A / in the beginning is used to indicate an absolute path as we saw. But it is also used to seperate path components. Directories can contain directories. If you would like to go into the Utilities directory that is in the Applications directory then you go do so by typing 3 commands:
cd /
cd Applications
cd Utilities
or you do it in one command:
cd /Applications/Utilities
or if you like in two:
cd /
cd Applications/Utilities
/ is also called the root of the filesystem. Not to be confused with the user root.
/ and your home directory are the two fixed points of you directory navigation. Since you use your home directory frequently there is also a shortcut for this:~ (you find this key on the upper left corner of your keyboard).
In order to go into your Desktop, no matter where you are currently you would enter:
cd ~/Desktop
Please note the / between ~ and Desktop: It is needed to seperate the path components.
Now you will be able to find your way around on your hard drive. And actually on any hard drive that you have access to and that runs unix. Which is quiet allot.
feedback
Foot note for unix geeks:
OS X is somehwat different from other unix implementations. The directory component appears to be case insensitive. Try
cd /TmP ; pwd
cd /mTp ; pwd
The results might surprise you ...