Solaris Advanced User's Guide

Changing the Working Directory (cd)

The cd (change directory) command enables you to move around within the file-system hierarchy.

$ cd /usr/lib
$ pwd

When you type the cd command by itself, you return to your home directory. For example, if your home directory was /export/home/user1:

$ cd
$ pwd

Although your home directory is /export/home/user1, the cd command returns you to the/home/user1 because home directories are mounted on the /home directory by the automounter.

In the Bourne Again, C, Korn, TC, and Z shells, the tilde (~) is used as a shortcut for specifying your home directory. For example, you would type the following to change to the subdirectory music within your home directory:

example% cd ~/music

You can also use this shortcut to specify another user's home directory. For example:

example% cd ~username

where username is another user's login name, you would change to that user's home directory.

Note –

The Bourne shell does not support the ~ shortcut.

If you use the Bourne shell, your system administrator might have configured the system so that you can type $home to specify your home directory. With this configuration, you type the following command to change your working directory to the subdirectory music in your home directory.

$ cd $home/music

The directory immediately “above” a subdirectory is called the parent directory. In the preceding example, /home is the parent directory of /home/user1. The symbol .. (“dot-dot”) represents the parent directory. The command cd .. changes the working directory to the parent directory, as in this example:

$ pwd
$ cd ..
$ pwd

If your current working directory is /home/user1 and you want to work with some files in /home/user2, type the following command.

$ pwd
$ cd ../user2
$ pwd

../user2 tells the system to look in the parent directory for user2. As you can see, this command is much easier than typing the entire path name /home/user2.