The Unix File-system and your home directory.

The Unix Operating system "views" the world as either a file or a process (a running program) or sometimes as both. As a result, its two primary features are its file-system and its process control mechanisms. The first feature is to provide the efficient storage and retrieval of files created by a user and control over who can access these files. The other feature provides moderated access and control to processes started by users or even other processes.

We will look at both features in detail in later modules. But for now, we need to take a quick tour of the structure of the file-system and relationship of your home directory in it.

The Unix file-system provides the framework for keeping track of files. Viewed as an inverted tree, the Unix file-system's primary directory file is root located at the top.

The root, the top most directory specified by the forward slash "/", is the one file that can always be located by the Linux/Unix operating system.

In the root directory, a variety of files can be listed including other directory files, executable programs, data files, and/or special purpose files that provide the Unix system's versatility.

Each directory listed under root in turn can also contain a list various files and directories.

Just as root is the most important directory for the operating system, the user's home directory is the most important directory for the user.

The location and name of a user's home directory is determined by the system administrator when a user's account is set up. Its location is then stored in the user's entry in the password system and copied to the user's Unix command shell variable $HOME.

The user's home directory name is most likely the same as the user's login id. And it is a common practice to group or list all users' home directories together under a single parent directory set apart from the other directories and files used by the operating system. On our system /home/hopper or /home/turing contains all users' home directories.

The user's home directory is the initial "current working directory" accessed by the user when he/she logs in. Any file manipulation actions taken by the user will apply to files in this directory unless additional steps are taken.

The user owns this directory and generally has control over all files found in it.

To find the name and location of your home directory, you may display the contents of the variable $HOME, echo $HOME. The log-in procedure initializes the $HOME variable to the appropriate value by reading information from your entry in the password file system. It also uses this information to make your home directory your current working directory when you log in.

Exercise :

# Lines beginning with octothorpe, #, are comments, don't bother entering.

# Log into your Unix/Linux account. If you are logging in for the 1st time, read module for current account activation.

# To see the contents of $HOME, enter the following command at the prompt and press the [enter] key :

echo $HOME

# Whenever you need to reset the current working directory to the home directory, use the command :

cd $HOME

# To see what files are in the current working directory ( your home directory, if you just logged in ), run the ls command. If your account is new, you may find few or no files are listed.

# Press the [enter] key after you have entered a particular command line. Run the commands :

ls
ls $HOME

#Both commands should list the same files.

Several command shells also support using cd by itself or combined with the symbol ~, cd ~, to reset the current working directory to the user's home directory.


You can view the contents of a directory with ls, the list command.

ls supports several options that affect the type or format of information listed.

A command option is usually specified by entering a hyphen and a letter after the command (and before pressing [enter]). For example :

ls -a

lists all files in current directory including 'hidden' files, filenames that start with a period such as .bashrc, which are not displayed by a plainls


Linux variation on options : in an effort to be more user friendly, Linux has developed an alternative format for options that use whole words for the options. e.g ls --all. We will mention these as we examine various commands.

All directories contain two special purpose hidden files, . (period or dot} and .. (double period or double dot).

Each directory listing has an entry for itself represented by the single dot and an entry for the directory it is listed in, its parent directory, represented by the double dot. This allows the directory listings to act as doubly linked list of directory names and makes it easy for users to move around in the directory tree. We will look at . and .. later when working with absolute and relative paths.

There may be additional files starting with a . (period), such as .bashrc. These are usually files containing configuration information for various commands. We will look at some of these when discussing the relevant command or feature.

You may see a collection of these in your home directory. Try the following :

# The ls -a lists all files in current directory including hidden files.
# The | or pipe connects the output of ls to the input of grep
# The grep filters out all file names except those that start with a period.

ls -a | grep "^\."

Notice that several additional files are listed. As a new user, you will find this list fairly short. But over time, this list may grow to be several screens long.

Another ls option you will find useful throughout the semester is the long listing (-l). This option instructs ls to list the type of file, access permissions, number of names associated with the file, time file last modified, its size, and finally its name. We will look at each of these fields in detail later. To see a long listing, enter :

# The -a formats the output as long listing, with additional 
# information about file size, ownership, permissions, etc.
# The | or pipe connects the output of ls to the input of grep
# The grep filters out all file names except those that start with a period.

ls -a | head -20

ls -al

Because the -l option lists one file per line, you may again find that the listing will fill more than one screen.


For now, work in your home directory to experiment and explore the various commands we will discuss. Eventually, you will learn how to create sub-directories and restrict access to it to protect your work.

Lectures