OpenWindows Advanced User's Guide

3.3.4 Change Working Directory (cd)

The cd (change directory) command allows 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 /home/user1:

$ cd
$ pwd

In the C shell, 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, would change to that user's home directory.

Note -

If you are using the Bourne shell, the ~ shortcut will not work.

If you are using the Bourne shell, it may be possible that your system administrator has configured the system so that you can type $home to specify your home directory. If this is the case, then typing:

$ $home/music

changes you to the subdirectory music in your home directory. Likewise, typing:

$ $homeusername

changes you to the specified user's home directory, where username represents another user's login name.

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. Therefore, the command cd .. changes the working directory to the parent directory, as in this example:

$ pwd
$ cd ..
$ pwd

Suppose your current working directory is /home/user1 and you want to work with some files in /home/user2. Here is a useful shortcut:

$ pwd
$ cd ../user2
$ pwd

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