Moving Around with the cd Command
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

To change directories using an absolute path
Type cd followed by the absolute path to the directory you want (for example, cd /usr/bin) and press

Figure 11. Here's how you can change the current directory to /usr/bin using an absolute path…

To change directories using a relative path
Type cd followed by the relative path to the directory you want (for example, from your home directory, type cd ../../usr/bin) and press

Figure 12. …or a relative path from your home directory.

To move to a subdirectory using an absolute path
Type cd followed by the absolute path to the subdirectory (for example, cd /Users/ronh/Sites) and press

Figure 13. Here's how you can move to a subdirectory using an absolute path…

To move to a subdirectory using a relative path
Type cd followed by the relative path to the subdirectory (for example, from your home directory, type cd Sites) and press

Figure 14. …or with a relative reference.

- 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 ).
Figure 15. If you enter an incorrect path, an error message appears.

To list the contents of the current directory
Type ls and press

Figure 16. Once you're in a directory, using the ls command by itself displays the contents of that directory.

To return to your home directory
Type cd (without any arguments) and press

- 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.