View
213
Download
0
Category
Preview:
Citation preview
1© 2001 John Urrutia. All rights reserved.
Chapter 3
An IntroductionAn Introduction to the to the UtilitiesUtilities
2© 2001 John Urrutia. All rights reserved.
TopicsFile Operations
File Compression and Archive
Obtaining User & System Information
Communicating with Other Users
Daily Miscellany
3© 2001 John Urrutia. All rights reserved.
File Operations
copy - move
head - tail
file - uniq - diff
sort - grep
lpr - more - less
Topics
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
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
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
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
8© 2001 John Urrutia. All rights reserved.
File Operationsfile - Display file content classification.
file [option] [file-list]
[option] -f file Input taken from file.
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
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
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
12© 2001 John Urrutia. All rights reserved.
diff ExampleAppend
line1aline2,line3
Changeline1,line2cline3,line4
Deleteline1,line2dline3
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
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)
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
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
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)
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
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
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 !
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
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
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)
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
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
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
27© 2001 John Urrutia. All rights reserved.
TopicsFile Operations
File Compression and Archive
Obtaining User & System Information
Communicating with Other Users
Daily Miscellany
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
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
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
31© 2001 John Urrutia. All rights reserved.
TopicsFile Operations
File Compression and Archive
Obtaining User & System Information
Communicating with Other Users
Daily Miscellany
32© 2001 John Urrutia. All rights reserved.
Obtaining User & System Information
apropos
whereis - which
w – who - finger
Topics
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
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: …)
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
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
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
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)
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.
40© 2001 John Urrutia. All rights reserved.
TopicsFile Operations
File Compression and Archive
Obtaining User & System Information
Communicating with Other Users
Daily Miscellany
41© 2001 John Urrutia. All rights reserved.
Communicating with Other Users
mesg
write
talk
pine
Topics
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.
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
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
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.
46© 2001 John Urrutia. All rights reserved.
[root@linux1root]$talk bdaddy
talk session
47© 2001 John Urrutia. All rights reserved.
[waiting for your party to respond]
========================================
[root] talk session
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
49© 2001 John Urrutia. All rights reserved.
[connection established]
========================================
[bdaddy] talk session
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.
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!
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
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]
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
55© 2001 John Urrutia. All rights reserved.
TopicsFile Operations
File Compression and Archive
Obtaining User & System Information
Communicating with Other Users
Daily Miscellany
56© 2001 John Urrutia. All rights reserved.
Daily Miscellany
echo
cal
date
Topics
57© 2001 John Urrutia. All rights reserved.
Daily Miscellanyecho - Display a message.
Default displays on the standard output device
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.
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