?? ae5
字號(hào):
.NHCUT AND PASTE WITH UNIX COMMANDS.PPOne editing area in which non-programmersseem not very confidentis in what might be called`cut and paste' operations _changing the name of a file,making a copy of a file somewhere else,moving a few lines from one place to another in a file,inserting one file in the middle of another,splitting a file into pieces,andsplicing two or more files together..PPYet most of these operations are actually quite easy,if you keep your wits about youand go cautiously.The next several sections talk about cut and paste.We will begin with the.UXcommandsfor moving entire files around,then discuss.UL edcommandsfor operating on pieces of files..SHChanging the Name of a File.PPYou have a file named `memo'and you want it to be called`paper'instead.How is it done?.PPThe.UXprogram that renames filesis called.UL mv(for `move');it `moves' the file from one name to another, like this:.P1mv memo paper.P2That's all there is to it:.UL mvfrom the old name to the new name..P1mv oldname newname.P2Warning: if there is already a file around with the new name,its present contents will besilentlyclobberedby the information from the other file.The one exception is that you can't move a fileto itself _.P1mv x x.P2is illegal..SHMaking a Copy of a File.PPSometimes what you want is a copy of a file _an entirely fresh version.This might be because you want to work on a file, andyet save a copy in case something gets fouled up,or just because you're paranoid..PPIn any case, the way to do it is with the.UL cpcommand..UL cp \& (stands for `copy';the.UC UNIXsystemis big on short command names,which are appreciated by heavy users,but sometimes a strain for novices.)Suppose you have a file called`good'andyou want to save a copy before you make somedramatic editing changes.Choose a name _`savegood'might be acceptable _ then type.P1cp good savegood.P2This copies`good'onto`savegood',and you now have two identical copies of the file`good'.(If`savegood'previously contained something,it gets overwritten.).PPNow if you decide at some time that you want to getback to the original state of`good',you can say.P1mv savegood good.P2(if you're not interested in`savegood'any more), or.P1cp savegood good.P2if you still want to retain a safe copy..PPIn summary, .UL mvjust renames a file;.UL cpmakes a duplicate copy.Both of them clobber the `target' fileif it already exists, so you had betterbe sure that's what you want to do.ulbeforeyou do it..SHRemoving a File.PPIf you decide you are really done with a fileforever, you can remove itwith the.UL rmcommand:.P1rm savegood.P2throws away (irrevocably) the file called`savegood'..SHPutting Two or More Files Together.PPThe next step is the familiar one of collecting two or morefiles into one big one.This will be needed, for example,when the author of a paperdecides that several sections need to be combinedinto one.There are several ways to do it,of which the cleanest, once you get used to it,is a program called.UL cat .(Not .ulall.UC UNIX programs have two-letter names.).UL catis short for`concatenate', which is exactlywhat we want to do..PPSuppose the job is to combine the files`file1'and`file2'into a single file called`bigfile'.If you say.P1cat file.P2the contents of`file'will get printed on your terminal.If you say.P1cat file1 file2.P2the contents of`file1'and then the contents of`file2'will.ulbothbe printed on your terminal,in that order.So.UL catcombines the files, all right,but it's not much help to print them on the terminal _we want them in `bigfile'..PPFortunately, there is a way.You can tellthe systemthat instead of printing on your terminal,you want the same information put in a file. The way to do it is to add to the command linethe character.UL >and the name of the filewhere you want the output to go.Then you can say.P1cat file1 file2 >bigfile.P2and the job is done.(As with.UL cpand.UL mv ,you're putting something into`bigfile',and anything that was already there is destroyed.).PPThis ability to`capture' the output of a programis one of the most useful aspects ofthe .UC UNIXsystem.Fortunately it's not limited to the.UL cat program _you can use it with .ulanyprogram that prints on your terminal.We'll see some more uses for it in a moment..PPNaturally, you can combine several files,not just two:.P1cat file1 file2 file3 ... >bigfile.P2collects a whole bunch..PPQuestion:is there any difference between.P1cp good savegood.P2and.P1cat good >savegood.P2Answer: for most purposes, no.You might reasonably ask why there are two programsin that case,since.UL catis obviously all you need.The answer is that .UL cpwill do some other things as well,which you can investigate for yourselfby reading the manual.For now we'll stick to simple usages..SHAdding Something to the End of a File.PPSometimes you want to add one file to the end of another.We have enough building blocks now that you can do it;in fact before reading further it would be valuableif you figured out how.To be specific,how would you use.UL cp ,.UL mvand/or.UL catto add the file`good1'to the end of the file`good'?.PPYou could try.P1cat good good1 >tempmv temp good.P2which is probably most direct.You should also understand why.P1cat good good1 >good.P2doesn't work.(Don't practice with a good `good'!).PPThe easy way is to use a variant of.UL > ,called.UL >> .In fact,.UL >> is identical to.UL >except that instead of clobbering the old file,it simply tacks stuff on at the end.Thus you could say.P1cat good1 >>good.P2and`good1'is added to the end of`good'.(And if`good'didn't exist,this makes a copy of`good1'called`good'.)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -