Other Utilities - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Other Utilities

Description:

Diff, lp, grep, file. Tr, sed. Types of Shell. Redirection. Piping. Command Grouping. head ... grep. Global Regular Expression Print ... – PowerPoint PPT presentation

Number of Views:41
Avg rating:3.0/5.0
Slides: 22
Provided by: Kami47
Category:
Tags: grep | utilities

less

Transcript and Presenter's Notes

Title: Other Utilities


1
Other Utilities The Shell
  • Head, tail
  • Sort, uniq
  • Diff, lp, grep, file
  • Tr, sed
  • Types of Shell
  • Redirection
  • Piping
  • Command Grouping

2
head
  • Displays the first ten lines of a file
  • cal 2001 gt lost-days
  • head lost-days
  • Pass a number to head to ask for the number of
    lines you want
  • head 6 lost-days
  • head 8 lost-days

3
tail
  • Similar to head, but displays the last ten lines
    of a file
  • tail lost-days
  • tail 2 lost-days
  • tail 14 lost-days

4
sort
  • Displays the contents of a file in order by lines
  • sort myfile
  • head 20 /etc/passwd gt mypasswd
  • cat mypasswd
  • sort mypasswd

5
uniq
  • Displays a file, skipping adjacent
    duplicatelines.
  • cat myfile ltEntergt
  • John
  • Tom
  • Tom
  • uniq myfile ltEntergt
  • John
  • Tom

6
diff
  • Compares two files and displays a list of
    differences between them
  • cat color1
  • red
  • blue
  • green
  • yellow
  • cat color2
  • red
  • blue
  • green
  • diff color1 color2
  • 4d3
  • lt yellow

7
lp
  • To print a file
  • On system V lp report
  • On BSD lpr report
  • on a printer named mailroom
  • lpr Pmailroom report
  • To see the printer jobs in queue
  • lpq
  • To remove a job number 86
  • lprm 86
  • To send more than one file
  • lpr Pmailroom file1 file2

8
grep
  • Global Regular Expression Print
  • Searches through the file to see if it contains a
    particular string
  • who gt users_on
  • grep ce144f01 users_on
  • Or
  • grep LOGNAME users_on
  • grep USER users_on

9
file
  • Classifies files according to their contents
  • file f1
  • f1 empty
  • file users_on
  • users_on ascii text
  • file inform
  • inform commands text

10
tr
  • Translates characters into other characters
  • tr 1 a lt myfile
  • Each instance of 1 in myfile is located by tr
    and changed into a
  • tr 123 abc lt myfile
  • 1 ? a
  • 2 ? b
  • 3 ? c
  • tr a-z A-Z lt myfile
  • Translates all lower case to uppercase

11
sed
  • Stream Editor
  • Sed works on the lines of a file one at a time to
    change the instance of the target
  • cat caffeine
  • coffee coffee
  • 2002 coffee coffee
  • coke coke
  • tea tea
  • sed s/coffee/milk/ coffeine
  • sed s/coffee/milk/g caffeine
  • sed /2002/s/coffee/milk/g coffeine

12
Types of Shell
  • Shell the program that waits for you to type a
    command, and then executes it.
  • Two general groups

13
Shells Connection ability
  • Technical Terms
  • Stdin ( standard input)
  • Defaultkeyboard
  • 2. Stdout(standard output)
  • Defaultscreen
  • 3. Stderr(standard error)
  • Defaultscreen

14
Redirection
  • stdout gt ( 1gt )
  • send output to a file
  • date gt myfile
  • stderr 2gt
  • send error to a file
  • cat myfile 2gt /dev/null
  • stdin lt
  • take input from a file
  • cat lt myfile gt newfile

15
Redirection Interpretation
  • Utility gt filename
  • (Shell connects output of utility to filename.)
  • Utility 2gt filename
  • (Shell connects error-output of utility to
    filename.)
  • Utility lt filename
  • (connects filename to input of utility.)

16
Standard Error
  • The error eg not found message appeared on
    your terminal is actually being written to
    standard error not standard output.Example
  • ls xx gt filename
  • xx not found
  • so you still get the message on the terminal.
  • To redirect std error to a file, use 2gt
  • ls xx 2gt filename

17
Task 1
  • Explain what each of the following commands do?
  • Sort
  • Who gt temp
  • Sort temp gt temp2
  • Sort temp1
  • Sort lt temp2
  • Sort lt temp2 gt temp1
  • Mailx John lt myletter

18
Appending
  • Caution with Redirecting output
  • Use gtgt appending instead
  • Eg, cat file1 gtgt majorfile

19
Pipes ( )
  • Send the stdout of one command to another command
    as stdin
  • who sort
  • who sort more

20
tee
  • The tee utility copies std input to std output
    and to one or more files you specify.
  • Who tee whofile

21
Task 2
  • What do the following commands do?
  • Who sort gt loggers
  • Who wc l
  • Who grep yourusername
  • Who grep USER
  • Who grep LOGNAME
  • Who tee whofile grep John
  • cat numberfile tr 1234 abcd
Write a Comment
User Comments (0)
About PowerShow.com