📄 ch01_29.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 1] 1.29 When Is a File Not a File? </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:31:40Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch01_01.htm"TITLE="1. Introduction"><LINKREL="prev"HREF="ch01_28.htm"TITLE="1.28 Some Gotchas with Background Processing "><LINKREL="next"HREF="ch01_30.htm"TITLE="1.30 Redirecting Input and Output "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_28.htm"TITLE="1.28 Some Gotchas with Background Processing "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.28 Some Gotchas with Background Processing "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 1<BR>Introduction</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_30.htm"TITLE="1.30 Redirecting Input and Output "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.30 Redirecting Input and Output "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-1017">1.29 When Is a File Not a File? </A></H2><PCLASS="para">UNIX differs from most operating systems in that itis file-oriented. The designers of UNIX decided that they couldmake the operating system much simpler if they treated everything asif it were a file. As far as UNIX is concerned, disk drives,terminals, modems, network connections, etc. are all justfiles. Some recent versions of UNIX (such as System V Release 4) have gonefurther:even<SPANCLASS="link">processes (<ACLASS="linkend"HREF="ch38_01.htm#UPT-ART-4890"TITLE="What's in This Chapter ">38.1</A>)</SPAN>are files. Like waves and particles in quantumphysics, the boundary between files and the rest of the world can beextremely fine: whether you consider a disk a piece of hardware or aspecial kind of file depends primarily on your perspective and whatyou want to do with it.</P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-2446"></A>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 longstring of bytes with no special structure. There are no special filestructures, and only a few special file types (for keeping track ofdisks and a few other purposes). The structure of any file is definedby the programs that use it, and not by the UNIX operating system.[5]You mayhear users talk about file headers and so on, butthese are defined by the applications that use the files, and not bythe UNIX filesystem itself.</P><BLOCKQUOTECLASS="footnote"><PCLASS="para">[5] Many executable files - programs - begin with a <EMCLASS="emphasis">magic number</EM>.This is a special two-byte-long sequence that tells the kernel how toexecute the file.</P></BLOCKQUOTE><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-2452"></A><ACLASS="indexterm"NAME="AUTOID-2455"></A><ACLASS="indexterm"NAME="AUTOID-2457"></A><ACLASS="indexterm"NAME="AUTOID-2460"></A>UNIX programs do abide by one convention, however. Text files use asingle newline character (linefeed) between lines of text,rather than the carriage return-linefeed combination usedin DOS or the carriage returns used in the Macintosh.This difference may cause problems when you bring files from other operatingsystems over to UNIX. DOS files will often be littered with<ACLASS="indexterm"NAME="AUTOID-2463"></A>carriage returns (CTRL-m), which are necessary for that operatingsystem but are superfluous for UNIX. These carriage returns willlook ugly if you try to edit or print the file and may confuse someUNIX programs. Mac text files will appear to be one long line withno breaks.Of course, you can use UNIX utilities to convert DOS and Mac filesfor UNIX-see article<ACLASS="xref"HREF="ch01_05.htm"TITLE="Anyone Can Program the Shell ">1.5</A>.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">ML</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_28.htm"TITLE="1.28 Some Gotchas with Background Processing "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 1.28 Some Gotchas with Background Processing "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch01_30.htm"TITLE="1.30 Redirecting Input and Output "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 1.30 Redirecting Input and Output "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">1.28 Some Gotchas with Background Processing </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">1.30 Redirecting Input and Output </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -