DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Directories and files

Changing directories

To change to a new directory, type cd (change directory) and the pathname of the directory you want to change to, then press <Enter>:

   $ pwd
   /u/susannah
   $ cd /usr/adm
   $ pwd
   /usr/adm
You tell cd which directory to change to by giving it an argument. You can use either a relative or an absolute (starting with ``/'') pathname as an argument to cd.

If you type cd with no arguments, you go to your home directory:

   $ pwd
   /etc
   $ cd
   $ pwd
   /u/susannah
You can also change to your home directory by saying cd $HOME:
   $ pwd
   /usr/lib
   $ cd $HOME
   $ pwd
   /u/susannah
Try moving around some directories now:

  1. Type pwd and press <Enter> to see where you are starting from.

  2. Next type cd /etc to go to the etc directory, one directory down from root. (The /etc directory is where many system administration tools are stored.)

  3. Type pwd and press <Enter> to check that you are in the right place.

  4. Then type cd default; pwd and press <Enter>. (See the ``Q and A'' section below for an explanation of the use of ``;'' between commands.)

  5. Type cd /usr/spool/lp/requests. You should see a message like /usr/spool/lp/requests: Permission denied. (/usr/spool/lp/requests is a directory the computer uses to store printer requests temporarily.)

  6. Type pwd and press <Enter>.

  7. You type cd; pwd <Enter> to return to your home directory and check that you are there.
    $ pwd
    /u/susannah
    $ cd /etc
    $ pwd
    /etc
    $ cd default; pwd
    /etc/default
    $ cd /usr/spool/lp/requests
    /usr/spool/lp/requests: Permission denied
    $ pwd
    /etc/default
    $ cd; pwd
    /u/susannah
    

Q: Why do I have to press <Enter> after every command?

A: The carriage return you type at the end of a command line tells the computer to process the command.

Q: What does the ``;'' do between two commands?

A: The semicolon (;) is a command separator. It tells the computer that the next word is the start of a separate command, instead of an argument for the previous command.

$ cd; pwd
This says ``change directory, print working directory.''
$ cd pwd
This says ``change to the directory named pwd.''

Semicolons allow you to put more than one command on a line before you press <Enter> to have all the commands processed.

Q: What does the message Permission denied mean?

A: The UNIX system uses file and directory permissions to control who can look at, and who can change, files. These permissions are discussed in ``Protecting files and directories''. When you see the message Permission denied it means the permissions on a directory are set so you cannot go into the directory. This is frequently the case for system directories, such as /usr/spool/lp/requests, and for other people's home directories.

Q: What happens if I misspell a directory name?

A: If you misspell a directory name, the computer may attempt to guess what you meant. Type y to accept its guess and change to the directory, or n to return to the prompt:

$ cd /etv
cd /etc? y
$ pwd
/etc

Next topic: Files
Previous topic: Identifying your current directory

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003