Download
week 9 agenda n.
Skip this Video
Loading SlideShow in 5 Seconds..
Week 9 Agenda PowerPoint Presentation
Download Presentation
Week 9 Agenda

Week 9 Agenda

186 Views Download Presentation
Download Presentation

Week 9 Agenda

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Week 9 Agenda Unix Commands du, df write, talk, mesg sort, uniq, grep wc tar I/O redirection, pipe, tee Week 9 - Mar 14, 2005

  2. UNIX Command Week 9 - Mar 14, 2005

  3. UNIX Command Week 9 - Mar 14, 2005

  4. UNIX Command Week 9 - Mar 14, 2005

  5. UNIX Command Week 9 - Mar 14, 2005

  6. UNIX Command Week 9 - Mar 14, 2005

  7. UNIX Command Week 9 - Mar 14, 2005

  8. UNIX Command sort - arranges lines in ASCII order • allows relative or absolute pathnames • processes either filename arguments or standard input • changes only the output not the file • allows a list of filenames • allows output to be piped or redirected Week 9 - Mar 14, 2005

  9. UNIX Command - sort ex. sort file1 file2 file3 • merges all the files into its “workspace” • sorts the workspace • displays the results there are many options to control what characters or fields are used to arrange the lines..... Week 9 - Mar 14, 2005

  10. UNIX Command - sort Sorting numbers by magnitude -n Week 9 - Mar 14, 2005

  11. UNIX Command - sort Sort ignoring leading blanks -b (+0b) Note: phobos works differently than zenit Week 9 - Mar 14, 2005

  12. Warning! -b is used as a simple sort option to ignore leading blanks in Linux and some older systems Newer commercial versions only use a special field option +0b Week 9 - Mar 14, 2005

  13. UNIX Command - sort Sort ignoring case -f (ie folding upper & lowercase together) Note: phobos works differently than zenit Week 9 - Mar 14, 2005

  14. UNIX Command - sort Sort ignoring punctuation -d Note: phobos works differently than zenit Week 9 - Mar 14, 2005

  15. UNIX Command - sort Combining sort options Sort ignoring punctuation & case -df Note: phobos works differently than zenit Week 9 - Mar 14, 2005

  16. Warning! In your zenit account, if you specify sort, By default, it will ignore the leading space and punctuation Week 9 - Mar 14, 2005

  17. UNIX Command - sort Sort in reverse order -r Week 9 - Mar 14, 2005

  18. UNIX Command - sort Sort Options -o put output in file sort numbers -o numbers cat numbers 10 rulers 5 pens 66 erasers Week 9 - Mar 14, 2005

  19. UNIX Command - sort Sorting based on fields within the line for sort any sequence of tabs or spaces is the start of a new field sort +n means skip n fields then sort based on the next characters on the line Week 9 - Mar 14, 2005

  20. UNIX Command - sort Sort Options Sorting based on fields within the line ex. ls -l produces 9 fields -r-xr-x- - - 1 zoro staff 30 Mar 26 19:49 colours drwxr-xr-x 4 aladdin sys 512 Apr 1 17:41 comfind field1 f2 f3 f4 f5 f6 f7 f8 f9 Week 9 - Mar 14, 2005

  21. UNIX Command - sort Sorting based on fields within the line To sort by owner ls -l | sort +2 (skip 2 fields, start on field 3) drwxr-xr-x 4 aladdin sys 512 Apr 1 17:41 comfind -r-xr-x- - - 1 zoro staff 30 Mar 26 19:49 colours field1 f2 f3 f4 f5 f6 f7 f8 f9 Week 9 - Mar 14, 2005

  22. UNIX Command Week 9 - Mar 14, 2005

  23. UNIX Command - uniq • uniq - displays lines of a file that are unique • allows relative and absolute pathname arguments • processes input from file specified on command line or from stdin • sends output to stdout unless you specify output file on command line • changes only the output not the file Week 9 - Mar 14, 2005

  24. UNIX Command - uniq Week 9 - Mar 14, 2005 Note: it only removes duplicate adjacent lines

  25. Warning! The file “must” be sorted first.... uniq only removes any lines that exactly match the preceding line! Week 9 - Mar 14, 2005

  26. UNIX Command - uniq uniq-c -- counts the number of duplicates for each line. Week 9 - Mar 14, 2005

  27. UNIX Command - uniq uniq-d -- displays one copy of only the duplicated lines. Week 9 - Mar 14, 2005

  28. UNIX Command - uniq uniq–u-- displays only the lines that are unique. Week 9 - Mar 14, 2005

  29. UNIX Command- grep • grep- searches line by line for a pattern in one or more files • allows relative and absolute pathname arguments • processes input from file(s) specified on command line or from stdin • sends output to stdout unless you specify output file on command line • changes only the output not the file Week 9 - Mar 14, 2005

  30. UNIX Command- grep grep - searches line by line for a pattern in one or more files ex. to search for lines with the R.E. boring in the file diary... Week 9 - Mar 14, 2005

  31. UNIX Command- grep grep- searches line by line for a pattern in one or more files grep pattern file(s) grep boring diary boring is the pattern to search for.... search for what? Week 9 - Mar 14, 2005

  32. UNIX Command- grep grep- searches line by line for a pattern in one or more files grep pattern file(s) grep boring diary diary is the file to search in.... search for where? Week 9 - Mar 14, 2005

  33. UNIX Command- grep grep options -c counts the number of lines with matches -i ignore case -l lists only the name of each file that contains one or more matches -n number - precedes each line with the line number in the file -v reverse - output all lines where pattern is NOT found Week 9 - Mar 14, 2005

  34. UNIX Command- grep Warning When search for a pattern, some characters have special meaning ^ - Beginning of a line $ - End of a line Week 9 - Mar 14, 2005

  35. UNIX Command- wc wc – word count, displays number of lines, words and bytes in a file or standard input wc-c – only displays the number of bytes wc-w – only displays the word counts wc-l – only displays the line counts Week 9 - Mar 14, 2005

  36. UNIX Command- tar tar – a utility to archive files Don’t need “–” before option Do you remember the options you used? tar xzvfapache_1.3.31.tar.gz Week 9 - Mar 14, 2005

  37. Redirection and Piping Most “processes” in UNIX: • send their output to the terminal screen • get their input from the keyboard • send any error messages to the terminal Week 9 - Mar 14, 2005

  38. Redirection and Piping Most “processes” in UNIX: • send their output to the terminal screen • get their input from the keyboard • send any error messages to the terminal Do you remember what a “process” is? Week 9 - Mar 14, 2005

  39. A process is the execution of a command by the UNIX system. • UNIX assigns a unique process identification (PID) number at the creation of each process. • As long as a process is in existence, it keeps the same PID number. Week 9 - Mar 14, 2005

  40. The ps command • displays the processes currently running on the controlling terminal • with the “-e” option displays all processes running on the system • with the “f” option displays a full listing of the processes Week 9 - Mar 14, 2005

  41. The ps command “ps” with no options displays just the processes running on the controlling terminal..... Week 9 - Mar 14, 2005

  42. ps -e “ps –e” displays all the processes running on the system... Week 9 - Mar 14, 2005

  43. ps -f “ps –f” displays a full listing... Week 9 - Mar 14, 2005

  44. ps -ef “ps –ef” displays a full listing... of all processes Week 9 - Mar 14, 2005

  45. Redirection Most “processes” in UNIX: • send their output to the terminal screen • get their input from the keyboard • send any error messages to the terminal Week 9 - Mar 14, 2005

  46. Redirection UNIX allows us to “redirect” where processes send their output where processes get their input and where processes send any error messages. Week 9 - Mar 14, 2005

  47. Week 9 - Mar 14, 2005

  48. I/O Channel 0 - standard input (stdin) I/O Channel 1 - standard output (stdout) I/O Channel 2 - standard error (stderr) These “channels” are called file descriptors Week 9 - Mar 14, 2005

  49. stderr stdin stdout Week 9 - Mar 14, 2005

  50. I/O Channel 0 – stdin -default is the terminal keyboard I/O Channel 1- stdout - default is the terminal screen I/O Channel 2- stderr - default is the terminal screen Let’s learn to redirect ”stdout” first These “channels” are called file descriptors Week 9 - Mar 14, 2005