Red Hat Enterprise Linux 4: Red Hat Enterprise Linux Step By Step Guide
Prev | Chapter 4. Shell Prompt Basics | Next

# 4.6. Leaving your Current Working Directory

To change directories from your current working directory, use the command `cd`.

    cd /tmp/

The above command changes directories to the `/tmp/` directory. The second word on the command line must be a path. It can either be relative or absolute, and can move one directory or many. If the `cd` command is entered at the shell prompt with no options or path specified, the default action is to move the user into their home directory. For example, user someone would be moved to the `/home/someone/` directory.

The `cd` has many useful options. You can see all of these options by entering `man cd` at the shell prompt. The most commonly used options are listed below.

- cd — Returns you to your login directory

- cd - — Returns you to your previous working directory

- cd ~ — Also returns you to your login directory

- cd / — Takes you to the entire system's root directory.

- cd /root — Takes you to the home directory of the root user. You must be the root user to access this directory.

- cd /home — Takes you to the home directory, where user login directories are usually stored

- cd .. — Takes you to the directory one level up.

- cd ~`otheruser` — Takes you to `otheruser`'s home directory, if `otheruser` has granted you permission.

Below are a few examples of the use of `cd`.

- cd /dir1/dir2/ — Regardless of which directory you are in, this absolute path takes you directly to `dir2`, a subdirectory of `/dir1/`.

- cd ../../dir2/dir3/ — This relative path takes you up two directories, then to `dir2/`, and finally into its subdirectory `dir3/`.

If you attempt to `cd` into a directory you do not have permission to access, you are denied permission to access that directory.

Denying access to the root and other users' accounts (or home directories) is one way your Red Hat Enterprise Linux system prevents accidental or malicious tampering. Refer to Section 4.11 Ownership and Permissions for more information.

Prev | Home | Next
Manipulating Files in Your Current Working Directory | Up | Locating Files and Directories