Here is an example in which user bohr goes exploring and is careful to
keep track of where he is and what is around him:
login:bohr | User bohr logs in. |
Password: | Bohr enters password - you can't see it. |
Welcome to OSU's Comphy Mate | See, Unix really is friendly! |
% pwd | Print working directory. |
/usr/bohr | Ah, my home directory. |
% ls | List files and subdirectories. |
class homefire.burn letters | |
% cd class | Move to subdirectory class. |
% ls -CF | Coded listing. |
mybin/ plot* hw | A directory (/), executable (*), & plain files. |
% cd .. | Move to preceding directory. |
% pwd | Tell me where I am! |
/u/bohr | Ah, home again. |
% cd bohr/class/mybin | Go directly to subdirectory mybin. |
Notice that the computer gives no response after changing
directories. This is typical for many Unix commands; if they work
properly, the computer simply returns the prompt. If not, you get an
error message. At first, bohr moved forward in small steps, and later
jumped around in really big steps by using the full path names. Big
steps are quicker, but for beginners it is probably more comforting to
move step by step, letting the computer tell you where you are at each
step and what's there. This is not so tedious if the cd and ls commands are combined, for example,
% cd; ls | Move to home directory, list files. |
class homefire.burn letters | The old files at home. |
% cd class | Move to class directory. |
% ls | List files. |
mybin plot hw | Files in class. |
To tell what's in a directory without going through the trouble of
changing into it, just issue the ls command indicating the
path leading to that directory from the present one. For example,
% ls /usr/local | List contents of directory usr/local. |
bin class lib slatec src | The contents. |
Even if local is a file rather than a directory, listing it
won't spill out its contents or do any harm. Unix will just tell you
its name (the ls -l version tells you about the file).
Now we
list the contents of a directory two levels below usr
(without visiting it):
% ls /usr/local/class | List contents of class in /usr/local. |
exam.f | |
% ls -l /usr/local/class/exam.f | Long listing of file exam.f. |
-rw-r-r- 1 bohr 3784 Mar 2 18:57 src/asr/asr2.c |