Directories in UNIX
If you’re one of those people who’s only used a GUI, or you save all of your files on your Desktop, this sub-section is for you. There are plenty of web sites that discuss directories; this is just a brief overview.
The “folders” that you see when you look at your GUI are actually
directories in your operating system. That tells you what a directory
is: a container for other files, including other directories. The
separator for directory names is “/”, so
a/b/c is directory
b within directory
Everything in UNIX is within a directory. Yes, even your Desktop;
typically, that is a directory whose name is
~/Desktop. That leads
us to common abbreviations and commands for directories when you’re
using the command line:
~<account>means the home directory of the user <account>2. Just plain
~means your own home directory. So
~/Desktopmeans a directory named Desktop within your home directory.
cdis the command to “change directory.” It’s the usual way to go from one directory to another. If there were a directory named
Root3 in your home directory, you could visit that directory with:
> cd ~/Root
..is a reference to your parent directory, the one “above” the one you’re currently in. If you wanted to return to your home directory from
~/Root, you could type:
> cd ..
If you use the
cdcommand without any arguments, it will return you to your home directory:4
To look at the contents of your current directory, use the
You can also list the contents of any other directory (for which you have permission to view):
> ls ~seligman/root-class
If you forget which directory you’re in, use the
pwd(“print working directory”) command:
Now you know why it’s hard to put a / in a folder name: The operating system can’t tell the difference between a / that’s within a folder name versus a / that is a directory separator.
It’s always something like “~seligman” (tilde-seligman), never “–seligman” (dash-seligman). Depending on the exact font used to print or display this tutorial, sometimes tildes look like dashes. On most keyboards, tilde is typed with SHIFT-` where ` (backtick) is near the upper-left-hand corner of the keyboard.
UNIX is normally a case-sensitive operating system.
~/rootare three different directories. Exception: In Mac OS Darwin, file names are case-insensitive; all three of those directories would be the same.
Knowing this will become useful in the future, as you become more sophisticated in your use of UNIX. Eventually you’ll learn about shell variables. Sooner or later, you’ll make a typo in a variable name; e.g.,
Instead of going to
$ROOTSYS, your intended destination, you’ll find yourself in your home directory. That’s because
$ROTSYSdoesn’t have a value, so UNIX interpreted this as the
cdcommand without any arguments.