UNIX - The cd Command

Using cd for navigation As a webmaster, you should have some idea of how your site is structured. Specifically, what directories you have created and where you have files located. Using the cd command is identical to the DOS equivalent of cd. cd followed by the directory name will move you into that particular directory. For example, lets say you have just telnetted into your account. You begin at the root of your account structure (which in most cases, you will have your public_html and wwwlogs directory in front of you) and you need to get to your public_html directory. By typing in cd public_html you will see output similar to this:

www: {1} % cd public_html
www: {2} %

The display will not say where you are. But if you do not get an error, then you have successfully moved into the directory you are trying to get to.

Moving out of a directory: Moving out of a directory is also very much like DOS. The cd command followed by two periods (".") will successfully back you out of the directory you are located in. Unlike DOS, you MUST have a space between the cd and the .. :

www: {4} % cd ..
www: {5} %

No matter where you are located in your directory structure, if you need to get back to your root (maybe you are lost, or just need to get back to square one), the cd command followed by the tilde (~) will take you back to your root. The following example commands shows a user: listing the contents of the root, move into the public_html directory, move into the cgi-bin directory, list the contents of the cgi-bin directory, move back to the root, and list the contents:

www: {1} % ls
public_html    wwwlogs
www: {2} % cd public_html
www: {3} % cd cgi-bin
www: {4} % ls -l
total 1
-rwxr-xr-x 1 sexsite user 3835 Sep 30 14:06 counter.cgi
www: {5} % cd ~
www: {6} % ls
public_html    wwwlogs
www: {7} %

You can also move through multiple directories with one command. If a user is in the root of their account and they want to go into the cgi-bin directory, which is located in the public_html directory, multiple directory names separated by the forward slash (/) can accomplish the task:

www: {1} % cd public_html/cgi-bin
www: {2} % ls -l
total 1
-rwxr-xr-x 1 sexsite user 3835 Sep 30 14:06 counter.cgi
www: {3} % cd ~
www: {4} %
The final use of the cd command that we will cover is the use of the tilde(~) and login name to navigate from any location of your account. From any location in your account, you can go to any other directory within your account with one command. This uses the tilde, followed by your login name, then the directory path. For example, if your login is sexsite (which you use for ftp, etc), and you wish to go into a directory called pics, which is located in a directory called members, which is located in your public_html directory, the following command would be used:
www: {1} % cd ~sexsite/public_html/members/pics
www: {2} %

Successfully done, you will receive output similar to the above. Any typos will cause this to fail. Unix is case sensitive with everything you do. So make sure you have lower case and upper case where applicable to your directories and files.