Header left.png

Unix Home Directory Explained

From Systems Group
Jump to: navigation, search

Files in Unix are organized by listing them in directories. Directories are themselves files, and so may appear within other directories. The result is a tree-like hierarchy. At the root of this tree is a directory known simply as ./. .1 This directory lists various others:
File:Unix-homedir-1.jpg

The bin directory contains many of the programs for performing common Unix commands. The usr directory contains many of the data files that are required by those and other commands. Of particular interest, however, is the home directory, which contains all of the files associated with individual users like you and me. Each individual user gets a directory within home bearing their own login name. For example, lets say your login name is "jdoe".

We can expand our view of the Unix files then as:
File:Unix-homedir-2.jpg

cd and ls are two common Unix commands, as will be explained later. Within your own home directory, I have a directory also named .bin. , containing your own personal programs. Two of these are called .clpr. and .psnup. . So these files are arranged as:
File:Unix-homedir-3.jpg

The full name of any file is given by listing the entire path from the root of the directory tree down to the file itself, with ./. characters separating each directory from what follows. For example, the full names of the four programs in the above diagram are

/bin/cd
/bin/ls
/home/jdoe/bin/clpr
/home/jdoe/bin/psnup

There are some common abbreviations that can be used to shorten file names. You can refer to the home directory of someone with login name name as ~name. You can refer to your own home directory simply as ~. So you could refer to the file containing your clpr program as either /home/jdoe/bin/clpr or ~jdoe/bin/clpr.

When you are logged in, I can refer to this program by either of those two names, or simply as ~/bin/clpr.

At all times when entering Unix commands, you have a .working. directory. If the file you want is within that directory (or within other directories contained in the working directory), the name of the working directory may be omitted from the start of the filename. When you first log in, your home directory is your working directory. For example, when I have just logged in, I could refer to your program simply as bin/clpr, dropping the leading /home/jdoe/ because that would be your working directory at that time. The working directory itself can be referred to as simply ... . The .parent. of the working directory (i.e., the directory containing the working directory) can be referred to as .... .

Unix filenames can be almost any length and may contain almost any characters. As a practical matter, however, you should avoid using punctuation characters other than the hyphen, the underscore, and the period. Also, avoid blanks, and non-printable characters within file names. All of these have special meanings when you are typing commands and so would be very hard to enter within a filename.

Some things to keep in mind about Unix file names that may be different from other file systems you have used: Unix file names are often very long so that they describe their contents.2 The rather perverse exception to this rule is that program/command names are, by tradition, very short, often confusingly so. Upper and lower case letters are distinct in Unix filenames. .YourFile. and .yourfile. are different names. Periods ( ... ) are not treated by Unix as a special character.

.This.Is.a.legal.name. is perfectly acceptable as a Unix filename. Many programs, however, expect names of their data files to end in a period followed by a short .standard. extension indicating the type of data in that file. Thus data files with names like .arglebargle.txt. for text files or .nonsense.cpp. for C source code are common. By convention, files containing executable programs generally do not receive such an extension.

Keep in mind that directories are separated by ./. in file names, not by .\. as is common in some other operating systems.