Saturday, September 5, 2009

Linux Filepaths

The first difference you’ll notice is that Linux does not use drive letters in pathnames. In the Windows world, the physical drives installed on the PC determine the pathname of the file. Windows assigns a letter to each physical disk drive, and each drive contains its own directory structure for accessing files stored on it.

For example, in Windows you may be used to seeing filepaths such as C:\Documents and
Settings\Rich\My Documents\test.doc. This indicates that the file test.doc is located in the directory My Documents, which is under the directory Rich, which is contained under the directory Documents and Settings, which is located on the hard disk partition assigned the letter C (usually the first hard drive on the PC).

The Windows filepath tells you exactly which physical disk partition contains the file named test.doc. If you want to save a file on a floppy disk, you would click the icon for the A drive, which automatically uses the filepath A:\test.doc. This path indicates that
the file is located at the root of the drive assigned the letter A, which is usually the PC’s floppy disk drive.

This is not the method used by Linux. Linux stores files within a single directory structure, called a virtual directory. The virtual directory contains filepaths from all the storage devices installed on the PC, merged into a single directory structure.

The Linux virtual directory structure contains a single base directory, called the root. Directories and files beneath the root directory are listed based on the directory path used to reach them, similar to the way Windows does it.

For example, the Linux filepath /home/rich/Documents/test.doc indicates that the file test.doc is in the directory Documents, under the directory rich, which is contained in the directory home. It doesn’t provide any information about which physical disk on the PC the file is stored on.

The tricky part about the Linux virtual directory is how it incorporates each storage device. The first hard drive installed in a Linux PC is called the root drive. The root drive contains the core, or root, of the virtual directory. Everything else builds from there. On the root drive, Linux creates special directories called mount points. Mount points are directories in the virtual directory structure where you assign additional storage devices.

The virtual directory causes files and directories to appear within these mount point directories, even though they are physically stored on a different drive. Often the system files are physically stored on the root drive, while user files are stored on a different drive.

There are two hard drives on the PC. One hard drive is associated with the root of the virtual directory (indicated by a single forward slash). Other hard drives can be mounted anywhere in the virtual directory structure. In this example, the second hard drive is mounted at the location /home, which is where the user directories are located.

The Linux filesystem structure has evolved from the UNIX file structure. Unfortunately, the UNIX file structure has been convoluted over the years by different flavors of UNIX. These days it seems that no two UNIX or Linux systems follow the same filesystem structure. However, a few common directory names are used for the same functions. Ubuntu makes use of many of the common UNIX directory names.

Ubuntu Directory Names
/ The root of the virtual directory. Normally, no files are placed here

/bin The binary directory, where many GNU user-level utilities are stored

/boot The boot directory, where boot files are stored

/dev The device directory, where Linux creates device nodes

/etc The system configuration files directory

/home The home directory, where Linux creates user directories

/initrd Location of files used during the boot process if a RAM disk is required

/lib The library directory, where system and application library files are stored

/lost+found Directory where lost filesystem nodes are stored. If your disk crashes, look here for missing files

/media Mount point used to mount external disks in the virtual directory

/mnt The mount directory, a common place for mount points used for removable media

/opt The optional directory, often used to store optional software packages

/proc Controlled by the kernel, this special directory provides information about internal kernel processes and can be used to send information to the kernel

/root The root home directory

/sbin The system binary directory, where the GNU admin-level utilities are stored

/srv Used as a base directory on the Ubuntu server platform for data that is served
to others, such as web pages

/sys Similar to the /proc directory, used by the newer Linux kernel to communicate with plug-in kernel modules

/tmp The temporary directory, where temporary work files can be created and
destroyed

/usr The user-installed software directory

/var The variable directory, for files that require write privileges, such as log files

In addition to the way it handles pathnames, Ubuntu has a way of handling filenames that might differ from what you might be used to in Windows.

No comments: