[ Pobierz całość w formacie PDF ]
.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-file52 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 [ Pobierz całość w formacie PDF ]
zanotowane.pl doc.pisz.pl pdf.pisz.pl odbijak.htw.pl
.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-file52 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 [ Pobierz całość w formacie PDF ]