Advanced UNIX Shell - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Advanced UNIX Shell

Description:

who | grep ad' ad tty06 May 23 10:31 $ who | sort. ad tty06 May 23 10:31 ... ps | grep ad. The tee Command. Passes its input through to standard output unchanged. ... – PowerPoint PPT presentation

Number of Views:29
Avg rating:3.0/5.0
Slides: 29
Provided by: RJS
Category:
Tags: unix | advanced | grep | shell

less

Transcript and Presenter's Notes

Title: Advanced UNIX Shell


1
Advanced UNIX (Shell)
  • Objectives
  • to supplement the Introduction to UNIX slides
    with extra information about the Shell

2
Overview
  • 1. Redirection
  • 2. Pipes
  • 3. Background Jobs
  • 4. Filename Generation

3
1. Redirection
  • Command I/O is stream-based

standard output
command
standard input
4
You type a line it is echoed
  • catThis is a line of text.This is a line of
    text. Cat keeps copying lines of textCat keeps
    copying lines of text until you press control-D
    at the until you press control-D at the
    beginning of a line.beginning of a line.

control-D
5
Redirect Output
  • Use gt to redirect standard output to a file

standard output
file
command
standard input
6
  • cat gt sample.txtThis text is being entered at
    the keyboard.Cat is copying it to a file.Press
    control-D to indicate theend of file.
  • cat file1.c file2.c file3.c gt all-files.c

control-D
7
Redirect Input
  • Use lt to redirect standard input from a file

standard output
standard input
file
command
8
  • cat lt supply_orders2000 sheets letterhead
    ordered 10/7/971 box masking tape ordered
    10/8/97
  • cat supply_orders
  • mail ad_at_ratree.psu.ac.th lt letter.txt

9
Dangers
  • Bad cat orange pear gt orange cat input
    orange is output
  • see noclobber in C Shell
  • Good cat orange pear gt temp mv temp orange

10
Appending Output to a File
  • Use gtgt to append
  • date gt whoson cat whosonFri May 29 092419
    GMT 2000 who gtgt whoson cat whosonFri May 29
    092419 GMT 2000jenny tty02 May 29 0721ad
    tty06 May 28 1101

11
2. Pipes
  • Use a pipe to connect standard output of one
    command to standard input of another

command1
command2
standard input
standard output
12
  • Use the operator between commands
  • command 1 command2
  • Same as
  • command1 gt temp command2 lt temp rm temp

13
  • ls more
  • who grep adad tty06 May 23 1031
  • who sortad tty06 May 23 1031jenny
    tty02 May 21 1529scott tty03 May 23 0902
  • Same as who gt temp sort lt temp or sort
    temp

14
Filters
  • A filter is a command that modifies its standard
    input, putting the changes onto its standard
    output
  • who sort lpr
  • ps grep ad

15
The tee Command
  • Passes its input through to standard output
    unchanged. Also saves input into a file

file
command1
command2
tee
standard input
standard output
16
  • who tee who.out grep ad ad tty06 May
    23 1031
  • cat who.outjenny tty02 May 21 1529 ad
    tty06 May 23 1031scott tty03 May 23 0902

17
3. Background Jobs
  • A normal command executes in the foreground you
    wait until it finishes before another command can
    be typed.
  • Commands (jobs) can execute in the background. No
    need to wait for them before another command is
    typed.

18
  • Background jobs end with a
  • gcc big-program.c 1466
  • ls -l lpr 1467
  • vi report.txt

19
Killing a Background Job
  • Cannot type control-C
  • Use kill and the process ID (PID)
  • kill 1466
  • Use ps to list PIDs
  • ps PID TT STAT TIME COMMAND1466 03 S
    005 gcc big-program.c1467 03 S 004 ls -l
    lpr1524 03 R 003 ps

20
4. Filename Generation
  • Commands involving filenames (e.g. cat, ls) can
    include special characters in the filenames.
  • called metacharacters
  • three kinds
  • ?
  • ...

21
The ? Special Character
  • ? matches any single character
  • lsmem memo12 memo9 memoalex
    newmemo5memo memo5 memoa memos ls
    memo?memo9 memo5 memoa memos lpr memo?

continued
22
  • ls7may4report may14report may4report.79mayqr
    eport may.report may4report may_report
    mayreport ls may?reportmayqreport may.report
    may4report may_report

23
The Special Character
  • matches any sequence of characters(0 or more
    characters)
  • lsamemo memo memoa memosallyuser.memo
    mem memo.0612memorandum sallymemo ls
    memomemo memoa memosally memo.0612
    memorandum

continued
24
  • ls .txt lpr .txt
  • ls .c cat .c gt all-files more
    all-files rm .c mv all-files all-files.c

25
The ... Special Characters
  • Match against any single character given inside
    ...
  • Can include - to give a range
  • lspart1.txt part2.txt part3.txt part4.txt
    part5.txt lpr part135.txt cat part1-3.txt

continued
26
Useful Ranges
  • a-z any letter between a and z
  • A-Z any letter between A and Z
  • 0-9 any digit betwwn 0 and 9
  • Can combine
  • a-z,0-9

continued
27
  • lspart0 part1 part2 part3 part4
    ...part32 part33 part34 part35 ls
    part0-9 ls part120-9 ls part30-5

28
Combining Special Characters
  • ls a-m ls x-z
  • lpr p0-9.c
Write a Comment
User Comments (0)
About PowerShow.com