Up to now, you haven't moved around in the directory tree. You've been fixed in place in your home directory. Changing directories is easyjust use the cd (change directory) command, followed by the destination you want to move to.
You have two ways to indicate a destination: with an
absolute path or a
relative path .
An absolute path specifies the location of a file or subdirectory, starting at the root directory and working downward.
A relative path specifies the location of a file or subdirectory starting at your present location.
Let's look at an example. Suppose I'm currently in my home directory (/Users/ronh) and I want to move to the /usr/bin directory. I could specify the destination with its absolute path: /usr/bin. Or I could use the relative path to go up two directories to the root and then down two directories to the one I want. This is where the special "double-dot" (..) directory name that I discussed earlier comes into play; it indicates the directory above the current one. So the relative path from my home directory to /usr/bin would be ../../usr/bin.
The cd command does not have any options and has no man page of its own because it's built in to the shell. You can find out more about the shell by using the man pages; enter man bash and press
Absolute paths, which always start with a forward slash (/), work no matter where you are located in the Unix file system because they start from the root directory.
Relative paths are especially useful if you are deep inside the directory structure and want to access a file or subdirectory just one level up. For example, it's a lot easier to type ../images/flower.jpg than /Users/ronh/Documents/ClipArt/Plants/Color/images/flower.jpgand it's a lot easier to remember, too!
Type cd followed by the absolute path to the directory you want (for example, cd /usr/bin) and press
The current directory changes and the path to the directory appears in the shell prompt (Figure 11 ).
Type cd followed by the relative path to the directory you want (for example, from your home directory, type cd ../../usr/bin) and press
The current directory changes and the path to the directory appears in the shell prompt (Figure 12 ).
Type cd followed by the absolute path to the subdirectory (for example, cd /Users/ronh/Sites) and press
The current directory changes and the path to the directory appears in the shell prompt (Figure 13 ).
Type cd followed by the relative path to the subdirectory (for example, from your home directory, type cd Sites) and press
The current directory changes and the path to the directory appears in the shell prompt (Figure 14 ).
Do not include a forward slash (/) before a subdirectory name. Doing so tells Unix to start at the root directory (as if you were entering an absolute path) and could result in an error message (Figure 15 ).
Type ls and press
The contents of the directory appear in the Terminal window (Figure 16 ).
Type cd (without any arguments) and press
The current directory changes to your home directory and the tilde (~) character appears in the shell prompt.
The tilde character is Unix shorthand for "home directory." So, for example, if you wanted to change to the home directory for user name rosef, you could type cd ~rosef.