RSS


[ Pobierz całość w formacie PDF ]
.You could just delete all the way back and retype everythingyou need to, but that takes much too much e ort! Instead, you can use the arrowkeys to move backthere, delete the bad character or two, and type the correct information.There are many special keys to help you edit your command line, most of them similar to thecommands used in GNU Emacs.For instance, C-t ips two adjacent characters.1 You'll be ableto nd most of the commands in the chapter on Emacs, Chapter 8.6.2.2 Command and File CompletionAnother feature of bash is automatic completion of your command lines.For instance, let's look atthe following example of a typical cp command:home larry ls -Fthis-is-a-long-filehome larry cp this-is-a-long-file shorterhome larry ls -Fshorter this-is-a-long-filehome larryIt's a big pain to have to type every letter of this-is-a-long-file whenever you try to accessit.So, create this-is-a-long-file by copying etc passwd to it2.Now, we're going to do theabove cp command very quickly and with a smaller chance of mistyping.Instead of typing the whole lename, type cp th and press and release the Tab.Like magic,the rest of the lename shows up on the command line, and you can type in shorter.Unfortunately,bash cannot read your thoughts, and you'll have to type all of shorter.When you type Tab , bash looks at what you've typed and looks for a le that starts like that.For instance, if I type usr bin ema and then hit Tab , bash will nd usr bin emacs since that'sthe only le that begins usr bin ema on my system.However, if I type usr bin ld and hit Tab ,bash beeps at me.That's because three les, usr bin ld, usr bin ldd, and usr bin ld86 allstart with usr bin ld on my system.If you try a completion and bash beeps, you can immediately hit Tab again to get a list of allthe les your start matches so far.That way, if you aren't sure of the exact spelling of your le, youcan start it and scan a much smaller list of les.1C-t means hold down the key labeled Ctrl", then press the t" key.Then release the Ctrl" key.2cp etc passwd this-is-a-long-file 52 CHAPTER 6.WORKING WITH UNIX6.3 The Standard Input and The Standard OutputLet's try to tackle a simple problem: getting a listing of the usr bin directory.If all we do is lsusr bin, some of the les scroll o the top of the screen.How can we see all of the les?6.3.1 Unix ConceptsThe Unix operating system makes it very easy for programs to use the terminal.When a programwrites something to your screen, it is using something called standard output.Standard output,abbreviated as stdout, is how the program writes things to a user.The name for what you tella program is standard input stdin.It's possible for a program to communicate with the userwithout using standard input or output, but most of the commands I cover in this book use stdinand stdout.For example, the ls command prints the list of the directories to standard output, which isnormally connected" to your terminal.An interactive command, such as your shell, bash, readsyour commands from standard input.It is also possible for a program to write to standard error, since it is very easy to makestandard output point somewhere besides your terminal.Standard error stderr is almost alwaysconnected to a terminal so an actual human will read the message.In this section, we're going to examine three ways of ddling with the standard input and output:input redirection, output redirection, and pipes.6.3.2 Output RedirectionA very important feature of Unix is the ability to redirect output.This allows you, instead ofviewing the results of a command, to save it in a le or send it directly to a printer.For instance,to redirect the output of the command ls usr bin, we place a sign at the end of the line, andsay what le we want the output to be put in:home larry lshome larry ls -F usr bin listinghome larry lslistinghome larryAs you can see, instead of writing the names of all the les, the command created a totally newle in your home directory.Let's try to take a look at this le using the command cat.If you thinkback, you'll remember cat was a fairly useless command that copied what you typed the standardinput to the terminal the standard output.cat can also print a le to the standard output if youlist the le as a parameter to cat:home larry cat listing.home larry 6.3.THE STANDARD INPUT AND THE STANDARD OUTPUT 53The exact output of the command ls usr bin appeared in the contents of listing.All welland good, although it didn't solve the original problem.3However, cat does do some interesting things when it's output is redirected.What does thecommand cat listing newfile do? Normally, the newfile says take all the output of thecommand and put it in newfile." The output of the command cat listing is the le listing.So we've invented a new and not so e cient method of copying les.How about the command cat fox? cat by itself reads in each line typed at the terminalstandard input and prints it right back out standard output until it reads Ctrl-d.In this case,standard output has been redirected into the le fox.Now cat is serving as a rudimentary editor:home larry cat foxThe quick brown fox jumps over the lazy dog.press Ctrl -dWe've now created the le fox that contains the sentence The quick brown fox jumps over thelazy dog." One last use of the versitile cat command is to concatenate les together.cat willprint out every le it was given as a parameter, one after another.So the command cat listingfox will print out the directory listing of usr bin, and then it will print out our silly sentence.Thus, the command cat listing fox listandfox will create a new le containing the contentsof both listing and fox.6.3.3 Input RedirectionLike redirecting standard output, it is also possible to redirect standard input [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • nvs.xlx.pl