⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 u2

📁 UNIX版本6的源代码
💻
📖 第 1 页 / 共 2 页
字号:
.SHII.  DAY-TO-DAY USE.SHCreating Files _ The Editor.PPIf we have to type a paper or a letter or a program,how do we get the information stored in the machine?Most of these tasks are done withthe.UC UNIX``text editor''.C ed .Since.C edis thoroughly documented in .SE ed (I) and explained in.ulA Tutorial Introduction to the UNIX Text Editor,we won't spend any time here describing how to use it.All we want it for right now is to make some.ulfiles.(A file is just a collection of information stored in the machine,a simplistic but adequate definition.).PPTo create a file with some text in it, do the following:.B1 ed	(invokes the text editor) a	(command to ``ed'', to add text).I now type in whatever text you want ....R \fB.\fP	(signals the end of adding text).B2At this point we could do various editing operationson the text we typed in, such as correcting spelling mistakes,rearranging paragraphs and the like.Finally, we write the information we have typedinto a file with the editor command ``w'':.B1w junk.B2.C edwill respond with the number of characters it wroteinto the file called ``junk''..PPSuppose we now add a few more lines with ``a'',terminate them with ``.'',and write the whole thing out as ``temp'', using.B1w temp.B2We should now have two files, a smaller one called ``junk'' and a bigger one(bigger by the extra lines) called ``temp''.Type a ``q'' to quit the editor..SHWhat files are out there?.PPThe.C ls(for ``list'') command lists the names(not contents) of any of the files that.UC UNIXknows about.If we type.B1ls.B2the response will be.B1junktemp.B2which are indeed our two files.They are sorted into alphabetical order automatically,but other variations are possible.For example,if we add the optional argument ``-t'',.B1ls -t.B2lists them in the order in which they were last changed,most recent first.The ``-l'' option gives a ``long'' listing:.B1ls -l.B2will produce something like.B1-rw-rw-rw-  1 bwk   41 Sep 22 12:56 junk-rw-rw-rw-  1 bwk   78 Sep 22 12:57 temp.B2The date and time are of the last change to the file.The 41 and 78 are the number of characters(you got the same thing from.C ed ).``bwk'' is the owner of the file _ the personwho created it.The ``-rw-rw-rw-'' tells who has permission to read and write the file,in this case everyone..PPOptions can be combined:``ls -lt'' would give the same thing,but sorted into time order.You can also name the files you're interested in,and .C lswill list the information about them only.More details can be found in  .SE ls (I)..PPIt is generally true of.UC UNIXprograms that ``flag'' arguments like ``-t''precede filename arguments..SHPrinting Files.PPNow that you've got a file of text,how do you print it so people can look at it?There are a host of programs that do that,probably more than are needed..PPOne simple thing is to use the editor,since printing is often done just before making changes anyway.You can say.B1ed junk1,$p.B2.C edwill reply with the count of the characters in ``junk''and then print all the lines in the file.After you learn how to use the editor,you can be selective about the parts you print..PPThere are times when it's not feasible to use the editor for printing.For example, there is a limit on how big a file.C edcan handle(about 65,000 characters or 4000 lines).Secondly, itwill only print one file at a time,and sometimes you want to print several, one after another.So here are a couple of alternatives..PPFirst is.C cat ,the simplest of all the printing programs..C catsimply copies all the files in a list onto the terminal.So you can say.B1cat junk.B2or, to print two files,.B1cat junk temp.B2The two files are simply concatenated (hence the name ``cat'')onto the terminal..PP.C prproduces formatted printouts of files.As with .C cat ,.C prprints all the files in a list.The difference is that it produces headings with date, time, page number and file nameat the top of each page,andextra lines to skip over the fold in the paper.Thus,.B1pr junk temp.B2will list ``junk'' neatly,then skip to the top of a new page and list``temp'' neatly..PP.C prwill also produce multi-column output:.B1pr -3 junk .B2prints ``junk'' in 3-column format.You can use any reasonable number in place of ``3''and .C prwill do its best..PPIt should be noted that.C pris.ulnota formatting program in the sense of shuffling lines aroundand justifying margins.The true formatters are.C roff ,.C nroff ,and.C troff ,which we will get to in the section on document preparation..PPThere are also programs that print fileson a high-speed printer.Look in your manual under.C oprand.C lpr .Which to use depends on the hardware configurationof your machine..SHShuffling Files About.PPNow that you have some files in the file systemand some experience in printing them,you can try bigger things.For example,you can move a file from one place to another(which amounts to giving a file a new name),like this:.B1mv junk precious.B2This means that what used to be ``junk'' is now ``precious''.If you do an.C lscommand now,you will get.B1precioustemp.B2Beware that if you move a file to another onethat already exists,the already existing contents are lost forever..PPIf you wantto make a.ulcopyof a file (that is, to have two versions of something),you can use the .C cpcommand:.B1cp precious temp1.B2makes a duplicate copy of ``precious''in``temp1''..PPFinally, when you get tired of creating and movingfiles,there is a command to remove files from the file system,called.C rm ..B1rm temp temp1.B2will remove all of the files named.You will get a warning message if one of the named files wasn't there..SHFilename, What's in a.PPSo far we have used filenames without ever saying what'sa legal name,so it's time for a couple of rules.First, filenames are limited to 14 characters,which is enough to be descriptive.Second, although you can use almost any characterin a filename,common sense says you should stick to ones that are visible,and that you should probably avoid characters that might be usedwith other meanings.We already saw, for example,that in the.C lscommand,``ls -t'' meant to list in time order.So if you had a file whose namewas ``-t'',you would have a tough time listing it by name.There are a number of other characters whichhave special meaning either to.UC UNIXas a whole or to numerous commands.To avoid pitfalls,you would probably do well to use only letters, numbers and the period.(Don't use the period as the first character of a filename,for reasons too complicated to go into.).sp.PPOn to some more positive suggestions.Suppose you're typing a large documentlike a book.Logically this divides into many small pieces,like chapters and perhaps sections.Physically it must be divided too,for .C edwill not handle big files.Thus you should type the document as a number of files.You might have a separate file for each chapter,called.B1.ne 3chap1chap2etc....B2Or, if each chapter were broken into several files, you might have.B1.ne 7chap1.1chap1.2chap1.3 ...chap2.1chap2.2 ....B2You can now tell at a glance where a particular file fits into the whole..PPThere are advantages to a systematic naming convention which are not obviousto the novice.UC UNIX user.What if you wanted to print the whole book?You could say.B1pr chap1.1 chap1.2 chap1.3 .......B2but you would get tired pretty fast, and would probably even make mistakes.Fortunately, there is a shortcut.You can say.B1pr chap*.B2The ``*'' means ``anything at all'',so this translates into ``print all fileswhose names begin with `chap' '',listed in alphabetical order.This shorthand notationis not a property of the.C prcommand, by the way.It is system-wide, a service of the programthat interprets commands(the ``shell''.SE sh (I)).Using that fact, you can see how to list the files of the book:.B1ls chap*.B2produces.B1.ne 4chap1.1chap1.2chap1.3 ....B2The ``*'' is not limited to the last position in a filename _it can be anywhere.Thus.B1rm *junk*.B2removes all files that contain ``junk''as any part of their name.As a special case, ``*'' by itself matches every filename,so.B1pr *.B2prints all the files(alphabetical order),and.B1rm *.B2removes.ulall files.(You had better be sure that's what you wanted to say!).PPThe ``*'' is not the only pattern-matching feature available.Suppose you want to print only chapters 1 through 4 and 9 of thebook.Then you can say.B1pr chap[12349]*.B2The ``[...]'' means to match any of the characters inside the brackets.You can also do this with.B1pr chap[1-49]*.B2``[a-z]'' matches any character in the range.ulathrough.ul z.There is also a ``?'' character, which matches any single character,so.B1pr ?.B2will print all files which have single-character names..PPOf these niceties,``*'' is probably the most useful,and you should get used to it.The others are frills, but worth knowing..PPIf you should ever have to turn off the special meaningof ``*'', ``?'', etc.,enclose the entire argument in quotes (single or double),as in.B1ls "?".B2

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -