CSCI 3294 January 30, 2006Slide 1Administrivia• Reminder: Homework 1 due today at 5pm.• Homework 2 on Web soon; due next Monday.Slide 2Shell Features — Recap• Things that happen while entering command — editing, tab completion, useof command history.• Parsing of completed command line — filename wildcard expansion,environment variables, separation into arguments, single and double quoting.• Aliases and functions.• How to save customizations for next login.CSCI 3294 January 30, 2006Slide 3I/O Redirection• stdin can come from keyboard, file, or “inline”. (Review syntax.)• stdout, stderr can go to terminal or file (overwrite or append),separately or together. (Review syntax.)• Or . . .Slide 4Pipes• “Pipes” provide one-way communication between programs — output ofprogram A becomes input of program B.• Key component of “the Unix philosophy” — emphasis on providing a toolkit ofsmall programs, mechanisms for combining them.• “Filters” are programs designed to work this way, and there are lots of them(some in next slides). less and more also useful.CSCI 3294 January 30, 2006Slide 5Filters• head, tail.• sort, uniq.• grep — search for text (or regular expression — more later).• wc — count characters, words, lines.• tr — “translate”. Good for converting, e.g., upper-case to lower-case.• tee — duplicates input. Good for capturing output to a file while alsodisplaying it onscreen.Slide 6Filters, Continued• sed — “stream editor”. Example — convert DOS/Windows-style text file(each line ends with \r\n) to UNIX-style (each line ends with \n).• awk — “pattern scanning and processing language” — many interestingpossibilities; simplest is just to break up input into whitespace-delimited fields.CSCI 3294 January 30, 2006Slide 7Examples• Find all users on local machines and print their names only:rwho | awk ’{print $1}’• Find all users on local machines and print their names only, suppressingduplicates:rwho | awk ’{print $1}’ | uniq• Generate a list of machines that are “up”:ruptime | grep up | awk ’{print $1}’Slide 8Minute Essay• What command could you use to count the number of aliases in your.bashrc file?• Was Homework 1 too hard, too easy, or about right?CSCI 3294 January 30, 2006Slide 9Minute Essay Answer• One possible answer (to the first question):grep alias .bashrc | wc
View Full Document