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

Navigating the filesystem

The following sections explain how to find out where you are in the directory tree, how to move from directory to directory, and how to list the contents of a directory.

Finding out where you are in the system

After a number of cd operations, it is possible to lose track of where you are in the filesystem. To identify your current directory, use the pwd(1) (print working directory) command. This command takes no arguments.

The output from pwd shows the absolute pathname of your current directory. For example, if your login is johnd and you are in your home directory (which is a subdirectory of /usr), the output would probably look like the following:

   $ pwd
   /usr/johnd

If you are using the Korn shell (see ``Identifying your login shell'' if you are unsure about this), you will find it useful to issue the following command as soon as you log in, or add it to your login script:

   alias pwd='pwd -P'
The reason for this is explained in ``Navigating symbolic links''.

Changing directory

Once a directory system exists, you need to know how to get from one directory to another, thereby changing your current working directory. This is done using the cd(1) (change directory) command. As an argument to the command, you specify the directory you want to change to, as follows:

cd directory

For example, if your current directory is /u/johnd, you can to change to a directory called /u/workfiles/projects by specifying its absolute pathname, as follows:

   $ cd /u/workfiles/projects
You can also change to the directory by specifying its relative pathname, as follows:
   $ cd ../workfiles/projects


NOTE: You must have execute permission on a directory before you can change to it. See ``Access control for files and directories''.

See ``Returning to your home directory'' for details of a special usage of cd.

Returning to your home directory

You can return to your home directory from anywhere in the directory structure by typing cd on its own.

Your home directory is stored in the HOME environment variable. You can display this value using the following command line:

   $ echo $HOME
Remember to include the dollar sign in the command line: without it, the echo(1) command will simply return the word ``HOME''. For an explanation of environment variables, see ``Understanding variables''. For more on the echo command, see ``Forcing a program to read standard input and output''.

A useful tool for filesystem navigation is the tilde character (~). The shell expands a tilde to the absolute pathname of your home directory. This notation can be included in a pathname, as follows:

   $ pwd
   /tmp
   $ cd ~/i486/dev/backup/scripts
   $ pwd
   /usr/martins/i486/dev/backup/scripts
Because the pathname is absolute, you do not need to know where it is in relation to your current working directory.

The tilde can also be used in conjunction with other users' login names, acting as a shorthand way of accessing their files without necessarily knowing exactly where their home directories are located. For example, the following command line allows you to check a colleague's directories for any file called hyacinth:

   $ find ~john -follow -name hyacinth -print
(See ``Finding files'' for how to use the find command.)

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 22 April 2004