Getting Linux File Facts Straight
Linux files are similar to Unix, DOS, Windows, and Macintosh files. All operating systems use files to store information. Files allow you to organize your stuff and keep them separate. For example, the text that comprises this appendix is stored in a file; all other book elements are stored in their own files. Follow the bouncing prompt as we make short work of long files.
Storing files
We assume that you know that a file is a collection of information identified by a filename and that Linux can store multiple files in directories as long as the files have different names. Linux stores files with the same name in different directories.
Wonderful or not, Linux filenames can be as long as 256 characters. The filenames can contain uppercase and lowercase letters (also known as mixed case), numbers, and special characters, such as underscores (_), dots (.), and hyphens (-). Because filenames can be composed of mixed-case names, and because each name is distinct, these names are case sensitive. For example, the names FILENAME, filename, and FiLeNaMe are unique filenames of different files, but they’re the same filename.Technical StuffAlthough filenames technically can contain wildcard characters, such as asterisks (*) and question marks (?), using them isn’t a good idea. Various command interpreters, or shells, use wildcards to match several filenames at one time. If your filenames contain wildcard characters, you have trouble specifying only those files. We recommend that you create filenames that don’t contain spaces or other characters that have meaning to shells. In this way, Linux filenames are different from DOS and Windows filenames.
Sorting through file types
Linux files can contain all sorts of information. In fact, Linux sees as a file every device (disks, display, or keyboard, for example) except for a network interface. These five categories of files eventually become the most familiar to you:
User data files: Contain information you create. User data files, sometimes known as flat files, usually contain the simplest data, consisting of plain text and numbers. More complex user data files, such as graphics or spreadsheet files, must be interpreted and used by special programs. These files are mostly illegible if you look at them with a text editor because the contents of these files aren’t always ASCII text. Changing these files generally affects only the user who owns the files.
System data files: Are used by the system to keep track of users on the system, logins, and passwords, for example. As system administrator, you may be required to view or edit these files. As a regular user, you don’t need to be concerned with system data files except, perhaps, the ones you use as examples for your own, private startup files.
Directory files: Hold the names of files — and other directories — that belong to them. These files and directories are called children. Directories in Linux (and Unix) are just another type of file. If you’re in a directory, the directory above you is the parent. Isn’t that homey?When you list files with the ls -l command, it displays a list of files and directories. Directory files begin with the letter d; for example:
[lidia@cancun lidia]$ ls -l
drwxr-xr-x 5 lidia lidia 1024 Jul 3 2002 Desktop
drwx------ 2 lidia lidia 1024 Jul 10 2002 nsmail
Special files: Represent either hardware devices (such as disk drives, tape drives, or keyboards) or some type of placeholder that the operating system uses. The /dev directory holds many of these special files. You can see this directory by running this command at a command prompt:
ls -l /dev
Executable files: Contain instructions (usually called programs or shell scripts) for your computer. When you type the name of one of these files, you’re telling the operating system to execute the instructions. Some executable files look like gibberish, and others look like long lists of computer commands. Many of these executable files are located in /bin, /usr/bin, /sbin, and /usr/sbin.
Understanding files and directories
If you live in the Windows world, you can think of a Linux file system as one huge file folder that contains files and other file folders, which in turn contain files and other file folders, which in turn contain files and — well, you get the point. In fact, the Linux file system is generally organized in this way. One big directory contains files and other directories, and all the other directories in turn contain files and directories.
Directories and subdirectories
A directory contained, or nested, in another directory is a subdirectory. For example, the directory named /mother may contain a subdirectory named /child. The relationship between the two is referred to as parent and child. The full name of the subdirectory is /mother/child, which would make a good place to keep a file named /mother/child/reunion that contains information about a family reunion.
The root directory
In the tree directory structure of Linux, DOS, and Unix, the big directory at the bottom of the tree is the root directory. The root directory is the parent of all other directories (the poor guy must be exhausted) and is represented by a single / symbol (pronounced "slash"). From the root directory, the whole directory structure grows like a tree, with directories and subdirectories branching off like limbs.Technical StuffIf you could turn the tree over so that the trunk is in the air and the branches are toward the ground, you would have an inverted tree — which is how the Linux file system is normally drawn and represented (with the root at the top). If we were talking about Mother Nature, you would soon have a dead tree. Because the subject is computer technology, however, you have something that looks like an ever-growing, upside-down tree.
What’s in a name?
You name directories in the same way as you name files, following the same rules. Almost the only way you can tell whether a name is a filename or a directory name is the way the slash character (/) is used to show directories nested in other directories. For example, usr/local means that local is in the usr directory. You know that usr is a directory because the trailing slash character tells you so; however, you don’t know whether local is a file or a directory.TipIf you issue the ls command with the -f option, Linux lists directories with a slash character at the end, as in local/, so you know that local is a directory.The simplest way to tell whether the slash character indicates the root directory or separate directories, or directories and files, is to see whether anything appears before the slash character in the directory path specification. If nothing appears before the slash, you have the root directory. For example, you know that /usr is a subdirectory or a file in the root directory because it has only a single slash character in front of it.
Home again
Linux systems have a directory named /home, which contains the user’s home directory, where she can
Store files
Create more subdirectories
Move, delete, and modify subdirectories and files
Linux system files and files belonging to other users are never in a user’s /home directory. Linux decides where the /home directory is placed, and that location can be changed only by a superuser (root), and not by general users. Linux is dictatorial because it has to maintain order and keep a handle on security.