Changing Directories with cd

Changing Directories with cd

To explore Unix and its capabilities, you'll need to move around among the directories. You do so using the cd command, which takes you from the directory you're currently in to one that you specify. Code Listing 1.4 illustrates how you use cd to change directories.

Code Listing 1.4. Using cd, you can change directories and move around in the system. Note that the prompt in this code listing shows the name of the current directory, which can be handy.

[jdoe@frazz jdoe]$ cd / [jdoe@frazz /]$ cd [jdoe@frazz jdoe]$ cd /home/jdoe/Project/ [jdoe@frazz Project]$ cd /etc [jdoe@frazz etc]$ cd /home/jdoe/ [jdoe@frazz etc]$ cd /home/jdoe/mail/ [jdoe@frazz mail]$ cd .. [jdoe@frazz jdoe]$ 

To change directories:


cd Projects

To move to a specific directory, type cd plus the name of the directory. In this example, we move down in the directory tree to a subdirectory called Projects. (See the Moving Up and Down sidebar for an explanation of what "up" and "down" mean in Unix terms.)


cd ..

Type cd .. to move up one level in the directory tree.


cd /etc

Here, /etc tells the system to look for the etc directory located at the system root.

Moving Up and Down

Throughout this book, we'll talk about moving "up" and "down" through the Unix file system. Moving "up" means moving into the directory that contains the current directorythat is, closer to the root directory. Moving "down" means moving into subdirectories that are contained by the current directorythat is, farther from the root directory.


  • If you don't remember the name of the directory you want to change to, you can use ls to list the directories and files in your current directory, then use cd as shown above. See the previous section, Listing Directories and Files with ls, for more information.

  • You can return to your home directory from anywhere in the Unix system by entering cd without specifying a directory.

  • You can often use a tilde (~) as a handy shortcut to your home directory. For example, if you want to change to the Urgent directory within the Projects directory in your home directory, you could use something like cd /home/users/ y/yourid/Projects/Urgent or just use the shortcut cd ~/Projects/Urgent

  • Keep in mind that your home directory isn't the same as the system root directory. You might think of your home directory as "the very small section of the Unix system that I can call my own." Every person using the Unix system has his or her own little personal section.

    The current directory is always indicated with a ., while the next higher directory (the one that contains the current directory) is indicated with .. That is why you use cd .. to move up a directory. In Chapter 10, you will see a specific use for . to specify the current directory when running scripts or programs.

  • Visit Chapter 2 for much more about directories and files.

Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: