-->
Previous | Table of Contents | Next |
by Jack Tackett
The term Linux file system has two different and often conflicting meanings: the file system of disks and mechanisms of the disks, and the logical file system that the user sees and manipulates. This chapter is about the logical Linux file system that you see and manipulate. If youre familiar with PC operating systems such as MS-DOS and OS/2, youll find many of the following topics familiar because the file structures of MS-DOS from version 2.0 onward were modeled on those of UNIX, which is the file structure used by Linux.
Every physical and logical entity in Linux is represented as a file in the Linux file system. The physical entities include disks, printers, and terminals; logical entities include directories and, of course, ordinary filesthe kind that store documents and programs.
In Linux, just as in other operating systems such as MS-DOS, you must distinguish between a filename and a path name. A filename consists of a simple series of contiguous letters, numbers, and certain punctuation marks. Filenames cant contain spaces or any characters that represent a field separator. For example, the filename johns.letter is valid, but johns letter isnt.
A filename shouldnt contain any characters that have special meaning to the shell. These are the forbidden special characters:
Also, a filename cant contain the front slash character (/) because this character is used to indicate path names. (Path names are discussed later in this section.)
NOTE: Actually, you can use any of the forbidden characters if you place double quotation marks around the filename like this:! johns.letterHowever, youll have a hard time accessing such a file with most programs, and the file isnt very portable to other UNIX systems.
Most early versions of UNIX, on which Linux is based, limited filenames to 14 characters; however, Linux allows 256 characters in a filename. Some recent UNIX versions, such as the Berkeley version (BSD), allow 64-character filenames, but only the first 14 are significant. Because one of the goals of Linux is portability, in the interest of writing portable programs and shell scripts, you might want to limit yourself to 14-character filenames.
A path name can contain any number of characters. In Linux, files dont exist in a vacuum; they exist in a directory. The highest directory in Linux is called the root and is symbolized by the slash character (/). If a file named fred exists in the root directory, its absolute path name is /fred. When you add a user to the system with the adduser command, he or she is assigned a home directory. By convention, this home directory is usually found under root in a directory named, appropriately enough, home. Therefore, if a user named Fred is assigned a directory named /home/fred, all files that Fred creates are attached to the /home/fred directory. An absolute path name for one of Freds files might be /home/fred/freds.file. An absolute path name specifies exactly where a file is stored in the file system.
Another kind of path name is a relative path name, which unambiguously points to a files location as relative to the current directory. If Fred is in his home directory, for example, the filename freds.file is also a relative path name, relative to his current directory. To find out which directory is your current directory, use the command pwd (print working directory). You can also check the contents of the $PWD environment variable with the command echo $PWD to see which directory is the current working directory.
You can define a file anywhere in the Linux file system with relative path names by using two pseudonyms found in all directories. The single dot (.) refers to the current directory, and the double dot (..) refers to the parent directory. MS-DOS and OS/2 use this same convention.
If Fred is in /home/fred, he can point to /fred by using ../../fred. In this relative path name, the second double dot points to /home (the parent directory of /home/fred), and the first double dot points to the parent directory of /homenamely, the root.
The pseudonym for the current directory, the single dot, comes in handy if you want to move files. If Fred wants to move /fred to his current directory, he can do so with absolute path names by using this command:
mv /fred fred
Alternatively, Fred can use the pseudonym for the current directory by using this command:
mv /fred.
Most Linux commands operate on path names. In most cases, the path name you use is the name of a file in the current directory. The default path name points to your current directory. If Fred is in his home directory (/home/fred), all three of the following are equivalent commands:
command freds.letter command /home/fred/freds.letter command ./freds.letter
NOTE: Although a difference exists between filenames and path names, directories are files, too. When naming directories, remember that you must follow the same naming guidelines as for ordinary files.Also note that unlike many PC-based operating systems, Linux doesnt have the concept of disk-drive letters, only directory paths. Linux deals with disk drive letters only when working with MS-DOS file systems on floppies with the m- commands (such as mcopy)
See Understanding File Systems, p. 266
Linux lumps everything into four basic types of files: ordinary files, directories, links, and special files. There are several kinds of ordinary files, links, and special files and a large number of standard directories. The basic file types are described in the following sections.
You can use the command file to determine the type of a file. file can recognize a file type as executable, text, data, and so on. Many UNIX commands are only shell scripts or are interpreted programs similar to MS-DOS batch files, and file can report whether a UNIX command is a binary executable program or simply a shell script. Its also useful for determining whether the file is text-based and, therefore, whether it can be viewed or edited. The syntax for the file command is as follows:
file [-vczL] [-f namefile] [-m magicfile] filelist
Previous | Table of Contents | Next |