+ All Categories
Home > Documents > 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

Date post: 04-Jan-2016
Category:
Upload: brent-payne
View: 213 times
Download: 0 times
Share this document with a friend
59
1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction An Introduction to the to the Utilities Utilities
Transcript
Page 1: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

1© 2001 John Urrutia. All rights reserved.

Chapter 3

An IntroductionAn Introduction to the to the UtilitiesUtilities

Page 2: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

2© 2001 John Urrutia. All rights reserved.

TopicsFile Operations

File Compression and Archive

Obtaining User & System Information

Communicating with Other Users

Daily Miscellany

Page 3: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

3© 2001 John Urrutia. All rights reserved.

File Operations

copy - move

head - tail

file - uniq - diff

sort - grep

lpr - more - less

Topics

Page 4: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

4© 2001 John Urrutia. All rights reserved.

File Operationscp - Copy a file or directory

cp [options ] srce-file dest-filesrce-filelist dest-directory

-i Interactive - prompts for overwrites -r Recursive - copies all subdirectories

Page 5: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

5© 2001 John Urrutia. All rights reserved.

File Operationsmv - 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

Page 6: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

6© 2001 John Urrutia. All rights reserved.

File Operationshead - Display the first X records in

file(s)

head [-number] [file-list]if a number is not specified

the first 10 records of each file are displayed

Page 7: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

7© 2001 John Urrutia. All rights reserved.

File Operationstail - 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

Page 8: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

8© 2001 John Urrutia. All rights reserved.

File Operationsfile - Display file content classification.

file [option] [file-list]

[option] -f file Input taken from file.

Page 9: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

9© 2001 John Urrutia. All rights reserved.

File Operationsuniq - Display unique records from files

uniq [options] [input file] [output file] c – count occurrences d – display repeated records sn – skip first n characters fn – skip first n space delimited fields u – display only non-repeated lines

Page 10: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

10© 2001 John Urrutia. All rights reserved.

File Operationsdiff - Display file differences line by line

diff [options] [file1|directory1] [file2|directory2]

b – ignore blanks c – display in context (<-3 lines ->) i – ignore case q – report if files are different r – recurse sub-directories

Page 11: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

11© 2001 John Urrutia. All rights reserved.

diff ExampleOutput from diff is a series of

instructions to make the files the samea – append

c – change

d – delete

Surrounding the instruction are the line ranges to convert file1 to file2

Page 12: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

12© 2001 John Urrutia. All rights reserved.

diff ExampleAppend

line1aline2,line3

Changeline1,line2cline3,line4

Deleteline1,line2dline3

Page 13: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

13© 2001 John Urrutia. All rights reserved.

diff Exampleline1,line2 – Range from file 1

line3,line4 – Range from file 2cat x cat y

aaaaa bbbbb

bbbbb bbbbb

ccccc ddddd

ddddd eeeee

eeeee fffff

fffff ggggg

diff x y

1d0< aaaaa3c2 < ccccc--- > bbbbb6a6 > ggggg

diff y x

0a1 > aaaaa2c3 < bbbbb--- > ccccc6d6 < ggggg

Page 14: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

14© 2001 John Urrutia. All rights reserved.

File Operationssort – 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

kn defines the field to start sort comparison. Count starts with 1(replace n with a number)

Page 15: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

15© 2001 John Urrutia. All rights reserved.

What is a ‘field’Contains ascii data

delimited by ‘whitespace’

whitespace is:tab

blank

carriage return

Examplethe day the earth stood still

Page 16: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

16© 2001 John Urrutia. All rights reserved.

Example

A K R O N O H I O

A K R O N O H I O

F A I R F I E L D C A L I F

Page 17: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

17© 2001 John Urrutia. All rights reserved.

SortingExamples

sort myfile

sort -r myfile

sort file1 file2

sort file1 file2 > file3

sort –k2 myfile(skip a field, then start comparisons)

Page 18: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

18© 2001 John Urrutia. All rights reserved.

Sortingsort -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

Page 19: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

19© 2001 John Urrutia. All rights reserved.

File OperationsSearching 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

Page 20: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

20© 2001 John Urrutia. All rights reserved.

Examplecat animal

Bat

Bird

Cat

Dog

Lizard

Turtle

grep ‘r’ animal

Bird

Lizard

Turtle

grep –v ‘r’ animal

Bat

Cat

Dog

TRUE grit !grep !

Page 21: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

21© 2001 John Urrutia. All rights reserved.

lpr (Lilliputian Practical guide to Romance)

line printer – places a filelist into the print queue for printing

Syntaxlpr [-options] filelist

-Pprintername

-h suppress burst or header page

-m send e-mail when job is complete

Page 22: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

22© 2001 John Urrutia. All rights reserved.

lprm (Lilliputian PRevious Manual)

line print remove – removes jobs from the print queue

Syntaxlprm [-option] job-identifier number(s)

– remove all jobs from the print queue

Page 23: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

23© 2001 John Urrutia. All rights reserved.

lpq (Lilliputian mind your P’s and Q’s)

line print queue – display jobs in the print queue

Syntaxlpq job-identifier number(s)

Page 24: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

24© 2001 John Urrutia. All rights reserved.

more or lessmore

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

Page 25: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

25© 2001 John Urrutia. All rights reserved.

more or lessless – 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

Page 26: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

26© 2001 John Urrutia. All rights reserved.

more of lessless – 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

