A file on a modern computer system is a named block of information accessible to a computer program and stored on some type of non-volatile memory.
Files can contain both programs and data, and data files can store text, images, sound, video, and many other kinds of data. The two most common types of data files for web designers are text files and image files. Web pages are written in text files.
Operating systems organize files through the use of a file system. File systems provide tools for the management of files and directories. A directory (or folder) is a special type of file that can contain other files and directories within it. Directories are used to organize files to make them easier to find.
Since a directory can have directories inside it, and those directories can directories inside them, and so on, we end up with a tree structure for the file system.
The screenshot above shows the
tree program display
of a directory named
webappdev that has four subdirectories named
Each of these subdirectories has two more subdirectories named
unix contains two files,
extention suggests these are text files.
A directory that contains a file or directory is called the
parent directory of that file or subdirectory. In the example above,
notes directory is the parent directory of the
lesson2.txt text files, and the
webappdev directory is the parent of the
A modern computer system has hundreds of thousands of files and directories. By utilizing the tree structure of the file system, it becomes possible to organize and manage these hundreds of thousands of files. Each file is located in a nested series of directories. The sequence of these nested directories ending with the name of the file is called the path to that file.
At the top of the Unix file system is what is called the root directory,
which is always just
/ in Unix. The absolute path to
any file in the filesystem is the sequence of directories, starting from the
root and ending with the file.
The easiest way to show how this works is by example. The following diagram shows part of a Unix filesystem tree.
The absolute path to the file
The absolute path to a file in the file system can be long, and it is normally
the case that the user is interested in files that are located in only one
small part of the system, located near the user. By
near the user we
mean near in the tree to the user's
working directory. You can think of the current working directory as your
present location as you move around the file system tree.
Again, it's much easier to show you than to tell you.
The screenshot above shows the
pwd program displaying the
current working directory as
it shows ls being run, with
vim directories as output. Lastly,
tree is run
again, this time with no
The relative path from the current working directory to the file
Notice that relative paths do not start with a slash (
In expressing relative paths we need a way to indicate both our current
working directory and its parent directory. Unix provides a very short way to
do this. The current working directory is referred to with a single dot
.) and the parent directory is referred to with two dots
..). Note that since each file or directory can have only a
single parent, using
.. to refer to this parent directory is
The follow unix commands are used to list the contents of the current working directory, print the current working directory itself, move from one directory to another, create a new directory, and remove an existing directory.
has several useful command line options which start with a
- (dash) character followed by one or more letters.
ls -lS, and
ls -lat are all useful forms.
directory_name if it is empty. If not empty, a
warning will be returned and the directory will not be removed.
webappdev directory tree displayed above with the
webappdev directory located in the user's home directory
/home/[username]/), typing the command:
cd webappdev/unix at the command prompt would change the current
working directory to
ls command would then reveal the two subdirectories,
display the full path to the current working directory:
To move up one level in the directory tree, typing
cd .. will
change the current working directory to
ls here will display the four subdirectories
The following exercises will give you practice with each of these new commands.
Note that the files that end in
.txt in these exercises are text
files, not directories. Use the following command to create these files:
$ touch [file_name]
We will learn a better way to create and edit text files in the next lesson.
storage) on the computer systems you use. What do you think volatile memory is?