The Unix File-system and the home directory.

One of the primary features of the Unix Operating system is its file system and directory protocol.

For our purposes, a file system is a mechanism which is used to track, control, and access information in a storage device. A storage device can be partitioned into several file systems with a variety of features. And the separate file systems can be presented to users as a single directory structure using the directory protocol.

Suggested wikipedia reading : file system

On Unix/Linux, it is possible to 'mount' different file systems/partitions on a single directory structure. We will touch on mounting systems at a later time.

A key feature of the Unix file system is the inode structure. Each stored file is assigned to an inode and all access to the file is performed via the inode

The Unix directory protocol provides the framework for tracking a file's assigned inode and thus the file itself. Directory files list an assigned file name and the file's inode. A single file system can list multiple file name assignments for regular files and some other file types.

Viewed as an inverted tree, the Unix file system's primary directory file is root directory represented by the forward slash, /, and located at the top. Below is a simplified example of a directory tree.

This was generated with the help of the tree command.

In the root directory, a variety of files are 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 Unix password system and copied to the user's Unix command shell variable, $HOME, as part of the login process.

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 most 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 most 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 or information are taken.

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

You can find the name and location of your home directory by displaying the contents of the variable $HOME.

Exercise :
# Lines beginning with octothorpe, #, and in italics are comments, don't bother entering.

# Log into your Unix/Linux account. Log-in instructions for new users

# 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, enter the following and press [enter] :

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 command at the prompt. Run the following 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.



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

Each directory file 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 can see these files by using ls with one of its options.

A command option is usually specified by entering a hyphen and a letter after the command (and before pressing [enter]). The -a or "all" option lists all file name in current directory including 'hidden' file names, those starting with a period such as .bashrc and are normally NOT displayed by a plain ls


Another useful ls option is the -l or "long listing". 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.

Exercise :
# List all files in current directory including hidden files.

ls -a

# Take a momemt to look this over. We will discuss a few of these in other modules.
# Now try the following :

ls -al | head -20

# This is a commpound command statement. The modified output of the ls is piped into the input of the head command which will display only the first 20 lines of information.

Notice that hidden file names are listed. The -l As a new user, you will find this list fairly short. But over time, this list may grow to be several screens long.

Try the following :

The | or pipe connects the output of ls to the input of head -20 command. This command and its option will limit the results to only the first 20 lines.



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