next up previous
Next: Processes Up: Basic GNU/Linux Internals Previous: Basic GNU/Linux Internals

Files and Filesystems

A file is a chunk of data that the kernel (or you) can manipulate in various ways. Files are stored in directories (``folders'' under MacOS and Windows). Documents are often ``text files,'' programs can be either ``executable binary files'' (.exe files in DOS) or ``scripts'' (DOS .bat files), several files may be archived and compressed as a single file, and so on. In GNU/Linux, everything18 is a file from the kernel's point of view. Almost all processes function by reading from and writing to files, and processes communicate using files called ``pipes'' and ``sockets''. Files are stored in a treelike structure called a filesystem. The root of the tree is the root directory, called  /. In the root directory are the ``core'' system directories,

/bin /boot /dev /etc /lib /root /sbin /tmp,
which contain ordinary files; a couple of directories ( /mnt and /proc) that are used internally for system functions; and three directories called /home, /usr, and /var, where all the ``interesting'' files and programs reside. The core directories and their contents must be present for the system to run at all. The others are needed for normal operation. (In rare situations, such as emergency recovery from a hardware crash, /usr, /home, and /var are not needed.) Each directory has a descriptive name: /bin and /sbin contain, respectively, binaries (that is, executable program files) needed by the administrator and system binaries (which are used by the kernel); /boot contains files the system needs immediately upon startup (namely the kernel itself and the system map, which contains memory locations of kernel modules); /dev contains device files, by which the kernel interacts with hardware; /etc contains configuration and initialization files, mostly as plain text; /lib contains ``statically linked libraries'' that are needed to run programs, and kernel modules; /root is root's home directory; and /tmp contains temporary files that are created by running processes.

A GNU/Linux filesystem is built by mounting filesystems that reside on a storage medium (usually the hard drive, but possibly a floppy or CD). The directory /mnt contains empty directories that serve as mount points for auxiliary filesystems. To view the contents of a floppy disk under GNU/Linux, you must first mount the disk's filesystem on an empty directory (such as /mnt/floppy). You may not simply insert and remove floppies or CDs from a GNU/Linux system. The /proc directory is used by the kernel for bookkeeping of running processes, and is useful as a tool for determining what devices the kernel knows about, or how much memory is free. This directory resides solely in RAM, not on the hard drive.

Users' home directories reside in /home. The /usr directory contains most of the software and data (word processors, web browsers, games, ...), and finally, /var contains files whose content changes frequently (``variable files''), such as mail, printer, and news spools, name server databases, and system log files.

If you try to modify (or sometimes merely view) certain files or directories, you may get the message permission denied. This means exactly what it says; you do not have write (or read) permission on the file in question. If you (as an ordinary user) try to remove a system file, you should receive this message. (Do not experiment like this as root.)

Every file in the root filesystem has a unique name, called its full pathname. The text file that was processed to make this document is called

If I were visiting the directory /home/hwang/GNU, I could refer to this file by its ``relative pathname'' Howto/intro.tex for short.

Filenames are rather different in GNU/Linux than in Windows, though they are not unrelated. First, GNU/Linux filenames should consist only of letters, numbers, periods, dashes, and underscores. Most punctuation characters (including spaces) have special meanings to the shell, and should be avoided in filenames. However, there is no practical limit on lengths of filenames (certainly 256 characters is allowable), and there is no limit on the length of a filename extension. Second, GNU/Linux (like all Unices) is case sensitive; intro.tex, Intro.tex, and intro.TEX are different filenames. Finally, GNU/Linux itself does not look at filename extensions; it does not automatically treat a .txt file differently from an .html file. There are a few naming conventions (needed by application programs), but mostly you're free to use whatever filenames you like.

Table 1: GNU/Linux filesystem permissions
  Ordinary File Directory
Read View file contents View directory contents (if directory is also executable)
Write Modify file contents Add or remove files
Execute Run program file Enter directory

Permissions on ordinary files and directories work differently, see Table 1. The following operations (when permitted) may be performed with the command shown: List the contents of a directory ( ls); view the contents of a file ( cat <filename> or less <filename>); remove a file ( rm <filename>); remove all the files in a directory ( rm -f *); removing the entire contents of a directory, including all subdirectories ( rm -Rf *); move to any point in the filesystem ( cd <target directory>). If a result of a command is forbidden, you will receive a permission denied message for the forbidden portion. For example, if you type ls -aR /, you get a list of all files that reside in directories in which you have both read and execute permissions, and you will get a permission denied message for all directories in which you do not have both permissions.

GNU/Linux uses both RAM and the hard drive for data storage. RAM is faster (by a few orders of magnitude), but the hard drive holds more (by a few orders of magnitude) and retains information even when the power is turned off. GNU/Linux keeps records of running processes, recently modified user files, and other filesystem information in RAM. Because of this, You must never turn the power off without shutting down. Failure to shut down properly may result in lost data and corruption of the filesystem. Shutting down in described in Section 5.1.

next up previous
Next: Processes Up: Basic GNU/Linux Internals Previous: Basic GNU/Linux Internals