next up previous contents index
Next: Using mkdir to Create Up: Storing Information Previous: Looking at Directories with

The Current Directory and cd

Using directories would be cumbersome if you had to type the full path each time you wanted to access a directory. Instead, Unix shells have a feature called the ``current'' or ``present'' or ``working'' directory. Your setup most likely displays your directory in your prompt: /home/larry. If it doesn't, try the command pwd, for present working directory. ; ; ; ;

screen5058

As you can see, pwd tells you your current directorygif--a very simple command. Most commands act, by default, on the current directory, such as ls. We can change our current directory using cd;. For instance, try:

screen5065

A generic template looks like:

cd [directory]

If you omit the directory, you're returned to your home, or original, directory. Otherwise, cd will change you to the specified directory. For instance:

screen5073

As you can see, cd allows you to give either absolute or relative pathnames. An ``absolute'' path starts with / and specifies all the directories before the one you wanted. A ``relative'' path is in relation to your current directory. In the above example, when I was in /usr, I made a relative move to local/bin--local is a directory under usr, and bin is a directory under local!

There are two directories used only for relative pathnames: ``.'' and ``..''.; ;. The directory ``.'' refers to the current directory and ``..'' is the parent directory. These are ``shortcut'' directories. They exist in every directory, but don't really fit the ``folder in a folder'' concept. Even the root directory has a parent directory--it's its own parent!

The file ./chapter-1 would be the file called chapter-1 in the current directory. Occasionally, you need to put the `` ./'' for some commands to work, although this is rare. In most cases, ./chapter-1 and chapter-1 will be identical.

The directory ``..'' is most useful in backing up:

screen5097

In this example, I changed to the parent directory using cd .., and I listed the directory /usr/src from /usr/local using ../src. Note that if I was in /home/larry, typing ls -F ../src wouldn't do me any good!

One other shortcut for lazy users: the directory ~/ is your home directory;:

screen5107

You can see at a glance that there isn't anything in your home directory! Actually, ~/ will become more useful as we learn more about how to manipulate files.


next up previous contents index
Next: Using mkdir to Create Up: Storing Information Previous: Looking at Directories with

Converted on:
Mon Apr 1 08:59:56 EST 1996