home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 1.28 Some Gotchas with Background Processing Chapter 1
Next: 1.30 Redirecting Input and Output

1.29 When Is a File Not a File?

UNIX differs from most operating systems in that it is file-oriented. The designers of UNIX decided that they could make the operating system much simpler if they treated everything as if it were a file. As far as UNIX is concerned, disk drives, terminals, modems, network connections, etc. are all just files. Some recent versions of UNIX (such as System V Release 4) have gone further: even processes (38.1 ) are files. Like waves and particles in quantum physics, the boundary between files and the rest of the world can be extremely fine: whether you consider a disk a piece of hardware or a special kind of file depends primarily on your perspective and what you want to do with it.

Therefore, to understand UNIX, you have to understand what files are. A file is nothing more than a stream of bytes - that is, an arbitrarily long string of bytes with no special structure. There are no special file structures, and only a few special file types (for keeping track of disks and a few other purposes). The structure of any file is defined by the programs that use it, and not by the UNIX operating system. [5] You may hear users talk about file headers and so on, but these are defined by the applications that use the files, and not by the UNIX filesystem itself.

[5] Many executable files - programs - begin with a magic number . This is a special two-byte-long sequence that tells the kernel how to execute the file.

UNIX programs do abide by one convention, however. Text files use a single newline character (linefeed) between lines of text, rather than the carriage return-linefeed combination used in DOS or the carriage returns used in the Macintosh. This difference may cause problems when you bring files from other operating systems over to UNIX. DOS files will often be littered with carriage returns (CTRL-m), which are necessary for that operating system but are superfluous for UNIX. These carriage returns will look ugly if you try to edit or print the file and may confuse some UNIX programs. Mac text files will appear to be one long line with no breaks. Of course, you can use UNIX utilities to convert DOS and Mac files for UNIX-see article 1.5 .

- ML

Previous: 1.28 Some Gotchas with Background Processing UNIX Power Tools Next: 1.30 Redirecting Input and Output
1.28 Some Gotchas with Background Processing Book Index 1.30 Redirecting Input and Output

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System