The UNIX/Linux file system vs. The User

How the user uses and relates to the Linux file system.

What is a file system?

A file system is an organization of storage space designed to contain files in directories. There are many types of file systems, the primary file system of Linux is the "Second Extended File System".

Important points:

1) No drive letters. All file systems (which exist on mass-storage devices such as hard drives, CD-ROMS's, floppy drives, ZIP drives, network mounts, etc..) Are "mounted" onto one logical tree. A "mount point" is a directory where a file system is attached to the tree.

For example, my systems mount table looks like this:

File system 1024-blocks Used Available Capacity Mounted on
/dev/hda1         74629  21493  49282      30%   /
/dev/hdb4        891705 356757 488883      42%   /home
/dev/hdb2         69776   1812  64361       3%   /tmp
/dev/hda2        792800 425003 326822      57%   /usr
/dev/hda5        595163 535096  29325      95%   /usr/local
/dev/hdb3        218119  43549 163306      21%   /usr/src
/dev/hda3        595195  13935 550516       2%   /var
/dev/hdd2        218119   6656 200199       3%   /usr/local/postgres
/dev/hdd3         59527   2365  54088       4%   /usr/local/httpd
/dev/hda6        430305   6855 401226       2%   /var/spool/news
/dev/hdc        490434  490434      0     100%   /mnt/cdrom
/dev/fd0          1423     521    902      37%   /mnt/floppy

which includes a CD-ROM, a MS-DOS floppy disk, and ten hard drive partitions across three physical drives. A user can transparently navigate among all these devices. This allows data/files to be moved easily, for additional capacity to be added with minimal re-configuration of services/applications, and for support of new storage devices without changing the way things work.

2) There is a standard layout. A document called the FSSTD codifies how a file system tree is laid out, compliance is voluntary, but most distributions follow it quite closely. This means you will "always" find the X Windows System binaries, kernel images, configuration files, etc... in the same place across most distributions.

Notable Directories
/sbinPrograms to configure, boot and repair the system.
/libSystem and Shared Libraries
/usr/binCommon stand-alone executable (I.e. df, ls, more, etc..)
/usr/includeC/C++ header files for system and shared libraries.
/usr/localPackages and applications added by the "local" system's administrator.
/etcMany configuration files
/usr/X11R6The X Windows Distribution, libraries, binaries, and configuration files.
/opt, /usr/optMany commercial packages (I.e. Word Perfect, NeXs, Wingz) traditionally like to be installed here.

3) Unlike FAT the (MS-DOS file system), the ext2 file system enforces a security model. In a long directory listing 'ls -l' you will see a owner, a group owner, and a string representing certain "permissions". Permissions are a way of controlling who can access a file, and how it can be accessed. There are three type of file permissions:
r or 4 = Read Access
w or 2 = Write Access
x or 1 = Execute (this file is a program)

Directories also have permissions. For the most part they are the same as file permissions, as the directory is itself actually a file. The primary exception is that the "Execute" property means "scan", i.e. I list the contents of a directory (perform an 'ls' command).

4) Everything is a file. As stated above, directories are files. But so is your physical hard drive, your serial and parallel ports, and even the bit bucket. There are "special" files that serve the purpose of letting processes communicated with the underlying OS and physical devices. In a long directory "ls -l" the first character indicates the file type. Most files will be a "-" indicating a "regular" file that

brw-rw-r-- 1 root floppy 2,     21 May 5 20:32 fd1h360
brw-rw-r-- 1 root floppy 2,     25 May 5 20:32 fd1h720
lrwxrwxrwx 1 root root           4 Oct 4 18:05 ftape -> rft0
crw-r--r-- 1 root root   1,      7 May 5 20:32 full
-rwxrwxrwx 1 awilliam users    128 Oct 11 18:00 regular_file

contains some data. A directory is indicated by a "d". For special device files the character is a "c" or a "b" depending on whether the device moves data one character at a time (like a tape drive) of a block of data at a time (like a hard drive). Most "special" files are found in the "/dev" directory. Some important "special" files are:

FileDescription
/dev/null

The bit bucket. Everything sent here goes nowhere. If you read it you receive nothing.

/dev/zeroEmits an endless string of nulls as you read it.
/dev/ttyS0Your first serial port, like DOS COM1:
/dev/ttyS1Your second serial port, like DOS COM2:
/dev/lp1Your parallel/printer port, like DOS LPT1:
/dev/audioYour sound card's speaker.
/dev/fd0Your first floppy drive, like DOS A:. But remember this represents the device, not a readable disk.

5) Links. Most UNIX file systems, including ext2, support a file type known as a link. There are in fact two type of links, hard links and soft or symbolic links. A link allows a file to appear in more than one directory. A hard links cannot span file systems, and is actually an additional reference to a file stored in that file system. Deleting the "original" file will not remove the file until the last hard link has been removed as well (the link count equals zero). A symbolic link is a special type of file that only stores the path to the "original" file, and this type of file can span file systems. Deleting a symbolic link will not delete the "original" file, and deleting the original file will not removed the link, but leave it "unresolved." An attempt to read an unresolved link will result in a "File Not Found" message, which can be confusing.

-rw-r--r-- 2 awilliam users 0 Oct 12 22:29 original
-rw-r--r-- 2 awilliam users 0 Oct 12 22:29 original.hardlink
lrwxrwxrwx 1 awilliam users 8 Oct 12 22:29 original.symlink -> original

Symbolic links can result in strange behavior over network mounts and in backups if the client machine is unable to access the file the link references. Most commands like tar, and subsystems like NFS, have special flags to indicate how to handle symbolic links.

Links can be very powerful for solving the problem of application that want to live, or find files, in places other than where you want them. For example, my copy of Word Perfect wants to line in /opt, and my copy of Z-mail wants to live in /usr/opt. But I want them both in /usr/local/opt in order to stay within the FSSTD. So I can make /opt, and /usr/opt links to /usr/local/opt before installing both applications, and they never know the difference.

File system related commands
UNIX CommandMS/DR-DOS
Equivalent
Command's function
lsdirList contents of a directory
cdcdChange current directory
mkdirmkdir, mdMake a directory
rmdirmkdir, rdRemove a directory
rmdelRemove a file or directory
cpcopy, xcopyCopy a file or directory
mvmoveMove a file
chownn/aChown owner of a file or directory
chgrpn/aChange group-owner of a file or directory
chmodn/aChange access permission of a file or directory
cattypePlay a file to standard-out
wcn/aCount words or lines in a file
moremorePlay a file to standard-out one screen or line at a time
findfindFind a file
grepn/aFind matches of a "regular expression" in a file