1 / 27

Introduction to Unix (CA263) Unix/Linux Utilities

Introduction to Unix (CA263) Unix/Linux Utilities. By Tariq Ibn Aziz. Objectives. Check File Type Unix utilities more , less , head , tail command Check Spelling Splitting a File comm and diff command Regular Expression rules grep and egrep Printing Files

kenton
Télécharger la présentation

Introduction to Unix (CA263) Unix/Linux Utilities

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Unix (CA263)Unix/Linux Utilities By Tariq Ibn Aziz

  2. Objectives • Check File Type • Unix utilities more, less, head, tail command • Check Spelling • Splitting a File • comm and diff command • Regular Expression rules • grep and egrep Printing Files • PostScript and PDF Files • Encrypting and Decrypting a File • mpage versus enscript

  3. Check File Type Unix> file .login .login: assembler program text (Page 28)

  4. more or less • Less is an improved version of more command. • You can say that more is less than less, and less is more than more. (Page 62)

  5. head or tail • head: view lines at the beginning of a file, by default, it display 10 line from top • tail: view lines at the end of a file, by default, it display 10 line from bottom (Page 63)

  6. Check Spelling Unix> spell info.txt Username dis • For interactive spell checking use ispell. For more information see man ispell (page 64)

  7. Split a File Unix> vi data.txt Username Tariq Naif Musa Manea Hassan Monim To split data file into files with 2 line each. Unix> split -2 data.txt stuff unix> ls stuff* Stuffaa stuffab stuffac stuffad Page 66

  8. comm is very handy command. comm file1 file2 will report three column report. Unique lines in f.txt, unique lines in g.txt, and duplicate lines unix> comm f.txt g.txt jay pat kit sam joe comm Page 67

  9. difffile1 file2 < sign indicates file1 > sign indicates file2 1d0 is number-letter-number 1 indicates a line in first file [a, c, or d] indicates an ed command, a append, c change, d mean delete. 0 third char indicates a line in second file. < pointing first file > pointing second file unix> diff f.txt g.txt 1d0 < jay 2a2 > kit diff Page 67

  10. Regular Expression rules • “.” Matches any single character For example: .at matches aat, bat, cat, … • [] matches one character between brackets • "-" indicates range. E.g. a-z • * matches zero or more instance, For example ba* macthes b, ba, baa, … • \ treat the next character literally, for example \* matches "*“ • ^ matches the start of the line, So ^cat matches every line that start with cat • $ matches the end of line. So cat$ matches every line that end with cat e.g. aristocat Page 69, 70

  11. unix>cat f.txt jay pat sam joe unix>cat g.txt pat kit sam joe unix> grep pat f.txt g.txt f.txt:pat g.txt:pat unix> grep –n pat f.txt g.txt f.txt:2:pat g.txt:1:pat grep(global regular expression print) Page 70

  12. unix>cat f.txt jay pat sam joe unix>cat g.txt pat kit sam joe Search all rows start with "p" unix> grep –n '^p' f.txt 2:pat Search all rows start with "k or j" unix> grep –n '^[kj]' g.txt g.txt:2:kit g.txt:4:joe Search all rows with one or more "a" unix> grep –n 'a*' g.txt g.txt:1:pat g.txt:3:sam grep (global regular expression print) Page 70

  13. egrep(extended global regular expression print) • Some of the extended set is as follow: • + matches one or more of its preceding characters, e.g. abc2+ will match abc2, abc22, abc222, … • ? matches zero or one character that precedes it, e.g. abc? Matches with ab andabc • | signifies an alternative or disjunction. e.g. a|b means a or b unix> egrep ‘uu+|ww+’ /usr/dict/words Continuum Hollowware vacuum Page 72

  14. egrep(extended global regular expression print) Search for line that have z or v in info.txt unix> egrep '(z|v)' info.txt Name: David I. Schwartz Favorite Color: blue Page 72

  15. Printing Files • The common print command is lp, which stands for line printer, lp work with spooling a file. unix> lp info.txt request if is jaded-2 (1 file) • Request id has the form printer-job number . • jaded is a printer. • My job is the 2nd print job. unix> echo $PRINTER jaded Page 72

  16. Find other printers unix> printers # Printer Type Location Owner/User #======================================= # astro HP2420 ROOM 271 …

  17. Print to Destination unix> lp –d astro a.txt • Some version of unix use the BSD print command unix> lpr –P astro b.txt Page 73

  18. Printing Status • lpq and lpstat have different output format unix> lpstat Jaded-2 dis 163 Nov 22 18:33 unix> lpq Jaded@blather 0 jobs Page 73

  19. Cancel a Print Job • lpq and lpstat have different output format unix> lpstat Jaded-2 dis 163 Nov 22 18:33 unix> cancel jaded-2 request "jaded-2" cancelled Page 74

  20. PostScript • PostScript (PS) is a text-based language that can describe graphical images and text. • You should be able to print a PS document anywhere. • PS document can be generated from a text file with genscript. unix> genscript info.txt > info.ps unix> Page 74

  21. View PostScript Document • Use ghostview or gs to view PS version of info.ps unix> gs info.ps GS> quit unix> Page 75

  22. Print PostScript Document unix> lp –d jaded info.ps unix> • You can do some conversions at the Unix command line. • pdf2ps: convert PDF file to PS format • ps2pdf: convert PS file to PDF format • ps2ascii: convert PS file to ACSII format • PDF (portable Document Format) need acroread or xpdf utilities to display the PDF file Page 75

  23. Viewing and Printing PDF Files unix> acroread info.pdf unix> • You can do some conversions at the Unix command line. • pdf2ps: convert PDF file to PS format • ps2pdf: convert PS file to PDF format • ps2ascii: convert PS file to ACSII format • PDF (portable Document Format) need acroread or xpdf utilities to display the PDF file Page 75

  24. Encrypting a File unix> cat info.txt Trans fat is evil. unix> crypt < info.txt > info.enc Enter Key: ***** (Enter 12345) • Try more info.enc, unix wil prompt you to view a binary file.

  25. Decrypting a File unix> crypt < info.enc > info.dec Enter Key: ***** (Enter 12345) • Try more info.dec, unix wil prompt you to view a binary file. unix> more info.dec Trans fat is evil.

  26. mpage versus enscript • mpage to print multiple page on one sheet, you can print 1, 2, 4 or 8 pages on one side of a sheet of paper. • If mpage is not available then use enscript

  27. Print a File using enscript unix> enscript –r –B –columns=4 –f Helvetica10 –p movies.ps movies.txt • This command will create movies.ps from movies.txt • The enscript command do the following: • print PS file (-p info.txt) • in landscape (-r) • with no header (-B) • four column (--columns=4) • in a plain font (-f Helvetica10)

More Related