5.E: Creating Directories | 5: Managing Files and Directories | 5.C: Changing Directories - Carefully |
By now you may be wondering if there is a quicker way to change directories. There is. With just one command you can do the equivalent of several list commands and change directory commands.
Because most of the files you access will be in or near your home
directory, perhaps the most useful cd
command is:
> cd ~
> cd
either one of which returns you to your home directory. Now check this
by printing the working directory:
> pwd
The list command with recursive option ls -R
no only lists
names of files and directories, but also the contents of the directories:
> ls -FCR
The listing of your home directory should look something like:
Mwm a.out* eqns2.ms public-html/ sample.doc
README.first development/ plotoutfile.ps s2
development:
data/ prog/
development/prog:
area.f
To see what the recursive -R
buys you, compare that listing to the output of
ls -FC *
:
Mwm a.out* plotoutfile.ps sample.doc
README.first eqns2.ms s2
development:
data/ prog/
You can change directly to a specific directory without jumping from branch
to branch on the directory tree. Just give cd
the
pathname of the target directory.
The pathname is the sequence of directories that lead to a file. It can be specified three ways. The full pathname has the form
> cd /u1/home/yourusername/development/prog
Here the leading
/
represents the topmost or root directory, and
u1/home
is where users' home directories are kept on some
make-believe computer (it's not the same on all Unix systems). You can also
give the pathname starting from the abbreviated form of your home
directory, for example,
> cd ~/development/prog
Or, you can give the relative pathname from the present (working) directory in either of two forms
> cd development/prog
> cd ./development/prog
Notice that the subdirectories in pathnames are separted by the the
which represents
the "root" or very top of the directory tree (owned by the user
root). It is unlikely you will work in the root directory unless
you become a system administrator. Nevertheless, it is educational for you
to look at what's in the root directory, at least if you follow the cavaet,
"look, but do not change":
If you want to know more about directory structure, try
A Scientist's and Engineer's Guide to
Workstations.
Remember, if you find yourself in the root directory, or anywhere else
you do not want to be, or should not be, you can always return home. You do not
even have to know where you are to get home, all roads lead you there:
Instead of going home, let's jump directly to our
Now do a
/
or "slash" symbol. (The /
functions
similarly to the backslash \ in DOS.) The exception to this
being the leading slash as in
/u1/home/yourusername/development/prog
> cd /
> ls -FC
cd
cd ~
~/development/prog
directory:
> cd ~/development/prog
pwd
to check where you are. You might want to try some exploring
with the cd
and ls
commands before going on to
Creating Directories.
5.E: Creating Directories
5: Managing Files and Directories
5.C: Changing Directories - Carefully