аЯрЁБс>ўџ 9;ўџџџ8џџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџьЅСY ПŸbjbjѓWѓW "8‘=‘=Ÿџџџџџџ],$(2\\\\\\\\эяяяяяя$ZєNЈ\\\\\\\\\2\\э\э$Сс \P `Ц<тИАТŽŽйFundamentals of Unix Tutorial PIPE Commands and REDIRECTION Commands – CH 7 The content of this tutorial also applies to linux. Piping UNIX supports and makes extensive use of the ability to connect commands to one another. By piping commands together, you can use the output of one command as the input for another. The pipe symbol is | (a vertical bar). To pipe commands together you simply place a pipe between each command on the command line. For example command1 | command2 | command3 Although you can pipe many commands together, you'll rarely need to do so. Examples of using pipes to connect commands Here are some examples you can learn from and adapt for your own uses. If you don't completely understand the commands are that are being piped, look them up in other parts of this tutorial or in the glossary of the Cisco-Sun online curriculum. Example: ls -alFs | more This command sends the output of the ls command with the options alFs to the more command. The options used with ls indicate that all files, including hidden ones will be listed, in long form, marking directories with a slash (/), executables (programs) with an asterisk (*), and the size of each file will be listed as well. Normally such a list would scroll by too quickly to view, but by piping the output through the more command you can view one page at a time. Example: who | wc -l This command takes the output from the who command which lists everyone currently logged in to the system and passes the information to the wc command which, using the -l option, counts the number of lines that the who command generated. Since who generates a line for each person logged in, the number of lines is equal to the number of people logged in to the system. Example: who | grep Chris Similar to the first example, this command pipes the output of the who command to the grep command which searches for instances of the letters "Chris". If grep finds a line containing the letters, grep prints the line(s) to the screen. This command would tell you how many people with the user name Chris are logged in. Example: Connecting several commands together: ps –ef | grep joe | sort +5 –6 | less The first command, ps –ef, outputs information about the processes currently running. This information becomes the input to the command grep joe which searches for any lines that contain the username "joe". The output from this command is then sorted on the sixth field of each line, with the output being displayed one screenful at a time using the less pager (similar to more). Redirection Normally everything you do on the keyboard is sent to the computer screen for your viewing pleasure. That is, when you type a command, the letters you type are sent to the screen so you can see what you're typing. The results of the command are also sent to the screen so you can see what happened. Your typing on the keyboard is the "input" and what you see on the screen is the "output." To UNIX, a computer screen and a file are forms of output. The screen is the standard output, normally abbreviated as "stdout." With redirection you can send output to files instead of the screen, or you can use what's in a file as the input for a command. With redirection you can change where the computer gets input, and where it puts output. You use the symbols < , > , >> , and 2> to redirect input and output. Examples of using redirection Redirecting standard output: To redirect the standard output from a command use the > (greater than) symbol followed by the name of the output file. If the file that you redirect standard output to does not already exist it will be created. Example: ls -la > mydir This command lists all the files and directories in long form, and sends them to the file mydir. If the file mydir does not exist, it will be created. If it does exist it will be overwritten with the new data. When you execute this command, you will not see anything appear on the screen (unless there is an error – that is described below). Example: grep Smith /etc/passwd > popular This redirects the standard output from the grep command so that it goes to the file popular. This file will contain all the lines containing occurrences of the string “Smith” that were found in the /etc/passwd file. Example: cat section1 section2 section3 > Chapter1 This example connects (concatenates) several files in order, and outputs them as one file, Chapter1. The cat command reads files section1 through section3 in turn and appends them to (tacks them onto the end of) the file Chapter1. The contents of section2 are appended to section1 and so on. Example: who > people This prints the list of active users to the file people. Example: sort file1 > sorted_list This sorts the contents of file1 and saves the sorted list as sorted_list. Appending standard output: To append the standard output from a command to a file, use two >> (greater than) symbols followed by the name of the file. If the file does not exist it is created. For example: Example: ls >> mydir This appends the data from a short form directory listing to the data (if any) already in the file mydir. Example: If you wanted to add one more section to the file Chapter1, created earlier, you'd append the text using the command cat section4 >> Chapter1 to make sure the text that already exists in the file isn't disturbed. Redirecting standard input: Redirecting input is just as easy. For example, say you want to mail someone the directory list you just made, called mydir. Instead of having to import it into a mail program, you can redirect the input for the mail command: Example: mail Tony < mydir This command uses the contents of the mydir file as the input for the mail command. The effect of this is to mail the contents of this file to the user Tony. Redirecting error output: Even though you send the standard output to a file, if an error occurs the error message will be sent to your screen. This is because the standard error output, or “stderr”, is the screen. If you wish to redirect error messages to a file for troubleshooting purposes, use the 2> symbol. For example: cat file1 file2 file3 2> Error_Log Any errors that occur during the execution of this command will be included in Error_Log. Since we are troubleshooting, the output, if any, of the command will probably be incorrect. If there is any output, it will be directed to the screen, since we did not direct it to a file. We directed only the error messages to a file so we could have a record of them. Example of combining piping and redirection You can combine piping with redirection to create files that contain the output. Example: who | grep Chris > List_of_Chris In the example above, the list of lines from the who command containing the letters "Chris" is redirected from the screen (the standard output device) to the file List_of_Chris. You could view the resulting text file with a viewer such as the more command, or an editor such TED or Nedit, or the text editor in the Solaris CDE. LM‚‰аю =iixŸЁЛПЧЫыэ # Y d   ђ є   = @ Z ] у ѓ 8 ; K O  ” К О i Ž Ђ Ј Љ   э ё Ca~ЕЖ\jЦЫйоТФЭэ"GN› ЙФХЫе§ћїѓёюъ§юючюююююючююююююююпмп裏ёмюёёюиююпбпёи 0JOJQJ0J50J0J5OJQJ0J0J60J55CJ6CJ6CJ RLM‚‰@а№;<=i_`zN O P f й к ѕ 5 ќќђђ№ьъфкдддвффффффффффф„а„а „ „ ЄdЄd„а„а„ „а„аЄdЄd$LM‚‰@а№;<=i_`zN O P f й к ѕ 5 6 e    EћBCaRSlТУФюђЫЬ$%=vw™фхцДЪ456Еа4вгджABЋЌ­Ўкл,WŸќќљљїѕќѕѕѕѕѕѕѕѕѕѕѕѕѕѓѕѕќѕѕѕќѕѕѕѓѕѕѕѕѕѕѕѕѕѕѕќѕѕT5 6 e    EћBCaRSlТУФюђЫЬ§љїѓёыщпйййщйййггггїгЩЩ „ „аЄdЄd„а„а„а„а „а„аЄdЄdЄЄ„а„аеў[cil‰’šнхїџ/;nu€˜ДЙзтцACДНШ-2qyЕЭ5ЋА  !2Z_z~ЬЭажя34?‘›ЊЎк5Vˆ‹њJNjmqvŸ§§ћ§§§§§§ћ§ћћћјє§ћћ§ћћ§є§ћ§ћь§§є§§єщ§§ћ§ћћCJ 0J5OJQJ0J50J50JN$%=vw™фхцДЪ456Еа4вгджћћћћћћћѕѕћыѕѕѕхыыѕѕхыѕѕѕѕх„а„а „ „аЄdЄd„а„а„аABЋЌ­Ўкл,WŸѕяяяяяэяячч„а„а„а„а „ „ ЄdЄd 1hАа/ Ар=!А"А# $ %А [8@ёџ8 NormalCJ_HaJmH sH tH J@J Heading 1ЄdЄd@&[$\$5CJ0KH$\aJ0T@T Heading 2&$„а„аЄdЄd@&[$\$]„а^„а 5CJ \@`@ Heading 3$„а„аЄdЄd@&CJ <A@ђџЁ< Default Paragraph Font:ўOђ: Normal (Web)ЄdЄd[$\$6ўOЂ6 HTML SampleOJPJQJ^J„ўO„ HTML Preformatted7 Ц2”(М Pфx  4 Ш#\'№*„.2Ќ5@9CJOJPJQJ^JaJ"W@Ђ!" Strong5\&X@Ђ1& Emphasis6]8T`B8 Block Text„а„аЄdЄdŸ8џџџџеŸ5 ŸŸzikmqŸЁЛПыэ_aђєщэKO”КОikmorvwzЂЄІЈ    X [ Я и   \^ejЦЫйоЭбну"ОФ™зтНПУШ-2ЋА-2Z_•›6?‘š;?HUњqvЁаи_a4;ikф    ЈЌЕИав Ёџџ Marc MatthesYC:\Documents and Settings\matthes\My Documents\PIPE Commands and REDIRECTION Commands.docFFCCxC:\WINDOWS\Application Data\Microsoft\Word\AutoRecovery save of PIPE Commands and REDIRECTION Commands- Marc Mathhes.asdFFCCŒC:\Jim stuff\UNIX training\My students lesson plan exercises- from trainings I gave\PIPE Commands and REDIRECTION Commands- Marc Mathhes.doc Jim BergquistSC:\windows\TEMP\AutoRecovery save of jbergqui_PIPE_and_REDIRECTION_Marc_Matthes.asd Jim Bergquist{C:\Jim stuff 9-00 to 11-02\Archiving Unix Instructor Resources- CH 1-8\CH 7\jbergqui_PIPE_and_REDIRECTION_Marc_Matthes.doc Jim Bergquist{C:\Jim stuff 9-00 to 11-02\Archiving Unix Instructor Resources- CH 1-8\CH 7\jbergqui_PIPE_and_REDIRECTION_Marc_Matthes.doc Jim Bergquist{C:\Jim stuff 9-00 to 11-02\Archiving Unix Instructor Resources- CH 1-8\CH 7\jbergqui_PIPE_and_REDIRECTION_Marc_Matthes.doc Jim Bergquist{C:\Jim stuff 9-00 to 11-02\Archiving Unix Instructor Resources- CH 1-8\CH 7\jbergqui_PIPE_and_REDIRECTION_Marc_Matthes.docЎ*’і1Ђ8џџџџџџџџџ„а„˜ўЦа^„а`„˜ўCJOJQJo(З№€„ „˜ўЦ ^„ `„˜ўCJOJQJo(o€„p„˜ўЦp^„p`„˜ўCJOJQJo(Ї№€„@ „˜ўЦ@ ^„@ `„˜ўCJOJQJo(Ї№€„„˜ўЦ^„`„˜ўCJOJQJo(Ї№€„р„˜ўЦр^„р`„˜ўCJOJQJo(Ї№€„А„˜ўЦА^„А`„˜ўCJOJQJo(Ї№€„€„˜ўЦ€^„€`„˜ўCJOJQJo(Ї№€„P„˜ўЦP^„P`„˜ўCJOJQJo(Ї№Ў*’џџџџџџ џ@€,,иЗЗ,,Ÿ @G‡:џTimes New Roman5€Symbol3& ‡:џArial?5 ‡:џCourier New;€Wingdings"qˆ№аhлuXF'љlFЇўЦ 0!№ ДД20dїџџ&PIPE Commands and REDIRECTION Commands Marc Matthes Jim Bergquistўџр…ŸђљOhЋ‘+'Гй0œ˜Шдьј 0< X d p|„Œ”ф'PIPE Commands and REDIRECTION Commands IPE Marc Matthes anarcarc Normal.dotsJim Bergquistan6m Microsoft Word 8.0E@ЊbT@ЊgшJ%С@:-дИАТўЦўџеЭеœ.“—+,љЎDеЭеœ.“—+,љЎX hp€ˆ˜  ЈАИ Р ѓфICCCm0 їj 'PIPE Commands and REDIRECTION Commands Title˜ 6> _PID_GUIDфAN{DD88CE76-8938-4E8C-A351-A180A7D0E011} ўџџџ !"#$%&'ўџџџ)*+,-./ўџџџ1234567ўџџџ§џџџ:ўџџџўџџџўџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџRoot Entryџџџџџџџџ РFр[p,ЂТ€б\тИАТ<€1TableџџџџџџџџџџџџіWordDocumentџџџџџџџџ"8SummaryInformation(џџџџ(DocumentSummaryInformation8џџџџџџџџџџџџ0CompObjџџџџjObjectPoolџџџџџџџџџџџџ€б\тИАТ€б\тИАТџџџџџџџџџџџџўџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџџўџ џџџџ РFMicrosoft Word Document MSWordDocWord.Document.8є9Вq