590 likes | 708 Views
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
E N D
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 • copy- move • head - tail • file - uniq - diff • sort - grep • lpr - more - less
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
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
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
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
File Operations • file - Display file content classification.file [option] [file-list][option] -ffile Input taken from file.
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
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
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
diff Example • Append • line1aline2,line3 • Change • line1,line2cline3,line4 • Delete • line1,line2dline3
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
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)
What is a ‘field’ • Contains ascii data • delimited by ‘whitespace’ • whitespace is: • tab • blank • carriage return • Example • the day the earth stood still
Sorting • Examples • sort myfile • sort -r myfile • sort file1 file2 • sort file1 file2 > file3 • sort –k2 myfile • (skip a field, then start comparisons)
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
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
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
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
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
lpq (Lilliputian mind your P’s and Q’s) • line print queue – displayjobs in the print queue • Syntax lpq job-identifier number(s)
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
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
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
Topics • File Operations • File Compression and Archive • Obtaining User & System Information • Communicating with Other Users • Daily Miscellany
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
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
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
Topics • File Operations • File Compression and Archive • Obtaining User & System Information • Communicating with Other Users • Daily Miscellany
Topics • Obtaining User & System Information • apropos • whereis - which • w – who - finger
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
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: …)
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
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
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
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)
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.
Topics • File Operations • File Compression and Archive • Obtaining User & System Information • Communicating with Other Users • Daily Miscellany
Topics • Communicating with Other Users • mesg • write • talk • pine
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.
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
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
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.
talk session [root@linux1root]$talk bdaddy
[root] talk session [waiting for your party to respond] ========================================
[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
[bdaddy] talk session [connection established] ========================================
[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.