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

📄 u2

📁 unix v7是最后一个广泛发布的研究型UNIX版本
💻
📖 第 1 页 / 共 2 页
字号:
.SHII.  DAY-TO-DAY USE.SHCreating Files \(em The Editor.PPIf you have to type a paper or a letter or a program,how do you get the information stored in the machine?Most of these tasks are done withthe.UC UNIX``text editor''.UL ed .Since.UL edis thoroughly documented in .UL ed (1) 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 called.UL junkwith some text in it, do the following:.P1.ta .65ied junk	\fR(invokes the text editor)\f3a	\fR(command to ``ed'', to add text)\f3.ft Inow type inwhatever text you want ....ft 3\&.	\fR(signals the end of adding text)\f3.P2The ``\f3.\fR'' that signals the end of adding text must beat the beginning of a line by itself.Don't forget it,for until it is typed,no other.UL edcommands will be recognized \(emeverything you type will be treated as text to be added..PPAt this point you can do various editing operationson the text you typed in, such as correcting spelling mistakes,rearranging paragraphs and the like.Finally, you must write the information you have typedinto a file with the editor command.UL w :.P1w.P2.UL edwill respond with the number of characters it wroteinto the file .UL junk ..PPUntil the.UL wcommand,nothing is stored permanently,so if you hang up and go homethe information is lost.\(dg.FS\(dg This is not strictly true \(emif you hang up while editing, the data you wereworking on is saved in a file called.UL ed.hup ,which you can continue with at your next session..FEBut after.UL wthe information is there permanently;you can re-access it any time by typing.P1ed junk.P2Type a.UL qcommandto quit the editor.(If you try to quit without writing,.UL edwill print a.UL ?to remind you.A second.UL qgets you out regardless.).PPNow create a second file called .UL tempin the same manner.You should now have two files,.UL junkand.UL temp ..SHWhat files are out there?.PPThe.UL ls(for ``list'') command lists the names(not contents)of any of the files that.UC UNIXknows about.If you type.P1ls.P2the response will be.P1junktemp.P2which are indeed the two files just created.The names are sorted into alphabetical order automatically,but other variations are possible.For example,the command.P1ls -t.P2causes the files to be listed in the order in which they were last changed,most recent first.The.UL \-loption gives a ``long'' listing:.P1ls -l.P2will produce something like.P1-rw-rw-rw-  1 bwk   41 Jul 22 2:56 junk-rw-rw-rw-  1 bwk   78 Jul 22 2:57 temp.P2The date and time are of the last change to the file.The 41 and 78 are the number of characters(which should agree with the numbers you got from.UL ed )..UL bwkis the owner of the file, that is, the personwho created it.The.UL \-rw\-rw\-rw\- tells who has permission to read and write the file,in this case everyone..PPOptions can be combined:.UL ls\ \-ltgives the same thing as.UL ls\ \-l ,but sorted into time order.You can also name the files you're interested in,and .UL lswill list the information about them only.More details can be found in .UL ls (1)..PPThe use of optional arguments that begin with a minus sign,like.UL \-tand.UL \-lt ,is a common convention for.UC UNIXprograms.In general, if a program accepts such optional arguments,they precede any filename arguments.It is also vital that you separate the various arguments with spaces:.UL ls\-lis not the same as.UL ls\ \ \-l ..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.P1ed junk1,$p.P2.UL edwill reply with the count of the characters in .UL junkand 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.UL edcan handle(several thousand 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.UL cat ,the simplest of all the printing programs..UL catsimply prints on the terminal the contents of all the filesnamed in a list.Thus.P1cat junk.P2prints one file, and.P1cat junk temp.P2prints two.The files are simply concatenated (hence the name.UL cat '') ``onto the terminal..PP.UL prproduces formatted printouts of files.As with .UL cat ,.UL prprints all the files named 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,.P1pr junk temp.P2will print.UL junkneatly,then skip to the top of a new page and print.UL tempneatly..PP.UL prcan also produce multi-column output:.P1pr -3 junk .P2prints.UL junkin 3-column format.You can use any reasonable number in place of ``3''and .UL prwill do its best..UL prhas other capabilities as well;see.UL pr (1)..PPIt should be noted that.UL pris.ulnota formatting program in the sense of shuffling lines aroundand justifying margins.The true formatters are.UL nroffand.UL 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.UL oprand.UL lpr .Which to use depends onwhat equipment is attached to 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 it a new name),like this:.P1mv junk precious.P2This means that what used to be ``junk'' is now ``precious''.If you do an.UL lscommand now,you will get.P1precioustemp.P2Beware 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 .UL cpcommand:.P1cp precious temp1.P2makes a duplicate copy of .UL preciousin.UL temp1 ..PPFinally, when you get tired of creating and movingfiles,there is a command to remove files from the file system,called.UL rm ..P1rm temp temp1.P2will remove both of the files named..PPYou will get a warning message if one of the named files wasn't there,but otherwise.UL rm ,like most.UC UNIXcommands,does its work silently.There is no prompting or chatter,and error messages are occasionally curt.This terseness is sometimes disconcertingto new\%comers,but experienced users find it desirable..SHWhat's in a Filename.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 have already seen, for example,that in the.UL lscommand,.UL ls\ \-tmeans to list in time order.So if you had a file whose namewas.UL \-t ,you would have a tough time listing it by name.Besides the minus sign, there are other characters whichhave special meaning.To avoid pitfalls,you would do well to use only letters, numbers and the perioduntil you're familiar with the situation..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 .UL edwill not handle really big files.Thus you should type the document as a number of files.You might have a separate file for each chapter,called.P1chap1chap2.ft Retc....P2Or, if each chapter were broken into several files, you might have.P1chap1.1chap1.2chap1.3\&...chap2.1chap2.2\&....P2You 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.P1pr chap1.1 chap1.2 chap1.3 .......P2but you would get tired pretty fast, and would probably even make mistakes.Fortunately, there is a shortcut.You can say.P1pr chap*.P2The.UL *means ``anything at all,''so this translates into ``print all fileswhose names begin with .UL chap '',listed in alphabetical order..PPThis shorthand notationis not a property of the.UL prcommand, by the way.It is system-wide, a service of the programthat interprets commands(the ``shell,''.UL sh (1)).Using that fact, you can see how to list the names of the files in the book:.P1ls chap*.P2produces.P1chap1.1chap1.2chap1.3\&....P2The.UL *is not limited to the last position in a filename \(emit can be anywhereand can occur several times.Thus.P1rm *junk* *temp*.P2removes all files that contain.UL junkor.UL tempas any part of their name.As a special case,.UL *by itself matches every filename,so.P1pr *.P2prints all your files(alphabetical order),and.P1rm *.P2removes.ulall files.(You had better be.IT  very sure that's what you wanted to say!).PPThe.UL *is not the only pattern-matching feature available.Suppose you want to print only chapters 1 through 4 and 9.Then you can say.P1pr chap[12349]*.P2The.UL [...]means to match any of the characters inside the brackets.A range of consecutive letters or digits can be abbreviated,so you can also do this with.P1pr chap[1-49]*.P2Letters can also be used within brackets:.UL [a\-z]matches any character in the range.UL athrough.UL z ..PPThe.UL ?pattern matches any single character,so.P1ls ?.P2lists all files which have single-character names,and.P1ls -l chap?.1.P2lists information about the first file of each chapter.UL chap1.1 \&, (.UL chap2.1 ,etc.)..PPOf these niceties,.UL *is certainly 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.UL * ,.UL ? ,etc.,enclose the entire argument in single quotes,as in.P1ls \(fm?\(fm.P2We'll see some more examples of this shortly..SHWhat's in a Filename, Continued.PPWhen you first made that file called.UL junk ,how did the systemknow that there wasn't another.UL junksomewhere else,especially since the person in the next office is alsoreading this tutorial?The answer is that generally each user has a private.IT directory ,which contains only the files that belong to him.When you log in, you are ``in'' your directory.Unless you take special action,when you create a new file,it is made in the directory that you are currently in;this is most often your own directory,and thus the file is unrelated to any other file of the same namethat might exist in someone else's directory..PPThe set of all filesis organized into a (usually big) tree,with your files located several branches into the tree.It is possible for you to ``walk'' around this tree,and to find any file in the system, by starting at the rootof the tree and walking along the proper set of branches.Conversely, you can start where you are and walk toward the root..PPLet's try the latter first.The basic tools is the command.UL pwd(``print working directory''),which prints the name of the directory you are currently in..PPAlthough the details will vary according to the system you are on,

⌨️ 快捷键说明

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