The Linux File System
The Directory Tree
Every normal file is data stored somewhere
on a device (e.g. hard drive, floppy drive, cd-rom, etc.).
A filename may contain:
- uppercase letters (A-Z)
- lowercase letters (a-z)
- numbers (0-9)
- underscore ( _ )
- period (. ) (usually called a "dot")
- comma ( , )
- (sometimes, a space or other symbols
may be included if they are preceded by a backslash ( \ )
Note that filenames that start with a
dot will usually only show up in the directory listing if you use the -a
option with ls. (ls -a)
A directory is a special file that
keeps a list of filenames and the location of their data.
Since a directory is also a file,
a directory can keep track of the location of other directories as
well as any other kind of file.
The base of the Linux directory tree is
called the root directory. The root directory is specified
with a single forward slash: / (this
is below the question mark on most keyboards)
Other directories branch off of the root,
- and others
Other directories branch from these directories,
and still more directories branch from those, and so on, creating a directory
Since devices are treated by Linux as files,
they can be mounted (using the mount
command) into a directory. All devices used by Linux (hard drives, cd-roms,
keyboards, monitors, etc.) usually have entries in the directory tree.
Each directory is called by its pathname.
root directory --> usr --> share -->
emacs --> 20.7 --> etc The
current directory is etc. You can find the
pathname of the current working directory by using the command pwd.
Every user generally has a home directory.
If your username is abear, then your home directory
(here at Parkland) is:
This is an example of an absolute pathname.
An absolute pathname starts from the root directory (the preceding
/) and lists all the directories
in the tree to the desired directory, separated by forward slashes.
There are many shortcuts. One is the
tilde ( ~, above the backquote, near the upper-left
corner of the keyboard). The home directory of abear can be quickly referred to like this:
A file in abear's
home directory called verse could be referred to like this:
These are examples of relative pathnames.
When we specify the filename relative to something other than the root--
in this case, a user's home directory-- it is considered a relative pathname.
An absolute pathname always starts from the root.
(Hint: if you use the command cd by
itself, it will change the current working directory to your home directory.)
To change directories, use the cd command. Examples:
(changes directory) to public_html, a directory
located in the current working directory. (found with pwd).
to the user aboar's home directory using the relative pathname
this does the same as the last example,
but uses an absolute pathname instead.
Each directory has two special directories
in it. They are . (dot) and .. (dot dot). (You can only see these special
directories if you use the -a option when using ls, since their filenames
both start with a dot.)
. (dot) is another name for the current
.. (dot dot) is another name for the
parent directory, one directory earlier in the tree. An example:
(changes the current working directory) to public_html
to the current working directory. (it does nothing)
to the current directory's parent directory, and we're back where
Changing the Directory Tree
You too can feel the joy of your very
own branches of the Linux directory tree. You can make new directories with
the mkdir command, and remove them with the rmdir command.
creates a new directory called new_directory in the current working directory.
permanently removes the directory called
new_directory. Note that the directory
must be empty to be removed by rmdir. (The rm
-r command will recursively delete a directory with all the files
and other directories in it. Be careful with rm -r )