The Unix Filesystem 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 filesystem 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 filesystem and relationship of your home directory in it.

The Unix filesystem provides the framework for keeping track of files. Viewed as an inverted tree, the Unix filesystem'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 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/lx 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. 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 :

#( 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 to the home directory.

You can view the contents of a directory with ls, the list command. ls supports several options that affect the type of information listed. A command option is usually specified by entering a hyphen and a letter after the command (and before pressing [enter]). The letter chosen specifies how to modify how or what is listed.

All directories contain two files that are not displayed by a plain ls. These are . (period or dot} and .. (double period or double dot). Each directory listing has an entry for itself represented by a single dot and an entry for the directory it is listed in, its parent directory, represented by a 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.

Files that begin with a period or . are not displayed by the plain ls command but are considered "hidden".

To see these "hidden" files, run ls with the -a option :

ls -a

Notice that several additional files are listed. You may even find that so many files are listed, they scroll off of the screen. We can pipe the output of a command to another command which allows us to pause the display or limit the number of lines displayed.

If a large number of files were displayed, try the following command sequence instead :

ls -a | head

The | is a pipe and it connects the output of the 1st command to the input of the second command. In this case, the output of ls gets fed as input to head. head's job is to display the 1st 10 lines of any input or files specified. We will look at head's options later.

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 :

ls -la

Use the -a option to guarantee at least 2 files are listed. Because the -l option lists one file per line, you may again find that the listing will fill more than one screen. Try piping it to head.


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.

When less is more - peaking in files.
Overview