The cd (change directory) command allows you to move around within the file system hierarchy:
$ cd /usr/lib $ pwd /usr/lib |
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 /home/user1 |
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.
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 /home/user1 $ cd .. $ pwd /home |
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 /home/user1 $ cd ../user2 $ pwd /home/user2 |
../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.