Linux Files

 < Day Day Up > 



You can name a file using any letters, underscores, and numbers. You can also include periods and commas. Except in certain special cases, you should never begin a filename with a period. Other characters, such as slashes, question marks, or asterisks, are reserved for use as special characters by the system and should not be part of a filename. Filenames can be as long as 256 characters. Filenames can also include spaces, although to reference such filenames from the command line, you need to be sure to encase them in quotes. On a desktop like GNOME and KDE you do not need quotes.

You can include an extension as part of a filename. A period is used to distinguish the filename proper from the extension. Extensions can be useful for categorizing your files. You are probably familiar with certain standard extensions that have been adopted by convention. For example, C source code files always have an extension of .c. Files that contain compiled object code have a .o extension. You can, of course, make up your own file extensions. The following examples are all valid Linux filenames. Keep in mind that to reference the last name on the command line you would have to encase it in quotes "New book review":

preface chapter2 9700info New_Revisions calc.c intro.bk1 New book review

Special initialization files are also used to hold shell configuration commands. These are the hidden, or dot, files, which begin with a period. Dot files used by commands and applications have predetermined names, such as the .mozilla directory used to hold your Mozilla data and configuration files. Recall that when you use ls to display your filenames, the dot files will not be displayed. To include the dot files, you need to use ls with the -a option. Dot files are discussed in more detail in the chapter on shell configuration, Chapter 9.

As shown in Figure 10-1, the ls -l command displays detailed information about a file. First the permissions are displayed, followed by the number of links, the owner of the file, the name of the group the user belongs to, the file size in bytes, the date and time the file was last modified, and the name of the file. Permissions indicate who can access the file: the user, members of a group, or all other users. Permissions are discussed in detail later in this chapter. The group name indicates the group permitted to access the file object. In Figure 10-1, the file type for mydata is that of an ordinary file. Only one link exists, indicating the file has no other names and no other links. The owner's name is chris, the same as the login name, and the group name is weather. Other users probably also belong to the weather group. The size of the file is 207 bytes and it was last modified on February 20, at 11:55 A.M. The name of the file is mydata.

click to expand
Figure 10-1: File information displayed using the -l option for the ls command

If you want to display this detailed information for all the files in a directory, simply use the ls -l command without an argument.

$ ls -l -rw-r--r-- 1 chris weather 207 Feb 20 11:55 mydata -rw-rw-r-- 1 chris weather 568 Feb 14 10:30 today -rw-rw-r-- 1 chris weather 308 Feb 17 12:40 monday

All files in Linux have one physical format—a byte stream. A byte stream is just a sequence of bytes. This allows Linux to apply the file concept to every data component in the system. Directories are classified as files, as are devices. Treating everything as a file allows Linux to organize and exchange data more easily. The data in a file can be sent directly to a device such as a screen because a device interfaces with the system using the same byte-stream file format as regular files.

This same file format is used to implement other operating system components. The interface to a device, such as the screen or keyboard, is designated as a file. Other components, such as directories, are themselves byte-stream files, but they have a special internal organization. A directory file contains information about a directory, organized in a special directory format. Because these different components are treated as files, they can be said to constitute different file types. A character device is one file type. A directory is another file type. The number of these file types may vary according to your specific implementation of Linux. Five common types of files exist, however: ordinary files, directory files, first-in first-out pipes, character device files, and block device files. Although you may rarely reference a file's type, it can be useful when searching for directories or devices. Later in the chapter, you see how to use the file type in a search criterion with the find command to search specifically for directory or device names.

Although all ordinary files have a byte-stream format, they may be used in different ways. The most significant difference is between binary and text files. Compiled programs are examples of binary files. However, even text files can be classified according to their different uses. You can have files that contain C programming source code or shell commands, or even a file that is empty. The file could be an executable program or a directory file. The Linux file command helps you determine what a file is used for. It examines the first few lines of a file and tries to determine a classification for it. The file command looks for special keywords or special numbers in those first few lines, but it is not always accurate. In the next example, the file command examines the contents of two files and determines a classification for them:

$ file monday reports monday: text reports: directory 

If you need to examine the entire file byte by byte, you can do so with the od (octal dump) command. The od command performs a dump of a file. By default, it prints every byte in its octal representation. However, you can also specify a character, decimal, or hexadecimal representation. The od command is helpful when you need to detect any special character in your file or if you want to display a binary file.



 < Day Day Up > 



Red Hat(c) The Complete Reference
Red Hat Enterprise Linux & Fedora Edition (DVD): The Complete Reference
ISBN: 0072230754
EAN: 2147483647
Year: 2004
Pages: 328

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net