Page 27: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

27© 2001 John Urrutia. All rights reserved.

TopicsFile Operations

File Compression and Archive

Obtaining User & System Information

Communicating with Other Users

Daily Miscellany

Page 28: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

28© 2001 John Urrutia. All rights reserved.

gzip – Squish the snot out of it

gunzip – Put the snot back in

zcat – view compressed files

tar – archive or retrieve files

Compression and Archive

Page 29: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

29© 2001 John Urrutia. All rights reserved.

gzip – compress gzip [options] file-listCompresses file contents appends .gzoptions

-# 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

Page 30: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

30© 2001 John Urrutia. All rights reserved.

tar option [modifier] [dev or file] [file-list]Create, add to or retrieve from an archive

option (only one at a time)-x extract file-list from archive-f use a file not a device-c create new archive (overwrites existing)-r appends file to end of archive (dups OK?)-u update the archive with file-list-t list table of contents in archive

tar - the stuff archives are made of

Page 31: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

31© 2001 John Urrutia. All rights reserved.

TopicsFile Operations

File Compression and Archive

Obtaining User & System Information

Communicating with Other Users

Daily Miscellany

Page 32: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

32© 2001 John Urrutia. All rights reserved.

Obtaining User & System Information

apropos

whereis - which

w – who - finger

Topics

Page 33: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

33© 2001 John Urrutia. All rights reserved.

apropos keywordsSearch 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

50¢ word of the day

Page 34: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

34© 2001 John Urrutia. All rights reserved.

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: …)

Page 35: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

35© 2001 John Urrutia. All rights reserved.

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

Page 36: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

36© 2001 John Urrutia. All rights reserved.

wW Like 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

Page 37: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

37© 2001 John Urrutia. All rights reserved.

finger this out!Provides .project and .plan info for

users onlineLogin name – Full name – Home

directory location – Login Shell

Last Login date & time

Last time mail was read

Plan: if present

Project: if present

Page 38: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

38© 2001 John Urrutia. All rights reserved.

The short fingerShort 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)

Page 39: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

39© 2001 John Urrutia. All rights reserved.

The long fingerLong 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.

Page 40: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

40© 2001 John Urrutia. All rights reserved.

TopicsFile Operations

File Compression and Archive

Obtaining User & System Information

Communicating with Other Users

Daily Miscellany

Page 41: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

41© 2001 John Urrutia. All rights reserved.

Communicating with Other Users

mesg

write

talk

pine

Topics

Page 42: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

42© 2001 John Urrutia. All rights reserved.

mesg y Pleasemesg 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.

Page 43: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

43© 2001 John Urrutia. All rights reserved.

The write stuffUsing 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

Page 44: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

44© 2001 John Urrutia. All rights reserved.

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

Page 45: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

45© 2001 John Urrutia. All rights reserved.

talk’n talk’n talk’n, Happy talktalk 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.

Page 46: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

46© 2001 John Urrutia. All rights reserved.

[root@linux1root]$talk bdaddy

talk session

Page 47: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

47© 2001 John Urrutia. All rights reserved.

[waiting for your party to respond]

========================================

[root] talk session

Page 48: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

48© 2001 John Urrutia. All rights reserved.

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

[bdaddy] talk session

Page 49: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

49© 2001 John Urrutia. All rights reserved.

[connection established]

========================================

[bdaddy] talk session

Page 50: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

50© 2001 John Urrutia. All rights reserved.

[connection established]

========================================

[root] talk session

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.

Page 51: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

51© 2001 John Urrutia. All rights reserved.

[connection established]

========================================

[bdaddy] talk session

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.

root – windows is going to wash you right out of the race no problem!

Page 52: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

52© 2001 John Urrutia. All rights reserved.

[connection established]

========================================

[root] talk session

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.

root – windows is going to wash you right out of the race no problem!

Did I tell you I wash windows for living!Bye.

Ctrl - G

Page 53: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

53© 2001 John Urrutia. All rights reserved.

[connection established]

========================================

[bdaddy] talk session

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.

root – windows is going to wash you right out of the race no problem!

Did I tell you I wash windows for living!Bye.

[connection closing. Exiting]

Page 54: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

54© 2001 John Urrutia. All rights reserved.

mail - now you’ve got itProvides email and to Linux users

Supports address books and attachments

User-friendly interface

And now a short demo

Page 55: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

55© 2001 John Urrutia. All rights reserved.

TopicsFile Operations

File Compression and Archive

Obtaining User & System Information

Communicating with Other Users

Daily Miscellany

Page 56: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

56© 2001 John Urrutia. All rights reserved.

Daily Miscellany

echo

cal

date

Topics

Page 57: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

57© 2001 John Urrutia. All rights reserved.

Daily Miscellanyecho - Display a message.

Default displays on the standard output device

Page 58: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

58© 2001 John Urrutia. All rights reserved.

Daily Miscellanycal - Display a calendar month or

full yearcal [[month] year]

no parms = current month

[month]specific month to display

yearthe calendar year to display.

Page 59: 1 © 2001 John Urrutia. All rights reserved. Chapter 3 An Introduction to the Utilities.

59© 2001 John Urrutia. All rights reserved.

Daily Miscellanydate - Display or set the date & time

date [option] [‘+format’]newdate

[option][-u] - (UTC) universal time

[‘+format’]{a d D h H j m M r y s T w} date & Time{n t} formatting characters


Recommended