1 / 59

Chapter 3

Chapter 3 . An Introduction to the Utilities. Topics. File Operations File Compression and Archive Obtaining User & System Information Communicating with Other Users Daily Miscellany. Topics. File Operations c o p y - m o v e head - tail file - uniq - diff sort - grep

nika
Download Presentation

Chapter 3

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. Chapter 3 An Introduction to the Utilities

  2. Topics • File Operations • File Compression and Archive • Obtaining User & System Information • Communicating with Other Users • Daily Miscellany

  3. Topics • File Operations • copy- move • head - tail • file - uniq - diff • sort - grep • lpr - more - less

  4. File Operations • cp - Copy a file or directory • cp [options ] srce-file dest-file srce-filelist dest-directory-i Interactive - prompts for overwrites -r Recursive - copies all subdirectories

  5. File Operations • mv - Move or re-name a file or directory(creates new link if on the same file system) • mv [options --] filenames -f Force - moves the file regardless of access permissions. -i Interactive - prompts for overwrites

  6. File Operations • head - Display the first Xrecords in file(s) head [-number] [file-list] if a number is not specified the first 10 records of each file are displayed

  7. File Operations • tail - Display the last X records in file tail [± [number]] [options] [file] + count from the beginning - count from the end[options] b blocks, c characters, l lines f follow-monitors the file until killed

  8. File Operations • file - Display file content classification.file [option] [file-list][option] -ffile Input taken from file.

  9. File Operations • uniq - Display unique records from files uniq[options] [input file] [output file]c– count occurrencesd– display repeated records sn– skip first n characters fn– skip first n space delimitedfields u– display only non-repeated lines

  10. File Operations • diff - Display file differences line by line diff[options] [file1|directory1] [file2|directory2]b– ignore blanksc– display in context (<-3 lines ->) i– ignore case q– report if files are different r– recurse sub-directories

  11. diff Example • Output from diff is a series of instructions to make the files the same • a – append • c – change • d – delete • Surrounding the instruction are the line ranges to convert file1 to file2

  12. diff Example • Append • line1aline2,line3 • Change • line1,line2cline3,line4 • Delete • line1,line2dline3

  13. diff Example • line1,line2– Range from file 1 • line3,line4– Range from file 2 cat x cat y aaaaa bbbbb bbbbb bbbbb ccccc ddddd ddddd eeeee eeeee fffff fffff ggggg diff xy 1d0< aaaaa3c2 < ccccc--- > bbbbb6a6 > ggggg diff yx 0a1 > aaaaa2c3 < bbbbb--- > ccccc6d6 < ggggg

  14. File Operations • sort– sorts or merges text files • sort [options] [field-specifier-list] [file-list] • f upper and lower case considered the same • u duplicate entries are eliminated from output • r reverse order (ie, z to a) • b ignores leading blanks • kndefines the field to start sort comparison. Count starts with 1 (replace n with a number)

  15. What is a ‘field’ • Contains ascii data • delimited by ‘whitespace’ • whitespace is: • tab • blank • carriage return • Example • the day the earth stood still

  16. Example

  17. Sorting • Examples • sort myfile • sort -r myfile • sort file1 file2 • sort file1 file2 > file3 • sort –k2 myfile • (skip a field, then start comparisons)

  18. Sorting • sort -k1,2 myfile • skip a field (start sort in field number 2) • end sort at end of field 2 • sort -b –k3.1,3 • -b ignore blanks • +2 skips first two fields • .1 skip 1 character in field 3 • 3 ends sort key at end of field 3

  19. File Operations • Searching for patterns with grepglobal regular expression print • grep [options] pattern [file-list] • sends all lines with that pattern to std out • options • -v display lines which do NOT have pattern • -i ignore case • -c count lines • -n print line numbers • -l print file names only

  20. TRUE grit ! grep ! • Example cat animal Bat Bird Cat Dog Lizard Turtle grep ‘r’ animal Bird Lizard Turtle grep –v ‘r’ animal Bat Cat Dog

  21. lpr (Lilliputian Practical guide to Romance) • line printer – places a filelist into the print queue for printing • Syntax lpr [-options] filelist -Pprintername -h suppress burst or header page -m send e-mail when job is complete

  22. lprm (Lilliputian PRevious Manual) • line print remove – removes jobs from the print queue • Syntax lprm [-option] job-identifier number(s) –remove all jobs from the print queue

  23. lpq (Lilliputian mind your P’s and Q’s) • line print queue – displayjobs in the print queue • Syntax lpq job-identifier number(s)

  24. moreorless • more • Displays a screen full of data at a time. • Starts at the beginning and proceeds to the end • Enter Key – scroll one line • Space bar – scroll one screen

  25. more or less • less– more functionality than more • Displays a screen full of data at a time. • Enter Key – scroll one line • Space bar – scroll one screen • Starts at the beginning and provides commands to control scrolling

  26. more ofless • less– more functionality than more • Provides interactive help panels • Will search forward or backward for matching patterns • Will jump to beginning or end • Provides bookmarks • Can invoke vim with current file • Over 40 invocation options

  27. Topics • File Operations • File Compression and Archive • Obtaining User & System Information • Communicating with Other Users • Daily Miscellany

  28. Compression and Archive • gzip– Squish the snot out of it • gunzip– Put the snot back in • zcat– view compressed files • tar– archive or retrieve files

  29. Compression • gzip – compress gzip [options] file-list • Compresses file contents appends .gz • options • -# set level of compression 1- fast, 9 - best • -d de-compress • -r recurse directories • -c send output to stdout, don’t overwrite file • -v show filename and compression amount

  30. tar - the stuff archives are made of • taroption [modifier] [dev or file] [file-list] • Create, add to or retrieve from an archive • option (only one at a time) • -xextract file-list from archive • -fuse a file not a device • -ccreate new archive (overwrites existing) • -rappends file to end of archive (dups OK?) • -uupdate the archive with file-list • -tlist table of contents in archive

  31. Topics • File Operations • File Compression and Archive • Obtaining User & System Information • Communicating with Other Users • Daily Miscellany

  32. Topics • Obtaining User & System Information • apropos • whereis - which • w – who - finger

  33. 50¢ word of the day • apropos keywords • Search the “whatis” database for keywords and displays suggested commands [student@linux1 student]$ apropos alarm alarm (2) - set an alarm clock for delivery of a signal [student@linux1 student]$ apropos deathdeath: nothing appropriate

  34. whereis the exit & which one? • whereis&which • whereis – locates utilities by looking in the standard locations • which – locates utilities by looking in the path [student@linux1 student]$ whereis exit exit: /usr/share/man/man1/exit.1.gz /us … [student@linux1 student]$ which exit /usr/bin/which: no exit in (/usr/local/bin: …)

  35. What the owl says? • who Identifies the users currently logged in and when they logged in [astudent@linux1 astudent]$ who jurrutia pts/0 Aug 18 07:55 astudent pts/1 Aug 18 09:38 calouise pts/2 Aug 18 10:10

  36. w • WLike who but more [astudent@linux1 astudent]$ w 10:17am up 8 days, 17:12, 3 users, load average: 0.00, 0.01, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT jurrutia pts/0 ts-25.solano.cc. 7:55am 2:03m 0.15s 0.09s -bash astudent pts/1 ts-34.solano.cc. 9:38am 29:35 0.14s 0.09s -bash calouise pts/2 ts-37.solano.cc. 10:10am 0.00s 0.14s 0.03s w

  37. finger this out! • Provides .project and .plan info for users online • Login name – Full name – Home directory location – Login Shell • Last Login date & time • Last time mail was read • Plan: if present • Project: if present

  38. The shortfinger • Short version of finger [astudent@linux1 astudent]$ finger Login Name Tty Idle Login Time Office Office Phone jurrutia pts/0 2:04 Aug 18 07:55 (ts-25.solano.cc.ca.us) astudent pts/1 30 Aug 18 09:38 (ts-34.solano.cc.ca.us) calouise pts/2 Aug 18 10:10 (ts-37.solano.cc.ca.us)

  39. The long finger • Long version of finger [astudent@linux1 astudent]$ finger -l astudent@Linux1 Login: astudent Name: Alouitious Purcevil Student Directory: /home/astudent Shell: bash On since Sat May 19 07:00 (PDT) on tty1, idle 2400:04:59 Last login Sat May 19 07:00 (PDT) on tty1 Mail last read Sat May 19 07:10 1999 (PDT) Plan: Finish homework and final for CIS52.

  40. Topics • File Operations • File Compression and Archive • Obtaining User & System Information • Communicating with Other Users • Daily Miscellany

  41. Topics • Communicating with Other Users • mesg • write • talk • pine

  42. mesg y Please • mesg is used to turn on or off your ability to receive messages from other users. mesg[y|n] • When mesg is set to n all messages are denied.

  43. The write stuff • Using write to send a message (or Henny Youngman – eat your heart out) • Syntax: [root@linux1 root]$ write gburnsWho was that blonde I saw you with? o

  44. The write Woman! [gburns@linux1 gburns]$Message from root@linux1 on pts/0 at 8:30…Who was that blonde I saw you with? o Message from gburns@linux1 on ttpy3 at 8:30…That’s no blonde – that’s my wife. ooEOF

  45. talk’n talk’n talk’n, Happy talk • talk initiates and carries on a two-way conversation. • It splits the users screen into two sections. • During the talk session you cannot use your terminal for other tasks.

  46. talk session [root@linux1root]$talk bdaddy

  47. [root] talk session [waiting for your party to respond] ========================================

  48. [bdaddy] talk session [bdaddy@linux1 bdaddy]$ Message from Talk_Daemon@linux1 at 8:43 … talk: connection requested by root@linux1 talk: respond with: talk root@linux1 talk root@linux1

  49. [bdaddy] talk session [connection established] ========================================

  50. [root] talk session [connection established] ======================================== Big Daddy - Did you add that blower to your windows rod? Put up the pink and let my linux relieve you from that piece of junk.

More Related