4-vi+cmds+vars

Upload: baaska214

Post on 01-Jun-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 4-vi+cmds+vars

    1/43

  • 8/9/2019 4-vi+cmds+vars

    2/43

    to sho! stuff on the screen

    "#rints$ to standard output echo hello

    hello echo % short line & ne!file % short line 'in ne!file(

    echo "% short line$ & ne!file

    % short line 'in ne!file( hello)"*i, there$ *i, there

    echo +$hello+$

    "hello$

  • 8/9/2019 4-vi+cmds+vars

    3/43

  • 8/9/2019 4-vi+cmds+vars

    4/43

    3

    grep4ind #attern in 4ile's(

    grep pattern file's( grep -v pattern filename 5

    grep 6pattern filename 5 grep pattern filename 5 grep "pattern !ith spaces$ filename 5

    fgrep -f patternfile filename 5 grep -i pattern filename 5 egrep "pat17pat 7pat $ filename 5

    3

  • 8/9/2019 4-vi+cmds+vars

    5/43

  • 8/9/2019 4-vi+cmds+vars

    6/43

    =

    tr E amples9o translate single characters to single characters

    tr abc D F filename a G , bGD, cG

    tr %-H a- or tr %-H2 a- 2 or tr I%-HJ Ia- J

    translates upper case to lo!er case

    tr a- %-H n- a-mK-H%-M F filename Arot1 0 changes letters half!aD up alphabet

    tr -s +t2 0 replace multiple spacesLtabs !ith single colon

  • 8/9/2019 4-vi+cmds+vars

    7/43

  • 8/9/2019 4-vi+cmds+vars

    8/43

  • 8/9/2019 4-vi+cmds+vars

    9/43

    P

    uniqEliminate /uplicate

  • 8/9/2019 4-vi+cmds+vars

    10/43

    1?

    sort

    sort file & ne!file alphabeticallD from beginning of line sort -. file & ne!file

    alphabeticallD from third field sort -. n file & ne!file

    numeric order, third field sort -rn -. file & ne!file

    reverse numeric order ls -l 7 sort -r -. 8n 7 less

    sho! largest files( sort -t0 -.1,1 -.8,8 BetcBpass!d 7 less

    sort the pass!ord file, bD account then name

    1?

  • 8/9/2019 4-vi+cmds+vars

    11/43

    11

    Comparing 4iles

    diff file1 file reports differences bet!een files

    form allo!s changing one to the other 8,=c>,@ means lines 8-= n file1 match lines >-@ in file F is line from file1R &2 is line from file

    diff file1 file file compares files cmp file1 file compares binarD files bD bDte 'and

    reports first different bDte(

    11

  • 8/9/2019 4-vi+cmds+vars

    12/43

  • 8/9/2019 4-vi+cmds+vars

    13/43

    1

    find

    find -name filename -print find a file !ith the name "filename$

    find Tisaacs -mtime L= -print find files in mD home, older than = daDs

    find . -tDpes f -e ec ls -l U + ; onlD do "ls$ on regular files

    find . -tDpe f 7 args ls -l

    1

  • 8/9/2019 4-vi+cmds+vars

    14/43

    13

    a!.

    9his is an e tra W !ill not test on a!., butit maD be useful in some of the qui andhome!or. questions

    a!. is more than a command, it isessentiallD a language Xut if Dou !ant the

    full po!er, W !ould suggest learning andusing #erl instead 9hough harder to learn,it is much more po!erful, and does all that

    a!. does 13

  • 8/9/2019 4-vi+cmds+vars

    15/43

  • 8/9/2019 4-vi+cmds+vars

    16/43

    1=

    *o! a!. !or.s

    a!. does actions 'li.e arithmetic or printing( for lines specified bD patterns, or before anD lines are read 'AXE:WKA( orafter all lines are read 'AEK/(

    a!. XE:WK Ustart-action Uaction EK/

    Ustop-action a!. pattern1Uaction1 pattern Uaction

    pattern Uaction1=

  • 8/9/2019 4-vi+cmds+vars

    17/43

  • 8/9/2019 4-vi+cmds+vars

    18/43

    1@

    a!. variables and actions KY - number of the current line

    K4 - number of fields in current line 4S - 4ield separator YS -

  • 8/9/2019 4-vi+cmds+vars

    19/43

    1P

    Some e tra commands'Kot in tests(

    column - ma.e a list into columns ls 7 grep somefiles 7 column -c 8

    locate - easier to use then AfindA

    locate filename paste - Qoin each line of t!o files together, one after

    the other paste file1 file

    Qoin - Wf files have a field in common, combine thelines from both files if the fields match 'Must sorton the field (

  • 8/9/2019 4-vi+cmds+vars

    20/43

  • 8/9/2019 4-vi+cmds+vars

    21/43

    1

    vi Concepts

    Modes command 'ESC(

    insert 'i, a, o, etc( e mode '0( Screen, as a !indo! in the te t [here is the cursor

    *o! to move around Search for a line '"B$ and " $( E it, saving or not saving Dour changes

    1

  • 8/9/2019 4-vi+cmds+vars

    22/43

    vi modes

    Command mode [hat Dou tDpe is a command to vi

    ESC !ill change Dou from insert to command Wnsert 'or replace( mode [hatever Dou tDpe !ill go into Dour file Various commands put Dou in insert mode

    e mode Commands to "e $ editor, start !ith "0$ ;n bottom line of screen

  • 8/9/2019 4-vi+cmds+vars

    23/43

    e mode s, d, undo, !, q 0undo undo last vi operation 0! Ffilename& !rite file '0!\ to force( 0q quit '0q\ to force(

    0d delete current line 08,1?d delete lines 8 through 1?

    0sBoldBne!Bg substitute ne! for old on currentline B D BsBoldBne!Bg sub ne! for old on all lines !ith

    " D $ in them 08,1?sBoldBne!B sub ne! for 1st old in lines 8-1?

  • 8/9/2019 4-vi+cmds+vars

    24/43

  • 8/9/2019 4-vi+cmds+vars

    25/43

    8

    Search for a line

    Babc search for!ard for pattern "abc$ abc search bac.!ards for pattern "abc$ n repeat search 'in same direction(

    8

  • 8/9/2019 4-vi+cmds+vars

    26/43

    =

    9o e it vi

    HH save file and e it /; K;9 confuse !ith 6H, !hich puts it in the

    bac.ground 0!q !rite file and e it 0! Ffilename& !rite ne! file

    0!\ Ffilename& over!rite old file

    =

  • 8/9/2019 4-vi+cmds+vars

    27/43

    >

    vi Wnserting and %ppending

    Inserting text commands.

    Cursor A Append atend

    Appendafter

    cursor

    aInsert

    before

    cursor

    i

    Open newline above

    Insert atbeginning

    Opennew linebelow

    O

    o

    I

    >

  • 8/9/2019 4-vi+cmds+vars

    28/43

    @

    Vie!ing 9e t [ithin % 4ile

    Basic VI COMMANDS

    !o enter VI t"pe

    vi #lena$e %cr&

    !o save a #le t"pe

    w!o get out of VI t"pe

    ''

    INS !IN* ! +!

    I , insert te-t beforecursor

    o , insert te-t belowcurrent line

    a , insert te-t aftercursor

    O , insert te-t aboveline

    !o save a #le t"pe

    w

    !o get out of VI t"pe''

    @

  • 8/9/2019 4-vi+cmds+vars

    29/43

    P

    vi Cursor Movements

    'ursor (o$e!ents 'o!!ands

    )r% these,cursor,co!!ands ,

    in a

    le.

    .*

    / O

    0101

    Cursor

    w 2 3

    eturn

    b4

    *

    l

  • 8/9/2019 4-vi+cmds+vars

    30/43

  • 8/9/2019 4-vi+cmds+vars

    31/43

    1

    vi /eleting [ords and

  • 8/9/2019 4-vi+cmds+vars

    32/43

    emacs Concepts

    Commands use special .eDs0 control 'C9Y

  • 8/9/2019 4-vi+cmds+vars

    33/43

    'emacs concepts(

    %utomatic bac.ups Can set automatic saving

    email, directories, ftp, much more Menu control 'instead of commands( Wnformation bars

  • 8/9/2019 4-vi+cmds+vars

    34/43

    3

    Starting and Ending emacs

    emacs 'puts Dou in scratch buffer( C- C-f to read in file

    emacs filename 'edits "filename$( C- C-s save file and e it C- s save all files and e it

    C-c C-c e it '!ill as. if Dou !ant to(

    3

  • 8/9/2019 4-vi+cmds+vars

    35/43

    8

    emacs help

    C-h usual help .eD 41 'function 1 .eD( trD if C-h doesn2t !or.

    C-h a apropos C-h c !hat does a character do C-h f !hat does a function do C-h t tutorial C-h b sho! all .eD bindings C-h sho! possible help questions

    8

  • 8/9/2019 4-vi+cmds+vars

    36/43

    =

    #rocesses

    Xasic unit of multi-processing ps to sho! Dour current processes ps -l to sho! more about them 'l)long( ps -al!f sho!s all processes on sDstem, in

    long format, child procs indented, lines ifnecessarD

    =

  • 8/9/2019 4-vi+cmds+vars

    37/43

    >

    Shell Variables

    Kame and Value

    E amplesMDKame)Wsaacs*;ME)isaacsfruit)appleM;K9*)%prilfullname)"Stan Wsaacs$

    >

  • 8/9/2019 4-vi+cmds+vars

    38/43

    @

    9o Zse or See Shell Variables

    K%ME to use it echo K%ME echo a! going to eat an fruit

    fruit appledrink crab fruitdrink /fruit01uice

    echo ruit is fruit, drink is drink @

  • 8/9/2019 4-vi+cmds+vars

    39/43

    P

    ZSES

    Environment Variables to define Dour environment

  • 8/9/2019 4-vi+cmds+vars

    40/43

    3?

    Environment Variables

    ZsuallD all caps Yepresent Dour personal environment

    Zsed bD various ZKW^ programs and commands *;ME

  • 8/9/2019 4-vi+cmds+vars

    41/43

    31

    Environment Variables

    en$ to see them all Nou can change some of them

    frequentlD in startup scripts

    export so everDbodD can see them sub-shells scripts

    set sho!s local variables also

    31

  • 8/9/2019 4-vi+cmds+vars

    42/43

    3

    E ample

    d)BusrBisaacsBclassBdaD1Be ercises cd d

    pr dBe

    3

  • 8/9/2019 4-vi+cmds+vars

    43/43

    3

    SummarD of Variables

    Case sensitive Ko spaces around ")"

    _uote if there are spaces in value CurlD braces 'U, ( to separate ZsuallD character strings

    num)1?? ? is different from num)1??( echo or en$ to see them export