dba important linux commands

97
UNIX / Linux: 7 Practical PS Command Examples for Process Monitoring ! S"SI#"L" on "P$IL %& ' &( %% Process is a running instance of a program) Linux is a multitas*ing operating s!stem' +,ic, means t,at more t,an one process can e acti-e at once) Use ps command to find out +,at processes are running on !our s!stem) .,is article explains 7 practical usages of ps command and its options) .o monitor and control t,e processes' Linux pro-ides lot of commands suc, as ps'  *ill' *illall  ' nice ' re nice and  top commands)  %) List Currentl! $unning Processes ps 0ef' ps 0aux1 Its a commonl! used example +it, a ps command to list do+n all t,e process +,ic, are currentl! running in a mac,ine) .,e follo+ing example s,o+s t,e options of ps command to get all t,e processes) 2 ps 0ef root &344% 4 ( 5e%( 6 ((:(:8% 9pdflus, root &347( 4 ( 5e%( 6 ((:((:&( 9pdflus, root (88 ;& ( 5e&% 6 ((:((:%% ss,d: root<pts/%8 root (34 (88 ( 5e&% pts/%8 ((:((:(& 0as, root (= ;& ( 5e&% 6 ((:((:%( ss,d: root<pts/%4 >,ere: 0e to displa! all t,e processes) 0f to displa! full format listing)

Upload: pankajsharma2302

Post on 18-Oct-2015

148 views

Category:

Documents


4 download

DESCRIPTION

very important commandds for oracle dba

TRANSCRIPT

  • 5/28/2018 dba important linux commands

    1/97

    UNIX / Linux: 7 Practical PS Command Examples for Process Monitoring

    ! S"SI#"L" on "P$IL %&' &(%%

    Process is a running instance of a program) Linux

    is a multitas*ing operating s!stem' +,ic, means t,at more t,an one process can e acti-e atonce) Use ps command to find out +,at processes are running on !our s!stem)

    .,is article explains 7 practical usages of ps command and its options)

    .o monitor and control t,e processes' Linux pro-ides lot of commands suc, as ps' *ill'*illall' nice 'renice and top commands)

    %) List Currentl! $unning Processes ps 0ef' ps 0aux1

    Its a commonl! used example +it, a ps command to list do+n all t,e process +,ic, arecurrentl! running in a mac,ine) .,e follo+ing example s,o+s t,e options of ps command to get

    all t,e processes)

    2 ps 0ef

    root &344% 4 ( 5e%( 6 ((:(:8% 9pdflus,

    root &347( 4 ( 5e%( 6 ((:((:&( 9pdflus,

    root (88 ;& ( 5e&% 6 ((:((:%% ss,d: root

  • 5/28/2018 dba important linux commands

    2/97

    In case of ?S@ mac,ines' !ou can use Aps 0auxB +ill gi-e t,e details aout all t,e process ass,o+n ao-e)

    2 ps 0aux

    &) List t,e Process ased on t,e UI@ and Commands ps 0u' ps 0C1

    Use 0u option to displa!s t,e process t,at elongs to a specific username) >,en !ou ,a-emultiple username' separate t,em using a comma) .,e example elo+ displa!s all t,e processt,at are o+ned ! user +++run' or postfix)

    2 ps 0f 0u +++run'postfix

    UI@ PI@ PPI@ C S.IME .. .IME CM@

    postfix 7847 784 ( Mar(= 6 ((:((:(( Dmgr 0l 0t fifo 0u

    +++run 78=4 78=% ( Mar(= 6 ((:((:(( /usr/sin/,ttpd&0prefor* 0f

    /etc/apac,e&/,ttpd)conf

    +++run 78=3 78=% ( Mar(= 6 ((:((:(( /usr/sin/,ttpd&0prefor* 0f/etc/apac,e&/,ttpd)conf

    +++run 78=7 78=% ( Mar(= 6 ((:((:(( /usr/sin/,ttpd&0prefor* 0f/etc/apac,e&/,ttpd)conf

    +++run 78=; 78=% ( Mar(= 6 ((:((:(( /usr/sin/,ttpd&0prefor* 0f/etc/apac,e&/,ttpd)conf

    +++run 78== 78=% ( Mar(= 6 ((:((:(( /usr/sin/,ttpd&0prefor* 0f/etc/apac,e&/,ttpd)conf

    +++run %((7; 78=% ( Mar(= 6 ((:((:(( /usr/sin/,ttpd&0prefor* 0f/etc/apac,e&/,ttpd)conf

    +++run %((;& 78=% ( Mar(= 6 ((:((:(( /usr/sin/,ttpd&0prefor* 0f/etc/apac,e&/,ttpd)conf

    postfix %4377 784 ( &&:& 6 ((:((:(( pic*up 0l 0t fifo 0u

    ften ps is used +it, grep li*e Fps 0aux G grep commandH to get t,e list of process +it, t,e gi-en

    command)?ut ps command itself ,as an option to ac,ie-e t,e same) .,e follo+ing example s,o+s t,at allt,e processes +,ic, ,as tatad)pl in its command execution)

    2 ps 0f 0C tatad)pl

    UI@ PI@ PPI@ C S.IME .. .IME CM@

  • 5/28/2018 dba important linux commands

    3/97

    root =473 % ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    root =477 =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    root =47= =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    root =4;( =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    root =4;% =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    root =4;& =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    root %&% =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    Note: >e can create aliasesfor ps command to list processes ased on commands' users orgroups)

    ) List t,e processes ased on PI@s or PPI@s ps 0p' ps ppid1

    Eac, process +ill e assigned +it, t,e uniDue Process I@ PI@1)

    >,en !ou launc, some application' it mig,t for* numer of processes and eac, su process+ill ,a-e its o+n PI@) So' eac, process +ill ,a-e its o+n process id and parent processid)

    5or all t,e processes t,at a process for*s +ill ,a-e t,e same PPI@ parent process identifier1).,e follo+ing met,od is used to get a list of processes +it, a particular PPI@)

    2 ps 0f 00ppid =473

    UI@ PI@ PPI@ C S.IME .. .IME CM@

    root =477 =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    root =47= =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    root =4;( =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    root =4;% =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    root =4;& =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    root %&% =473 ( Mar(= 6 ((:((:(( /opt/tata/perl/in/perl /opt/tata/in/tatad)pl

    .,e follo+ing example is to list t,e processes +,ic, ,as gi-en PI@)

    2 ps 0f 0p &4((='7&4;'&8&3

    UI@ PI@ PPI@ C S.IME .. .IME CM@

    root &8&3 8 ( Mar(= 6 ((:((:(( 9reiserfs/(

    root 7&4; % ( Mar(= 6 ((:((:(( /usr/sin/nscd

    http://www.thegeekstuff.com/2010/04/unix-bash-alias-examples/http://www.thegeekstuff.com/2010/04/unix-bash-alias-examples/
  • 5/28/2018 dba important linux commands

    4/97

    postfix &4((= 784 ( ((:(& 6 ((:((:(( pic*up 0l 0t fifo 0u

    8) List Processes in a Jierarc,! ps forest1

    .,e example elo+ displa! t,e process Id and commands in a ,ierarc,!) forest is an argumentto ps command +,ic, displa!s "SCII art of process tree) 5rom t,is tree' +e can identif! +,ic, is

    t,e parent process and t,e c,ild processes it for*ed in a recursi-e manner)

    2 ps 0e 0o pid'args 00forest

    83; K ss,d: root

  • 5/28/2018 dba important linux commands

    5/97

    3) List all t,reads for a particular process ps 0L1

    ou can get a list of t,reads for t,e processes) >,en a process ,angs' +e mig,t need toidentif! t,e list of t,reads running for a particular process as s,o+n elo+)

    2 ps 0C a-a 0L 0o pid'tid'pcpu'state'nl+p'args

    PI@ .I@ QCPU S NL>P CMM"N@

    %3==& %3==& ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %3== ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %3==8 ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %3==4 ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %3==3 ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %3==7 ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %3==; ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %3=== ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %7((( ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %7((% ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

  • 5/28/2018 dba important linux commands

    6/97

    %3==& %7((& ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %7(( ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug

    0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %7(&8 ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %474 ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    %3==& %4748 ()( S %4 ))/re/in/a-a 0@a-a)ext)dirs))/re/li/ext:))/li:))/autoli 0Xdeug

    0Xnoagent 0@a-a)compilerNNE0Xrund+p:transportdtsoc*et'ser-er!'suspendn'address4((3

    0L option is used to displa! t,e list of t,reads for a process +,ic, ,as t,e command gi-en) "ndit also displa!s nl+p' +,ic, represents numer of lig,t +eig,t processes) In t,e ao-e example'a total of %4 a-a t,reads are running)

    7) 5inding memor! Lea* ps sort pmem1

    " memor! lea*' tec,nicall!' is an e-er0increasing usage of memor! ! an application)

    >it, common des*top applications' t,is ma! go unnoticed' ecause a process t!picall! freesan! memor! it ,as used +,en !ou close t,e application)

    Jo+e-er' In t,e client/ser-er model' memor! lea*age is a serious issue' ecause applicationsare expected to e a-ailale &8R7) "pplications must not continue to increase t,eir memor!usage indefinitel!' ecause t,is can cause serious issues) .o monitor suc, memor! lea*s' +ecan use t,e follo+ing commands)

    2 ps aux 00sort pmem

    USE$ PI@ QCPU QMEM ST $SS .. S.". S."$. .IME CMM"N@root % ()( ()( %4&( 4(; 6 S &((4 %:&7 init

    inst %(= ()( ()8 88(; (8; 6 S &((4 %:44 agnt idle1

    inst &=%= ()( ()8 844;( 73; 6 S &((4 &(:(& agnt idle1

    inst &84=8 ()( ()8 84(3; 3=3( 6 S &((4 %4:84 agnt idle1

  • 5/28/2018 dba important linux commands

    7/97

    root &7384 ()( %8)8 %&%&;; %%;=73 6 S &((4 :(% /.as*Ser-er/in/)/+rapper0linux0x;30&

    In t,e ao-e ps command' sort option outputs t,e ,ig,est QMEM at ottom) ust note do+nt,e PI@ for t,e ,ig,est QMEM usage) .,en use ps command to -ie+ all t,e details aout t,is

    process id' and monitor t,e c,ange o-er time) ou ,ad to manuall! repeat ir or put it as a cronto a file)

    2 ps e- 00pid&7384

    PI@ .. S.". .IME M"5L .$S @$S $SS QMEM CMM"N@

    &7384 6 S :(% ( &4 %&%&3& %%;=73 %8)8 /.as*Ser-er/in/)/+rapper0linux0x;30&

    2 ps e- 00pid&7384

    PI@ .. S.". .IME M"5L .$S @$S $SS QMEM CMM"N@

    &7384 6 S :(% ( &4 %&%&3& %%;=73 %8)8 /.as*Ser-er/in/)/+rapper0linux0x;30&

    Note: In t,e ao-e output' if $SS resident set siVe' in #?1 increases o-er time so +ouldQMEM1' it ma! indicate a memor! lea* in t,e application)

    S+itc,e of ps : SIMPLE P$CESS SELEC.IN

    S+itc, @escription

    0" select all processes

    0N negate selection

    0a select all +it, a tt! except session leaders

    0d select all' ut omit session leaders

    0e select all processes

    . select all processes on t,is terminal

    a select all processes on a terminal' including t,ose of ot,erusers

    g reall! all' e-en group leaders does not,ing +/o SunSsettings1

    r restrict output to running processes

    x select processes +it,out controlling tt!s

  • 5/28/2018 dba important linux commands

    8/97

    00deselect

    negate selection

    P$CESS SELEC.IN ? LIS.

    S+itc, @escription

    0C select ! command name

    0W select ! $WI@ supports names1

    0U select ! $UI@ supports names1

    0g select ! session leader $ ! group name

    0p select ! PI@

    0s select processes elonging to t,e sessionsgi-en

    0t select ! tt!

    0u select ! effecti-e user I@ supports names1

    U select processes for specified users

    p select ! process I@

    t select ! tt!

    00Wroup

    select ! real group name or I@

    00User select ! real user name or I@

    00group select ! effecti-e group name or I@

    00pid select ! process I@

    00sid select ! session I@

    00tt! select ! terminal

    00user select ! effecti-e user name or I@

    0%& implied 00sid

    %& implied 00pid

    U.PU. 5$M". CN.$L

    S+itc, @escription

    0 is preloaded 0o

  • 5/28/2018 dba important linux commands

    9/97

    0c different sc,eduler info for 0l option

    0f does full listing

    0 os format

    0l long format0o user0defined format

    0! do not s,o+ flagsY s,o+ rss in place ofaddr

    is preloaded o o-erloaded1

    X old Linux i;3 register format

    o control format

    l displa! long format

    o specif! user0defined format

    s displa! signal format

    u displa! user0oriented format

    - displa! -irtual memor! format

    00formatuser0defined format

    U.PU. M@I5IE$S

    S+itc, @escription

    0J s,o+ process ,ierarc,! forest1

    0m s,o+ all t,reads

    0n set namelist file

    0+ +ide output

    C use ra+ CPU time for QCPU instead of deca!ing a-erage

    N specif! namelist file

    sorting order o-erloaded1

    S include some dead c,ild process data as a sum +it, t,eparent1

    c true command name

    e s,o+ en-ironment after t,e command

  • 5/28/2018 dba important linux commands

    10/97

    f "SCII0art process ,ierarc,! forest1

    , do not print ,eader lines repeat ,eader lines in ?S@personalit!1

    m all t,reads

    n numeric output for >CJ"N and USE$

    + +ide output

    00cols set screen +idt,

    00columns set screen +idt,

    00cumulati-e

    include some dead c,ild process data as a sum +it, t,eparent1

    00forest "SCII art process tree

    00,tml J.ML escaped output

    00,eaders repeat ,eader lines

    00no0,eaders

    print no ,eader line at all

    00lines set screen ,eig,t

    00nul unustified output +it, NULs

    00null unustified output +it, NULs

    00ro+s set screen ,eig,t

    00sort specif! sorting order

    00+idt, set screen +idt,

    00Vero unustified output +it, NULs

    IN5$M".IN

    S+itc, @escription

    0 print -ersion

    L list all formatspecifiers

    s,o+ -ersion info

    00,elp print ,elp message

    00info print deugging info

  • 5/28/2018 dba important linux commands

    11/97

    00-ersion

    print -ersion

    ?SLE.E

    S+itc,

    @escription

    " increase t,e argument space @ecUnix1

    M use alternate core tr! 0n or N instead1

    > get s+ap info from ))) not /de-/drum tr! 0n or Ninstead1

    * use /-mcore as c0dumpfile tr! 0n or N instead1

    ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ ))

    %( Linux @U Command Examples 5iles and 5olders @is* Usage SiVe1

    ! JIM"NSJU "$$" on UNE &7' &(%&

    @u stands for @is* Usage)

    Linux du command is used for summariVing t,e dis* usage in terms of file siVe) It can e used+it, folders to get t,e total dis* usage) .,is article pro-ides some examples on ,o+ to use ducommand effecti-el!)

    "ll t,e du examples s,o+n ,ere are executed on a director! containing t,e follo+ing contents:

    2 ls

    linux#ernel red,at testfile)txt uuntu

    %) " asic example

    2 du 0a

    ( )/red,at/r,7

    8 )/red,at

    8 )/testfile)txt

    ( )/linux#ernel

  • 5/28/2018 dba important linux commands

    12/97

    ( )/uuntu/u%(

    8 )/uuntu

    %3 )

    I ,a-e used t,e 0a flag in t,e example ao-e to s,o+ t,e dis* usage of all t,e files anddirectories) Its ecause if 0a is not used t,en onl! directories t,at are occup!ing some dis* arelisted) 5or example :

    2 du

    8 )/red,at

    8 )/uuntu

    %3 )

    So' no+ +e get a asic idea aout ,o+ to use du command ut as +it, me' an!one +ould find it,ard to understand +,at t,ose numers in t,e output mean66Lets mo-e on to next examples and t,e clouds +ill clear off)

    &) @ispla! output in ,uman readale form using 0,

    2 du 0a,

    ( )/red,at/r,7

    8)(# )/red,at

    8)(# )/testfile)txt

    ( )/linux#ernel

    ( )/uuntu/u%(

    8)(# )/uuntu

    %3# )

    So +e see t,at in t,e ao-e example' I used t,e 0, flag along +it, t,e 0a flag) .,e 0, flag isused to get t,e output in t,e ,uman readale format) "s !ou can see t,at ao-e output is more

    eas! to understand as dis* usage is listed in terms of A#B)

    ) @ispla! grand total in t,e output using 0c

    .,e example t,at I am using ,as a small director! structure) ne could easil! calculate t,e totaldis* usage of t,e director! ! calculating manuall!) ?ut' in real time scenario manual calculationis not practical) So' t,ere exists a flag t,roug, +,ic, one can get t,e total usage in t,e output)

    2 du 0a,c

  • 5/28/2018 dba important linux commands

    13/97

    ( )/red,at/r,7

    8)(# )/red,at

    8)(# )/testfile)txt

    ( )/linux#ernel

    ( )/uuntu/u%(

    8)(# )/uuntu

    %3# )

    %3# total

    So +e see t,at t,roug, t,e 0c flag' one can get t,e total usage in t,e output)

    8) @ispla! onl! t,e total count using 0sIf !ou +is, to fetc, onl! t,e total siVe in form of a summar!' use t,e 0s flag)

    2 du 0s,

    7)W )

    So +e see t,at onl! t,e total siVe +as displa!ed in t,e output ao-e)

    4) 5eed input files from stdin using Afiles(0from0B

    If t,ere arises a situation +,erein !ou +ant to pro-ide AduB input on t,e go' t,en t,is is possile

    t,roug, t,e Afiles(0fromB flag)

    2 du 0a, 00files(0from0

    cop!% cop!

    file% file

    ,ello>orld%,ello>orld

    [C

    2

    Note t,at +e passed -alue as A0B to t,e flag Afiles(0fromB in order to indicate AduB to startaccepting t,e file names from stdin) "fter entering eac, file name press ctrl\@ t+ice in order toproduce t,e output for t,at file)

    3) End t,e output +it, null !te using 0(

  • 5/28/2018 dba important linux commands

    14/97

    If !ou +is, to produce eac, output ending +it,out a ne+line ut +it, a null !te instead t,enuse t,e 0( flag)

    2 du 0am 0(

    ( )/red,at/r,7% )/red,at% )/testfile)txt( )/linux#ernel( )/uuntu/u%(% )/uunt

    u%

    So +e see t,at t,e output ao-e +as produced in a single line as eac, output +as terminated+it, a ( !te)

    7) CustomiVe t,e loc* siVe in output t,roug, loc*0siVe

    .al*ing of loc* siVe' some times it is reDuired to ,a-e output in a different +a!) 5or example :

    2 du 0ac

    ( )/red,at/r,7

    8 )/red,at

    8 )/testfile)txt

    ( )/linux#ernel

    ( )/uuntu/u%(

    8 )/uuntu

    %3 )

    %3 total

    .,e ao-e output is represented in terms of numer of %(&8 !tes loc*s) No+ suppose if +ereDuire t,e output to e in numer of &(8; !tes loc*' t,en in t,is case t,e flag Aloc*0siVeBcan e used)

    2 du 0a,c 00loc*0siVe&(8;

    ( )/red,at/r,7

    & )/red,at

    & )/testfile)txt

    ( )/linux#ernel

    ( )/uuntu/u%(

    & )/uuntu

  • 5/28/2018 dba important linux commands

    15/97

    ; )

    ; total

    So +e see t,at t,e ao-e output is in t,e form of numer of &(8; !tes loc*s)

    ;) @ispla! output in !tes using 0

    .o get t,e output in terms of !tes' t,e 0 flag can e used)

    2 du 0ac,

    ( )/red,at/r,7

    8(=3 )/red,at

    )/testfile)txt

    ( )/linux#ernel( )/uuntu/u%(

    8(=3 )/uuntu

    %&&=% )

    %&&=% total

    So +e see t,at t,e ao-e output is in terms of !tes)

    =) Exclude particular t!pes of files1 using exclude

    Suppose +e do not +ant to ,a-e t,e statistics of )txt files) So for t,ese t!pes of reDuirementst,ere is a AexcludeB flag)

    2 du 0c,a 00exclude])txt

    ( )/red,at/r,7

    8)(# )/red,at

    ( )/linux#ernel

    ( )/uuntu/u%(

    8)(# )/uuntu

    % )

    % total

    So +e see t,at in t,e output ao-e' t,e text file entr! +as not t,ere)

  • 5/28/2018 dba important linux commands

    16/97

    %() @ispla! t,e modification time and customiVe t,e displa! st!le

    .,is can e ac,ie-ed t,roug, time and time0st!le flags)

    2 du 0c,a 00time

    ( &(%&0(40&& &%:4& )/red,at/r,7

    8)(# &(%&0(40&& &%:4& )/red,at

    &(%&0(30%; %=:& )/testfile)txt

    ( &(%&0(40&& &%:4& )/linux#ernel

    ( &(%&0(40&& &%:4& )/uuntu/u%(

    8)(# &(%&0(40&& &%:4& )/uuntu

    %# &(%&0(30%; %=:& )%# &(%&0(30%; %=:& total

    2 du 0c,a 00time 00time0st!leiso

    ( &(%&0(40&& )/red,at/r,7

    8)(# &(%&0(40&& )/red,at

    &(%&0(30%; )/testfile)txt

    ( &(%&0(40&& )/linux#ernel

    ( &(%&0(40&& )/uuntu/u%(

    8)(# &(%&0(40&& )/uuntu

    %# &(%&0(30%; )

    %# &(%&0(30%; total

    5or time0st!le' !ou can also use full0iso' long0iso' iso)

    S+itc,es:

    du ta*es a single argument' specif!ing a pat,name for du to +or*Y if it is not specified' t,ecurrent director! is used) .,e SUS mandates for du t,e follo+ing options:

    0a' displa! an entr! for eac, file and not director!1 contained in t,e current director!

    0c' displa! a grand total of t,e dis* usage found ! t,e ot,er arguments

  • 5/28/2018 dba important linux commands

    17/97

    0d ' t,e dept, at +,ic, summing s,ould occur) 0d ( sums at t,e current le-el' 0d % sums at t,esudirector!' 0d & at su0sudirectories' etc)

    0J' calculate dis* usage for lin* references specified on t,e command line

    0*' s,o+ siVes as multiples of %(&8 !tes'not 4%&0!te

    0L' calculate dis* usage for lin* references an!+,ere

    0s' report onl! t,e sum of t,e usage in t,e current director!' not for eac, file

    0x' onl! tra-erse files and directories on t,e de-ice on +,ic, t,e pat,name argument isspecified)

    t,er Unix and Unix0li*e operating s!stems ma! add extra options) 5or example' ?S@ andWNU duspecif! a 0, option' displa!ing dis* usage in a format easier to read ! t,e user' addingunits +it, t,e appropriate SI prefix e)g) %( M?1))

    ptions

    0a' 00all +rite counts for all files' not ust directories)

    00apparent0siVe print apparent siVes' rat,er t,an dis* usageY alt,oug, t,e apparent siVe is usuallma! e larger due to ,oles in ^sparse^1 files' internal fragmentation' indirect locli*e)

    0?' 00loc*0

    siVeSITE

    scale siVes ! SITE efore printing t,em) 5or example' ^0?M^ prints siVes in units

    %'(8;'473 !tes) See SITE format elo+1)

    0' 00!tes eDui-alent to ^00apparent0siVe 00loc*0siVe%^

    0c' 00total displa! a grand total)

    0@' 00dereference0args

    dereference onl! s!mlin*s t,at are listed on t,e command line)

    00files(0from5 summariVe dis* usage of t,e NUL0terminated file namesspecified in file 5Y If 5 isnames from standard input)

    0J eDui-alent to 00dereference0args 0@1)

    0,' 00,uman0 print siVes in ,uman readale format' rounding -alues and using are-iations) 5

    http://en.wikipedia.org/wiki/Bytehttp://en.wikipedia.org/wiki/Bytehttp://en.wikipedia.org/wiki/SI_prefixhttp://en.wikipedia.org/wiki/SI_prefixhttp://en.wikipedia.org/wiki/Megabytehttp://en.wikipedia.org/wiki/Megabytehttp://www.computerhope.com/jargon/d/director.htmhttp://www.computerhope.com/jargon/d/director.htmhttp://www.computerhope.com/jargon/f/filefrag.htmhttp://www.computerhope.com/jargon/f/filefrag.htmhttp://www.computerhope.com/jargon/b/block.htmhttp://www.computerhope.com/jargon/s/symblink.htmhttp://www.computerhope.com/jargon/s/symblink.htmhttp://www.computerhope.com/jargon/c/commandi.htmhttp://www.computerhope.com/jargon/c/commandi.htmhttp://www.computerhope.com/jargon/n/nullchar.htmhttp://www.computerhope.com/jargon/n/nullchar.htmhttp://www.computerhope.com/jargon/f/filename.htmhttp://www.computerhope.com/jargon/f/filename.htmhttp://www.computerhope.com/jargon/s/stdin.htmhttp://www.computerhope.com/jargon/s/stdin.htmhttp://en.wikipedia.org/wiki/Bytehttp://en.wikipedia.org/wiki/SI_prefixhttp://en.wikipedia.org/wiki/Megabytehttp://www.computerhope.com/jargon/d/director.htmhttp://www.computerhope.com/jargon/f/filefrag.htmhttp://www.computerhope.com/jargon/b/block.htmhttp://www.computerhope.com/jargon/s/symblink.htmhttp://www.computerhope.com/jargon/c/commandi.htmhttp://www.computerhope.com/jargon/n/nullchar.htmhttp://www.computerhope.com/jargon/f/filename.htmhttp://www.computerhope.com/jargon/s/stdin.htm
  • 5/28/2018 dba important linux commands

    18/97

    readale %#' &8M' &W' etc)

    00si li*e 0,' ut use po+ers of %(((' not %(&8)

    0* li*e 00loc*0siVe%#)

    0l' 00count0lin*s count siVes man! times if ,ard0lin*ed)

    0m li*e 00loc*0siVe%M)

    0L' 00dereference dereference all s!molic lin*s)

    0P' 00no0dereference don^t follo+ an! s!molic lin*s t,is is t,e default1)

    0(' 00null end eac, output line +it, ( !te rat,er t,an ne+line)

    0S' 00separate0dirs do not include siVe of sudirectories)

    0s' 00summariVe displa! onl! a total for eac, argument)

    0x' 00one0file0s!stem

    s*ip directories on different file s!stems)

    0X' 00exclude0from5ILE

    exclude files t,at matc, an! pattern in 5ILE

    00excludeP"..E$N

    exclude files t,at matc, P"..E$N)

    0d' 00max0dept,N print t,e total for a director! or file' +it, 00all1 onl! if it is N or fe+er le-els elo+ command line argumentY 00max0dept,(is t,e same as 00summariVe)

    00time s,o+ time of t,e last modification of an! file in t,e director!' or an! of its sudire

    http://www.computerhope.com/jargon/h/hardlink.htmhttp://www.computerhope.com/jargon/h/hardlink.htmhttp://www.computerhope.com/jargon/n/newline.htmhttp://www.computerhope.com/jargon/n/newline.htmhttp://www.computerhope.com/jargon/s/subdirec.htmhttp://www.computerhope.com/jargon/s/subdirec.htmhttp://www.computerhope.com/jargon/h/hardlink.htmhttp://www.computerhope.com/jargon/n/newline.htmhttp://www.computerhope.com/jargon/s/subdirec.htm
  • 5/28/2018 dba important linux commands

    19/97

    00time>$@ s,o+ time as >$@ instead of modification time: atime'access' use' ctime or st

    00time0st!leS.LE

    s,o+ times using st!le S.LE: full0iso' long0iso' iso' or\5$M".) 5$M". is li*e t,e format of date^)1

    00,elp displa! a ,elp message and exit)

    00-ersion output -ersion information and exit)

    ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ

    ou s,ould get a grip on t,e Linux grep command)

    .,is is part of t,e on0going %4 Examples series' +,ere %4 detailed examples +ill e pro-ided fora specific command or functionalit!) Earlier +e discussed %4 practical examples for Linux findcommand' Linuxcommand line ,istor! and m!sDladmin command)

    In t,is article let us re-ie+ %4 practical examples of Linux grep command t,at +ill e -er! usefulto ot, ne+ies and experts)

    5irst create t,e follo+ing demofile t,at +ill e used in t,e examples elo+ to demonstrate grepcommand)

    2 cat demofile

    .JIS LINE IS .JE %S. UPPE$ C"SE LINE IN .JIS 5ILE)

    t,is line is t,e %st lo+er case line in t,is file)

    .,is Line Jas "ll Its 5irst C,aracter f .,e >ord >it, Upper Case)

    .+o lines ao-e t,is line is empt!)

    "nd t,is is t,e last line)

    http://www.computerhope.com/jargon/d/date.htmhttp://www.computerhope.com/jargon/d/date.htmhttp://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/http://www.thegeekstuff.com/2008/08/15-examples-to-master-linux-command-line-history/http://www.thegeekstuff.com/2009/01/15-practical-usages-of-mysqladmin-command-for-administering-mysql-server/http://www.thegeekstuff.com/2009/01/15-practical-usages-of-mysqladmin-command-for-administering-mysql-server/http://www.computerhope.com/jargon/d/date.htmhttp://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/http://www.thegeekstuff.com/2008/08/15-examples-to-master-linux-command-line-history/http://www.thegeekstuff.com/2009/01/15-practical-usages-of-mysqladmin-command-for-administering-mysql-server/
  • 5/28/2018 dba important linux commands

    20/97

    %) Searc, for t,e gi-en string in a single file

    .,e asic usage of grep command is to searc, for a specific string in t,e specified file as s,o+nelo+)

    S!ntax:

    grep literalstring filename

    2 grep t,is demofile

    t,is line is t,e %st lo+er case line in t,is file)

    .+o lines ao-e t,is line is empt!)

    &) C,ec*ing for t,e gi-en string in multiple files)

    S!ntax:

    grep string 5ILEP"..E$N

    .,is is also a asic usage of grep command) 5or t,is example' let us cop! t,e demofile todemofile%) .,e grep output +ill also include t,e file name in front of t,e line t,at matc,ed t,especific pattern as s,o+n elo+) >,en t,e Linux s,ell sees t,e meta c,aracter' it does t,eexpansion and gi-es all t,e files as input to grep)

    2 cp demofile demofile%

    2 grep t,is demo]

    demofile:t,is line is t,e %st lo+er case line in t,is file)

    demofile:.+o lines ao-e t,is line is empt!)

    demofile:"nd t,is is t,e last line)

    demofile%:t,is line is t,e %st lo+er case line in t,is file)

    demofile%:.+o lines ao-e t,is line is empt!)

    demofile%:"nd t,is is t,e last line)

    ) Case insensiti-e searc, using grep 0i

    S!ntax:

    grep 0i string 5ILE

  • 5/28/2018 dba important linux commands

    21/97

    .,is is also a asic usage of t,e grep) .,is searc,es for t,e gi-en string/pattern caseinsensiti-el!) So it matc,es all t,e +ords suc, as Ft,eH' F.JEH and F.,eH case insensiti-el! ass,o+n elo+)

    2 grep 0i t,e demofile.JIS LINE IS .JE %S. UPPE$ C"SE LINE IN .JIS 5ILE)

    t,is line is t,e %st lo+er case line in t,is file)

    .,is Line Jas "ll Its 5irst C,aracter f .,e >ord >it, Upper Case)

    "nd t,is is t,e last line)

    8) Matc, regular expression in files

    S!ntax:

    grep $EWEX filename

    .,is is a -er! po+erful feature' if !ou can use use regular expression effecti-el!) In t,e follo+ingexample' it searc,es for all t,e pattern t,at starts +it, FlinesH and ends +it, Fempt!H +it,an!t,ing in0et+een) i)e .o searc, Flines9an!t,ing in0et+eenempt!H in t,e demofile)

    2 grep lines)]empt! demofile

    .+o lines ao-e t,is line is empt!)

    5rom documentation of grep: " regular expression ma! e follo+ed ! one of se-eral repetitionoperators:

    6 .,e preceding item is optional and matc,ed at most once)

    ] .,e preceding item +ill e matc,ed Vero or more times)

    \ .,e preceding item +ill e matc,ed one or more times)

    _n` .,e preceding item is matc,ed exactl! n times)

    _n'` .,e preceding item is matc,ed n or more times)

    _'m` .,e preceding item is matc,ed at most m times)

    _n'm` .,e preceding item is matc,ed at least n times' ut not more t,an m times)

    4) C,ec*ing for full +ords' not for su0strings using grep 0+

    If !ou +ant to searc, for a +ord' and to a-oid it to matc, t,e sustrings use 0+ option) ustdoing out a normal searc, +ill s,o+ out all t,e lines)

  • 5/28/2018 dba important linux commands

    22/97

    .,e follo+ing example is t,e regular grep +,ere it is searc,ing for FisH) >,en !ou searc, for FisH'+it,out an! option it +ill s,o+ out FisH' F,isH' Ft,isH and e-er!t,ing +,ic, ,as t,e sustring FisH)

    2 grep 0i is demofile

    .JIS LINE IS .JE %S. UPPE$ C"SE LINE IN .JIS 5ILE)

    t,is line is t,e %st lo+er case line in t,is file)

    .,is Line Jas "ll Its 5irst C,aracter f .,e >ord >it, Upper Case)

    .+o lines ao-e t,is line is empt!)

    "nd t,is is t,e last line)

    .,e follo+ing example is t,e >$@ grep +,ere it is searc,ing onl! for t,e +ord FisH) Please

    note t,at t,is output does not contain t,e line F.,is Line Jas "ll Its 5irst C,aracter f .,e >ord>it, Upper CaseH' e-en t,oug, FisH is t,ere in t,e F.,isH' as t,e follo+ing is loo*ing onl! for t,e+ord FisH and not for Ft,isH)

    2 grep 0i+ is demofile

    .JIS LINE IS .JE %S. UPPE$ C"SE LINE IN .JIS 5ILE)

    t,is line is t,e %st lo+er case line in t,is file)

    .+o lines ao-e t,is line is empt!)

    "nd t,is is t,e last line)

    3) @ispla!ing lines efore/after/around t,e matc, using grep 0"' 0? and 0C

    >,en doing a grep on a ,uge file' it ma! e useful to see some lines after t,e matc,) ou mig,tfeel ,and! if grep can s,o+ !ou not onl! t,e matc,ing lines ut also t,e linesafter/efore/around t,e matc,)

    Please create t,e follo+ing demotext file for t,is example)

    2 cat demotext

    8) im >ord Na-igation

    ou ma! +ant to do se-eral na-igation in relation to t,e +ords' suc, as:

  • 5/28/2018 dba important linux commands

    23/97

    ] e 0 go to t,e end of t,e current +ord)

    ] E 0 go to t,e end of t,e current >$@)

    ] 0 go to t,e pre-ious efore1 +ord)

    ] ? 0 go to t,e pre-ious efore1 >$@)

    ] + 0 go to t,e next +ord)

    ] > 0 go to t,e next >$@)

    >$@ 0 >$@ consists of a seDuence of non0lan* c,aracters' separated +it, +,ite space)

    +ord 0 +ord consists of a seDuence of letters' digits and underscores)

    Example to s,o+ t,e difference et+een >$@ and +ord

    ] %=&)%3;)%)% 0 single >$@

    ] %=&)%3;)%)% 0 se-en +ords)

    3)% @ispla! N lines after matc,

    0" is t,e option +,ic, prints t,e specified N lines after t,e matc, as s,o+n elo+)

    S!ntax:

    grep 0" Nb string 5ILEN"ME

    .,e follo+ing example prints t,e matc,ed line' along +it, t,e lines after it)

    2 grep 0" 0i example demotext

    Example to s,o+ t,e difference et+een >$@ and +ord

    ] %=&)%3;)%)% 0 single >$@

    ] %=&)%3;)%)% 0 se-en +ords)

    3)& @ispla! N lines efore matc,

    0? is t,e option +,ic, prints t,e specified N lines efore t,e matc,)

  • 5/28/2018 dba important linux commands

    24/97

    S!ntax:

    grep 0? Nb string 5ILEN"ME

    >,en !ou ,ad option to s,o+ t,e N lines after matc,' !ou ,a-e t,e 0? option for t,e opposite)

    2 grep 0? & single >$@ demotext

    Example to s,o+ t,e difference et+een >$@ and +ord

    ] %=&)%3;)%)% 0 single >$@

    3) @ispla! N lines around matc,

    0C is t,e option +,ic, prints t,e specified N lines efore t,e matc,) In some occasion !ou mig,t

    +ant t,e matc, to e appeared +it, t,e lines from ot, t,e side) .,is options s,o+s N lines inot, t,e sideefore after1 of matc,)

    2 grep 0C & Example demotext

    +ord 0 +ord consists of a seDuence of letters' digits and underscores)

    Example to s,o+ t,e difference et+een >$@ and +ord

    ] %=&)%3;)%)% 0 single >$@

    7) Jig,lig,ting t,e searc, using W$EPP.INS

    "s grep prints out lines from t,e file ! t,e pattern / string !ou ,ad gi-en' if !ou +anted it to,ig,lig,t +,ic, part matc,es t,e line' t,en !ou need to follo+ t,e follo+ing +a!)

    >,en !ou do t,e follo+ing export !ou +ill get t,e ,ig,lig,ting of t,e matc,ed searc,es) In t,efollo+ing example' it +ill ,ig,lig,t all t,e t,is +,en !ou set t,e W$EPP.INS en-ironment-ariale as s,o+n elo+)

    2 export W$EPP.INS^00colorauto^ W$EPCL$^%((Y;^

    2 grep t,is demofile

    t,is line is t,e %st lo+er case line in t,is file)

    .+o lines ao-e t,is line is empt!)

  • 5/28/2018 dba important linux commands

    25/97

    "nd t,is is t,e last line)

    ;) Searc,ing in all files recursi-el! using grep 0r

    >,en !ou +ant to searc, in all t,e files under t,e current director! and its su director!) 0roption is t,e one +,ic, !ou need to use) .,e follo+ing example +ill loo* for t,e string Frames,H

    in all t,e files in t,e current director! and all itBs sudirector!)

    2 grep 0r rames, ]

    =) In-ert matc, using grep 0-

    ou ,ad different options to s,o+ t,e lines matc,ed' to s,o+ t,e lines efore matc,' and tos,o+ t,e lines after matc,' and to ,ig,lig,t matc,) So definitel! ouBd also +ant t,e option 0- todo in-ert matc,)

    >,en !ou +ant to displa! t,e lines +,ic, does not matc,es t,e gi-en string/pattern' use t,e

    option 0- as s,o+n elo+) .,is example +ill displa! all t,e lines t,at did not matc, t,e +ordFgoH)

    2 grep 0- go demotext

    8) im >ord Na-igation

    ou ma! +ant to do se-eral na-igation in relation to t,e +ords' suc, as:

    >$@ 0 >$@ consists of a seDuence of non0lan* c,aracters' separated +it, +,ite space)

    +ord 0 +ord consists of a seDuence of letters' digits and underscores)

    Example to s,o+ t,e difference et+een >$@ and +ord

    ] %=&)%3;)%)% 0 single >$@

    ] %=&)%3;)%)% 0 se-en +ords)

    %() displa! t,e lines +,ic, does not matc,es all t,e gi-en pattern)

    S!ntax:

    grep 0- 0e pattern 0e pattern

    2 cat test0file)txt

  • 5/28/2018 dba important linux commands

    26/97

    a

    c

    d

    2 grep 0- 0e a 0e 0e c test0file)txt

    d

    %%) Counting t,e numer of matc,es using grep 0c

    >,en !ou +ant to count t,at ,o+ man! lines matc,es t,e gi-en pattern/string' t,en use t,eoption 0c)

    S!ntax:

    grep 0c pattern filename

    2 grep 0c go demotext

    3

    >,en !ou +ant do find out ,o+ man! lines matc,es t,e pattern

    2 grep 0c t,is demofile

    >,en !ou +ant do find out ,o+ man! lines t,at does not matc, t,e pattern

    2 grep 0- 0c t,is demofile

    8

    %&) @ispla! onl! t,e file names +,ic, matc,es t,e gi-en pattern using grep 0l

    If !ou +ant t,e grep to s,o+ out onl! t,e file names +,ic, matc,ed t,e gi-en pattern' use t,e 0llo+er0case L1 option)

    >,en !ou gi-e multiple files to t,e grep as input' it displa!s t,e names of file +,ic, contains t,etext t,at matc,es t,e pattern' +ill e -er! ,and! +,en !ou tr! to find some notes in !our +,oledirector! structure)

    2 grep 0l t,is demo]

  • 5/28/2018 dba important linux commands

    27/97

    demofile

    demofile%

    %) S,o+ onl! t,e matc,ed string

    ?! default grep +ill s,o+ t,e line +,ic, matc,es t,e gi-en pattern/string' ut if !ou +ant t,egrep to s,o+ out onl! t,e matc,ed string of t,e pattern t,en use t,e 0o option)

    It mig,t not e t,at muc, useful +,en !ou gi-e t,e string straig,t for+ard) ?ut it ecomes -er!useful +,en !ou gi-e a regex pattern and tr!ing to see +,at it matc,es as

    2 grep 0o is)]line demofile

    is line is t,e %st lo+er case line

    is line

    is is t,e last line

    %8) S,o+ t,e position of matc, in t,e line

    >,en !ou +ant grep to s,o+ t,e position +,ere it matc,es t,e pattern in t,e file' use t,efollo+ing options as

    S!ntax:

    grep 0o 0 pattern file

    2 cat temp0file)txt

    %&84

    %&84

    2 grep 0o 0 temp0file)txt

    &:

    ;:

    Note: .,e output of t,e grep command ao-e is not t,e position in t,e line' it is !te offset of t,e+,ole file)

    %4) S,o+ line numer +,ile displa!ing t,e output using grep 0n

    .o s,o+ t,e line numer of file +it, t,e line matc,ed) It does %0ased line numering for eac,file) Use 0n option to utiliVe t,is feature)

  • 5/28/2018 dba important linux commands

    28/97

    2 grep 0n go demotext

    4: ] e 0 go to t,e end of t,e current +ord)

    3: ] E 0 go to t,e end of t,e current >$@)

    7: ] 0 go to t,e pre-ious efore1 +ord)

    ;: ] ? 0 go to t,e pre-ious efore1 >$@)

    =: ] + 0 go to t,e next +ord)

    %(: ] > 0 go to t,e next >$@)

    P.INS

    ption

    @escription

    0 @ispla! t,e loc* numer at t,e eginning of eac, line)

    0c @ispla! t,e numer of matc,ed lines)

    0, @ispla! t,e matc,ed lines' ut do not displa! t,efilenames)

    0i Ignore case sensiti-it!)

    0l @ispla! t,e filenames' ut do not displa! t,e matc,edlines)

    0n @ispla! t,e matc,ed lines and t,eir line numers)

    0s Silent mode)

    0- @ispla! all lines t,at do N. matc,)

    0+ Matc, +,ole +ord)

    ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ ))

    .P Command Examples in Linux

  • 5/28/2018 dba important linux commands

    29/97

    ?! $a-i Sai-eUnder: CentS' 5edora' Linux Commands'Linux @istros' $edJatn: Marc, 8'&(%

    @o+nload our 5ree e?oo*s N> 0 %( 5ree Linux e?oo*s for "dministrators

    .,is is t,e part of our on0going series of commands in Linux) >e ,a-e co-ered asic ls

    command and cat command) In t,is article' +e are tr!ing to explore top command +,ic, is oneof t,e most freDuentl! used commands in our dail! s!stem administrati-e os) topcommanddispla!s processor acti-it! of !our Linux ox and also displa!s tas*s managed ! *ernel in real0time) ItBll s,o+ processor and memor! are eing used and ot,er information li*e runningprocesses) .,is ma! ,elp !ou to ta*e correct action) top command found in UNIX0li*e operatings!stems)

    Linux .op Command Examples

    ou mig,t also e interested in follo+ing tutorials :

    Jtop Linux Process Monitoring1 tool for $JEL' CentS 5edora

    Iotop Monitor Linux @is* I/1 in $JEL' CentS and 5edora

    %) @ispla! of .op Command

    In t,is example' it +ill s,o+ information li*e tas*s' memor!' cpu and s+ap) Press ADA to Duit+indo+)

    top

    http://www.tecmint.com/author/admin/http://www.tecmint.com/category/linux-distros/centos/http://www.tecmint.com/category/linux-distros/fedora/http://www.tecmint.com/category/linux-commands/http://www.tecmint.com/category/linux-distros/http://www.tecmint.com/category/linux-distros/http://www.tecmint.com/category/linux-distros/redhat/http://www.tecmint.com/10-useful-free-linux-ebooks-for-newbies-and-administrators/http://www.tecmint.com/15-basic-ls-command-examples-in-linux/http://www.tecmint.com/15-basic-ls-command-examples-in-linux/http://www.tecmint.com/13-basic-cat-command-examples-in-linux/http://www.tecmint.com/install-htop-linux-process-monitoring-for-rhel-centos-fedora/http://www.tecmint.com/install-iotop-monitor-linux-disk-io-in-rhel-centos-and-fedora/http://www.tecmint.com/wp-content/uploads/2012/08/Linux-Top-Commands.pnghttp://www.tecmint.com/author/admin/http://www.tecmint.com/category/linux-distros/centos/http://www.tecmint.com/category/linux-distros/fedora/http://www.tecmint.com/category/linux-commands/http://www.tecmint.com/category/linux-distros/http://www.tecmint.com/category/linux-distros/redhat/http://www.tecmint.com/10-useful-free-linux-ebooks-for-newbies-and-administrators/http://www.tecmint.com/15-basic-ls-command-examples-in-linux/http://www.tecmint.com/15-basic-ls-command-examples-in-linux/http://www.tecmint.com/13-basic-cat-command-examples-in-linux/http://www.tecmint.com/install-htop-linux-process-monitoring-for-rhel-centos-fedora/http://www.tecmint.com/install-iotop-monitor-linux-disk-io-in-rhel-centos-and-fedora/
  • 5/28/2018 dba important linux commands

    30/97

    Linux .op Command

    &) Sorting +it, 0 Uppercase Letter AB1)Press S,ift\1 to Sort field -ia field letter' for example press AaA letter to sort process +it, PI@Process I@1)

    http://www.tecmint.com/wp-content/uploads/2012/08/Top-Command.jpg
  • 5/28/2018 dba important linux commands

    31/97

    Sorting Process I@Bs +it, .op

    .!pe an! *e! to return to main top +indo+ +it, sorted PI@ order as s,o+n in elo+ screen)Press ADA to Duit exit t,e +indo+)

    http://www.tecmint.com/wp-content/uploads/2012/08/Top-Sort.jpg
  • 5/28/2018 dba important linux commands

    32/97

    Sorting Process I@Bs

    ) @ispla! Specific User ProcessUse top command +it, AuA option +ill displa! specific User process details)

    top 0u tecmint

    http://www.tecmint.com/wp-content/uploads/2012/08/Sort-with-PID.jpg
  • 5/28/2018 dba important linux commands

    33/97

    .op +it, Specific User Processes

    8) Jig,lig,t $unning Process in .opPress AVA option in running top command +ill displa! running process in color +,ic, ma! ,elp!ou to identified running process easil!)

    http://www.tecmint.com/wp-content/uploads/2012/08/Top-User-Process.jpg
  • 5/28/2018 dba important linux commands

    34/97

    .op Process +it, Colorful

    4) S,o+s "solute Pat, of ProcessesPress AcA option in running top command' it +ill displa! asolute pat, of running process)

    http://www.tecmint.com/wp-content/uploads/2012/08/Top-Colorful.png
  • 5/28/2018 dba important linux commands

    35/97

    .op +it, Specific Process Pat,

    3) C,ange @ela! or Set AScreen $efres, Inter-alB in .op

    ?! default screen refres, inter-al is )( seconds' same can e c,ange pressing AdA option inrunning top command and c,ange it as desired as s,o+n elo+)

    http://www.tecmint.com/wp-content/uploads/2012/08/Top-command-with-Path.jpg
  • 5/28/2018 dba important linux commands

    36/97

    .op Set $efres, .ime

    7) #ill running process +it, argument A*B

    ou can *ill a process after finding PI@ of process ! pressing A*A option in running topcommand +it,out exiting from top +indo+ as s,o+n elo+)

    http://www.tecmint.com/wp-content/uploads/2012/08/Top-Set-Refresh-Time.jpg
  • 5/28/2018 dba important linux commands

    37/97

    .op #ill Process I@

    ;) Sort ! CPU Utilisation

    Press S,ift\P1 to sort processes as per CPU utiliVation) See screens,ot elo+)

    http://www.tecmint.com/wp-content/uploads/2012/08/Top-Kill-Process.jpg
  • 5/28/2018 dba important linux commands

    38/97

    .op Jig, CPU UtiliVation

    =) $enice a Process

    ou can use ArA option to c,ange t,e priorit! of t,e process also called $enice)

    http://www.tecmint.com/wp-content/uploads/2012/08/Top-With-CPU-Utilization.jpg
  • 5/28/2018 dba important linux commands

    39/97

    .op $enice Process

    %() Sa-e .op Command $esults

    Press S,ift\>1 to sa-e t,e running top command results under /root/)toprc)

    http://www.tecmint.com/wp-content/uploads/2012/08/Top-Renice-Process.jpg
  • 5/28/2018 dba important linux commands

    40/97

    .op Command Sa-e $esults

    %%) Wetting .op Command Jelp

    Press A,A option to otain t,e top command ,elp)

    http://www.tecmint.com/wp-content/uploads/2012/08/Top-Save-Results.jpg
  • 5/28/2018 dba important linux commands

    41/97

    .op Command Jelp

    %&) Exit .op Command "fter Specific repetition

    .op output *eep refres,ing until !ou press ADA) >it, elo+ command top command +illautomaticall! exit after %( numer of repetition)

    top 0n %(

    .,ere are numer of arguments to *no+ more aout top command !ou ma! refer man pageof top command) Please s,are it if !ou find t,is article useful t,roug, our comment ox elo+)

    P.INS

    pid)))

    Specif! t,e list of processes t,at *ill s,ould signal) Eac, pid can e one of fi-e t,ings:

    n

    http://www.tecmint.com/wp-content/uploads/2012/08/Top-command-help.jpg
  • 5/28/2018 dba important linux commands

    42/97

    +,ere n is larger t,an () .,e process +it, pid n +ill e signaled)

    (

    "ll processes in t,e current process group are signaled)

    0%

    "ll processes +it, pid larger t,an % +ill e signaled)

    0n

    +,ere n is larger t,an %) "ll processes in process group n are signaled) >,en an argument oft,e form 0n^ is gi-en' and it is meant to denote a process group' eit,er t,e signal must especified first' or t,e argument must e preceded ! a 00^ option' ot,er+ise it +ill e ta*en ast,e signal to send)

    commandname

    "ll processes in-o*ed using t,at name +ill e signaled)

    0s signal

    Specif! t,e signal to send) .,e signal ma! e gi-en as a signal name or numer)

    0l

    Print a list of signal names) .,ese are found in /usr/include/linux/signal),

    0a

    @o not restrict t,e commandname0to0pid con-ersion to processes +it, t,e same uid as t,epresent process)

    0p

    Specif! t,at *ill s,ould onl! print t,e process id pid1 of t,e named processes' and not send an!signals)

    7 Linux fdis* Command Examples to Manage Jard @is* Partition

    ! ?"L"#$ISJN"N M"$I"PP"N on SEP.EM?E$ %8' &(%(

  • 5/28/2018 dba important linux commands

    43/97

    n Linux distriutions' fdis* is t,e est tool tomanage dis* partitions) fdis* is a text ased utilit!)

    Using fdis* !ou can create a ne+ partition' delete an existing partition' or c,ange existingpartition)

    Using fids* !ou are allo+ed to create a maximum of four primar! partition' and an! numer oflogical partitions' ased on t,e siVe of t,e dis*)

    #eep in mind t,at an! single partition reDuires a minimum siVe of 8(M?)

    In t,is article' let us re-ie+ ,o+ to use fdis* command using practical examples)

    >arning: @onBt delete' modif!' or add partition' if !ou donBt *no+ +,at !ou are doing) ou +illlose !our data

    %) ie+ "ll Existing @is* Partitions Using fdis* 0l?efore !ou create a ne+ partition' or modif! an existing partition' !ou mig,t +ant to -ie+ alla-ailale partition in t,e s!stem)

    Use fdis* 0l to -ie+ all a-ailale partitions as s,o+n elo+)

    fdis* 0l

  • 5/28/2018 dba important linux commands

    44/97

    @is* /de-/sda: ;()( W?' ;((&33%;43 !tes

    &44 ,eads' 3 sectors/trac*' =7&= c!linders

    Units c!linders of %3(34 ] 4%& ;&&4&;( !tes

    @is* identifier: (xf3edf3ed

    @e-ice ?oot Start End ?loc*s Id S!stem

    /de-/sda% % %=4= %47433 c >=4 5".& L?"1

    /de-/sda& %=3( 4&; &37(((( f >=4 Ext^d L?"1

    /de-/sda 4&;8 34&; %((((83&\ 7 JP5S/N.5S/de-/sda8 34&= =7&= &47%&(&\ c >=4 5".& L?"1

    /de-/sda4 ] %=3( &33% 43;74& ; Linux

    /de-/sda3 &33& &=(8 %=4%;33 ; Linux

    /de-/sda7 &=(4 %87 %=4%;33 ; Linux

    /de-/sda; %8; &38 ==77% ;& Linux s+ap / Solaris

    /de-/sda= &34 4&; %3&%74;3 >=4 5".&

    .,e ao-e +ill list partitions from all t,e connected ,ard dis*s) >,en !ou ,a-e more t,an onedis* on t,e s!stem' t,e partitions list are ordered ! t,e de-iceBs /de- name) 5or example'/de-/sda' /de-/sd' /de-/sdc and so on)

    &) ie+ Partitions of a Specific Jard @is* using fdis* 0l /de-/sd_a`

    .o -ie+ all partitions of t,e /de-/sda ,ard dis*' do t,e follo+ing)

    fdis* 0l /de-/sda

    ie+ all fdis* Commands Using fdis* Command m

    Use fdis* command m' to -ie+ all a-ailale fdis* commands as s,o+n elo+)

    fdis* /de-/sda

    .,e numer of c!linders for t,is dis* is set to =7&=)

  • 5/28/2018 dba important linux commands

    45/97

    .,ere is not,ing +rong +it, t,at' ut t,is is larger t,an %(&8'

    and could in certain setups cause prolems +it,:

    %1 soft+are t,at runs at oot time e)g)' old -ersions of LIL1

    &1 ooting and partitioning soft+are from ot,er Ss

    e)g)' @S 5@IS#' S/& 5@IS#1

    Command m for ,elp1: m

    Command action

    a toggle a ootale flag

    edit sd dis*lael c toggle t,e dos compatiilit! flag

    d delete a partition

    l list *no+n partition t!pes

    m print t,is menu

    n add a ne+ partition

    o create a ne+ empt! @S partition tale

    p print t,e partition tale

    D Duit +it,out sa-ing c,anges

    s create a ne+ empt! Sun dis*lael

    t c,ange a partition^s s!stem id

    u c,ange displa!/entr! units

    - -erif! t,e partition tale

    + +rite tale to dis* and exit

    x extra functionalit! experts onl!1

    ) @elete a Jard @is* Partition Using fdis* Command d

  • 5/28/2018 dba important linux commands

    46/97

    Let us assume t,at !ou li*e to comine se-eral partitions for example' /de-/sda3' /de-/sda7and /de-/sda;1 into a single dis* partition) .o do t,is' !ou s,ould first delete all t,ose indi-idualpartitions' as s,o+n elo+)

    fdis* /de-/sda

    .,e numer of c!linders for t,is dis* is set to =7&=)

    .,ere is not,ing +rong +it, t,at' ut t,is is larger t,an %(&8'

    and could in certain setups cause prolems +it,:

    %1 soft+are t,at runs at oot time e)g)' old -ersions of LIL1

    &1 ooting and partitioning soft+are from ot,er Ss

    e)g)' @S 5@IS#' S/& 5@IS#1

    Command m for ,elp1: p

    @is* /de-/sda: ;()( W?' ;((&33%;43 !tes

    &44 ,eads' 3 sectors/trac*' =7&= c!linders

    Units c!linders of %3(34 ] 4%& ;&&4&;( !tes

    @is* identifier: (xf3edf3ed

    @e-ice ?oot Start End ?loc*s Id S!stem

    /de-/sda% % %=4= %47433 c >=4 5".& L?"1

    /de-/sda& %=3( 4&; &37(((( f >=4 Ext^d L?"1

    /de-/sda 4&;8 34&; %((((83&\ 7 JP5S/N.5S

    /de-/sda8 34&= =7&= &47%&(&\ c >=4 5".& L?"1

    /de-/sda4 ] %=3( &33% 43;74& ; Linux

    /de-/sda3 &33& &=(8 %=4%;33 ; Linux

    /de-/sda7 &=(4 %87 %=4%;33 ; Linux

  • 5/28/2018 dba important linux commands

    47/97

    /de-/sda; %8; &38 ==77% ;& Linux s+ap / Solaris

    /de-/sda= &34 4&; %3&%74;3 >=4 5".&

    Command m for ,elp1: d

    Partition numer %0=1: ;

    Command m for ,elp1: d

    Partition numer %0;1: 7

    Command m for ,elp1: dPartition numer %071: 3

    Command m for ,elp1: +

    .,e partition tale ,as een altered

    Calling ioctl1 to re0read partition tale)

    >"$NINW: $e0reading t,e partition tale failed +it, error %3: @e-ice or resource us!)

    .,e *ernel still uses t,e old tale) .,e ne+ tale +ill e used at

    t,e next reoot or after !ou run partproe;1 or *partx;1

    S!ncing dis*s)

    8) Create a Ne+ @is* Partition +it, Specific SiVe Using fdis* Command n

    nce !ouB-e deleted all t,e existing partitions' !ou can create a ne+ partition using all a-ailalespace as s,o+n elo+)

    fdis* /de-/sda

    .,e numer of c!linders for t,is dis* is set to =7&=)

  • 5/28/2018 dba important linux commands

    48/97

    .,ere is not,ing +rong +it, t,at' ut t,is is larger t,an %(&8'

    and could in certain setups cause prolems +it,:

    %1 soft+are t,at runs at oot time e)g)' old -ersions of LIL1

    &1 ooting and partitioning soft+are from ot,er Ss

    e)g)' @S 5@IS#' S/& 5@IS#1

    Command m for ,elp1: n

    5irst c!linder &33&04&;' default &33&1:

    Using default -alue &33&

    Last c!linder' \c!linders or \siVe_#'M'W` &33&0&38' default &381:Using default -alue &38

    In t,e ao-e example' fdis* n command is used to create ne+ partition +it, t,e specific siVe)>,ile creating a ne+ partition' it expects follo+ing t+o inputs)

    Starting c!linder numer of t,e partition to e create 5irst c!linder1)

    SiVe of t,e partition or1 t,e last c!linder numer Last c!linder' \c!linders or \siVe 1)

    Please *eep in mind t,at !ou s,ould issue t,e fdis* +rite command +1 after an! modifications)

    Command m for ,elp1: +

    .,e partition tale ,as een altered

    Calling ioctl1 to re0read partition tale)

    >"$NINW: $e0reading t,e partition tale failed +it, error %3: @e-ice or resource us!)

    .,e *ernel still uses t,e old tale) .,e ne+ tale +ill e used at

    t,e next reoot or after !ou run partproe;1 or *partx;1

    S!ncing dis*s)

    "fter t,e partition is created' format it using t,e m*fs commandas s,o+n elo+)

    m*fs)ext /de-/sda7

    http://linux.101hacks.com/sysadmin-tasks/format-a-partition-using-mke2fsk/http://linux.101hacks.com/sysadmin-tasks/format-a-partition-using-mke2fsk/
  • 5/28/2018 dba important linux commands

    49/97

    4) ie+ t,e SiVe of an existing Partition Using fdis* 0s

    "s s,o+n elo+' fdis* 0s displa!s t,e siVe of t,e partition in loc*s)

    fdis* 0s /de-/sda7

    8;8433

    .,e ao-e output corresponds to aout 8=((M?)

    3) .oggle t,e ?oot 5lag of a Partition Using fdis* Command a

    5dis* command displa!s t,e oot flag of eac, partition) >,en !ou +ant to disale or enale t,eoot flag on t,e corresponding partition' do t,e follo+ing)

    If !ou donBt *no+ +,! are !ou are doing t,is' !ouBll mess0up !our s!stem)

    fdis* /de-/sda

    .,e numer of c!linders for t,is dis* is set to =7&=)

    .,ere is not,ing +rong +it, t,at' ut t,is is larger t,an %(&8'

    and could in certain setups cause prolems +it,:

    %1 soft+are t,at runs at oot time e)g)' old -ersions of LIL1

    &1 ooting and partitioning soft+are from ot,er Ss

    e)g)' @S 5@IS#' S/& 5@IS#1

    Command m for ,elp1: p

    @is* /de-/sda: ;()( W?' ;((&33%;43 !tes

    &44 ,eads' 3 sectors/trac*' =7&= c!linders

    Units c!linders of %3(34 ] 4%& ;&&4&;( !tes

    @is* identifier: (xf3edf3ed

    @e-ice ?oot Start End ?loc*s Id S!stem

    /de-/sda% % %=4= %47433 c >=4 5".& L?"1

  • 5/28/2018 dba important linux commands

    50/97

    /de-/sda& %=3( 4&; &37(((( f >=4 Ext^d L?"1

    /de-/sda 4&;8 34&; %((((83&\ 7 JP5S/N.5S

    /de-/sda8 34&= =7&= &47%&(&\ c >=4 5".& L?"1

    /de-/sda4 ] %=3( &33% 43;74& ; Linux

    /de-/sda3 &34 4&; %3&%74;3 >=4 5".&

    /de-/sda7 &33& &38 8;8433 ; Linux

    Partition tale entries are not in dis* order

    Command m for ,elp1: aPartition numer %071: 4

    Command m for ,elp1: p

    @is* /de-/sda: ;()( W?' ;((&33%;43 !tes

    &44 ,eads' 3 sectors/trac*' =7&= c!linders

    Units c!linders of %3(34 ] 4%& ;&&4&;( !tes

    @is* identifier: (xf3edf3ed

    @e-ice ?oot Start End ?loc*s Id S!stem

    /de-/sda% % %=4= %47433 c >=4 5".& L?"1

    /de-/sda& %=3( 4&; &37(((( f >=4 Ext^d L?"1

    /de-/sda 4&;8 34&; %((((83&\ 7 JP5S/N.5S

    /de-/sda8 34&= =7&= &47%&(&\ c >=4 5".& L?"1

    /de-/sda4 %=3( &33% 43;74& ; Linux

    /de-/sda3 &34 4&; %3&%74;3 >=4 5".&

  • 5/28/2018 dba important linux commands

    51/97

    /de-/sda7 &33& &38 8;8433 ; Linux

    Partition tale entries are not in dis* order

    Command m for ,elp1:

    "s seen ao-e' t,e oot flag is disaled on t,e partition /de-/sda4)

    7) 5ix Partition .ale rder Using fdis* Expert Command f

    >,en !ou delete a logical partition' and recreate it again' !ou mig,t see t,e Fpartition out oforderH issue) i)e FPartition tale entries are not in dis* orderH error message)

    5or example' +,en !ou delete t,ree logical partitions sda3' sda7 and sda;1' and create a ne+

    partition' !ou mig,t expect t,e ne+ partition name to e sda3) ?ut' t,e s!stem mig,tB-e createdt,e ne+ partition as sda7) .,is is ecause' after t,e partitions are deleted' sda= partition ,aseen mo-ed as sda3 and t,e free space is mo-ed to t,e end)

    .o fix t,is partition order issue' and assign sda3 to t,e ne+l! created partition' execute t,eexpert command f as s,o+n elo+)

    2 fdis* /de-/sda

    .,e numer of c!linders for t,is dis* is set to =7&=)

    .,ere is not,ing +rong +it, t,at' ut t,is is larger t,an %(&8'

    and could in certain setups cause prolems +it,:

    %1 soft+are t,at runs at oot time e)g)' old -ersions of LIL1

    &1 ooting and partitioning soft+are from ot,er Ss

    e)g)' @S 5@IS#' S/& 5@IS#1

    Command m for ,elp1: p

    @is* /de-/sda: ;()( W?' ;((&33%;43 !tes

    &44 ,eads' 3 sectors/trac*' =7&= c!linders

  • 5/28/2018 dba important linux commands

    52/97

    Units c!linders of %3(34 ] 4%& ;&&4&;( !tes

    @is* identifier: (xf3edf3ed

    @e-ice ?oot Start End ?loc*s Id S!stem

    /de-/sda% % %=4= %47433 c >=4 5".& L?"1

    /de-/sda& %=3( 4&; &37(((( f >=4 Ext^d L?"1

    /de-/sda 4&;8 34&; %((((83&\ 7 JP5S/N.5S

    /de-/sda8 34&= =7&= &47%&(&\ c >=4 5".& L?"1

    /de-/sda4 ] %=3( &33% 43;74& ; Linux

    /de-/sda3 &34 4&; %3&%74;3 >=4 5".&/de-/sda7 &33& &38 8;8433 ; Linux

    Partition tale entries are not in dis* order

    Command m for ,elp1: x

    Expert command m for ,elp1: f

    @one)

    Expert command m for ,elp1: +

    .,e partition tale ,as een altered

    Calling ioctl1 to re0read partition tale)

    >"$NINW: $e0reading t,e partition tale failed +it, error %3: @e-ice or resource us!)

    .,e *ernel still uses t,e old tale) .,e ne+ tale +ill e used at

  • 5/28/2018 dba important linux commands

    53/97

    t,e next reoot or after !ou run partproe;1 or *partx;1

    S!ncing dis*s)

    nce t,e partition tale order is fixed' !ouBll not get t,e FPartition tale entries are not in dis*orderH error message an!more)

    fdis* 0l

    @is* /de-/sda: ;()( W?' ;((&33%;43 !tes

    &44 ,eads' 3 sectors/trac*' =7&= c!linders

    Units c!linders of %3(34 ] 4%& ;&&4&;( !tes

    @is* identifier: (xf3edf3ed

    @e-ice ?oot Start End ?loc*s Id S!stem

    /de-/sda% % %=4= %47433 c >=4 5".& L?"1

    /de-/sda& %=3( 4&; &37(((( f >=4 Ext^d L?"1

    /de-/sda 4&;8 34&; %((((83&\ 7 JP5S/N.5S

    /de-/sda8 34&= =7&= &47%&(&\ c >=4 5".& L?"1

    /de-/sda4 ] %=3( &33% 43;74& ; Linux

    /de-/sda3 &33& &38 8;8433 ; Linux

    /de-/sda7 &34 4&; %3&%74;3 >=4 5".&

    Jo+.o: Linux List @is* Partitions Command

    ! NIX C$"5. on 5E?$U"$ &8' &(%& 4 CMMEN.SL"S. UP@".E@ C.?E$ ' &(%&

    in LINUX

    http://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/faq/linux-list-disk-partitions-command/#commentshttp://www.cyberciti.biz/faq/linux-list-disk-partitions-command/#commentshttp://www.cyberciti.biz/faq/category/linux/http://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/faq/linux-list-disk-partitions-command/#commentshttp://www.cyberciti.biz/faq/category/linux/
  • 5/28/2018 dba important linux commands

    54/97

    Jo+ do I list all ,ard dis* partitions under Linux operating s!stems6

    Usuall!' !our ,ard dis* dri-e di-ided into one or more logical dis*s called partitions) .,is di-isionis descried in t,e partition tale found in sector ( of t,e ,ard dis*)

    .utorial details

    @ifficult!Eas! rss1

    $oot pri-ileges es

    $eDuirements None

    Estimated completiontime

    N/"

    .,e de-ice is usuall! /de-/sda' /de-/sd or so) " de-ice name refers to t,e entire dis* and t,ede-ice name +ill e as follo+s:

    /de-/,d] 0 I@E dis*s) /de-/,da +ill e first I@E ,ard dis*' /de-/,d +ill e second I@E ,ard dis*'and so on)

    /de-/sd] 0 SCSI or S"." dis*s) /de-/sda +ill e first S"."/SCSI ,ard dis*' /de-/sd +ill esecond S"."/SCSI ,ard dis*' and so on)

    >"$NINW .,ese examples ma! cras, !our computer if N. executed +it, proper care)?E EX.$EMEL C"$E5UL >I.J .JE 5LL>INW CMM"N@S) NE .PINW MIS."#E"N@ "LL U$ @"." IS LS.)

    lsl* Command

    .o list all loc* de-ices' run: lsl*Sample outputs:

    N"ME M":MIN $M SITE $ .PE MUN.PIN.

    http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/feed/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/feed/http://www.cyberciti.biz/faq/how-can-i-log-in-as-root/http://www.cyberciti.biz/faq/category/linux/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/feed/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/feed/http://www.cyberciti.biz/faq/how-can-i-log-in-as-root/
  • 5/28/2018 dba important linux commands

    55/97

    sda ;:( % 44;W ( dis*

    sda% ;:% % (7M ( part /oot

    sda& ;:& % &4(W ( part /+eroot

    sda ;: % 3W ( part 9S>"P

    sda8 ;:8 % %# ( part

    h sda4 ;:4 % (%)7W ( part /

    sr( %%:( % %(&8M ( rom

    List Partitions Under Linux

    pen a terminal +indo+ select "pplications b "ccessories b .erminal1) S+itc, to t,e root user! t!ping su 0 and entering t,e root pass+ord' +,en prompted) r use sudo command:

    2 su 0 fdis* 0l$2 sudo fdis* 0lSample outputs:

    @is* /de-/sda: &4%)% W?' &4%(4=488(38 !tes

    &44 ,eads' 3 sectors/trac*' (4&& c!linders

    Units c!linders of %3(34 ] 4%& ;&&4&;( !tes

    Sector siVe logical/p,!sical1: 4%& !tes / 4%& !tes

    I/ siVe minimum/optimal1: 4%& !tes / 4%& !tes

    @is* identifier: (x(((;fcd

    @e-ice ?oot Start End ?loc*s Id S!stem

    /de-/sda% ] % %8 %(888; ; Linux

    Partition % does not end on c!linder oundar!)

    /de-/sda& %8 %(3; %(8;473(( ; Linux

    /de-/sda %(3; %%=; %(8;473 ;& Linux s+ap / Solaris

    /de-/sda8 %%=; (4& %=%338; 4 Extended

    /de-/sda4 %%=; (4& %=%3&3&8 ; Linux

  • 5/28/2018 dba important linux commands

    56/97

    .,e 0l options s,o+s t,e partition tales for t,e specified de-ices and t,en exit) If no de-ices aregi-en' t,ose mentioned in /proc/partitions if t,at exists1 are used) ou can specif! de-ice nameas follo+s in t,is example list partitions for /de-/sda1: fdis* 0l

    sfdis* Command.,e sfdis* command act as a partition tale manipulator for Linux) ou can use t,is tool to listpartitions too: sfdis* 0l /de-/sda sfdis* 0lu /de-/sda sfdis* 0ls /de-/sdaSample outputs:

    7%33=73(

    @is* /de-/sda: ;=&& c!linders' &44 ,eads' 3 sectors/trac*

    Units c!linders of ;&&4&;( !tes' loc*s of %(&8 !tes' counting from (

    @e-ice ?oot Start End c!ls loc*s Id S!stem

    /de-/sda% ] (\ %(80 %(40 ;;343 ; Linux

    /de-/sda& %(8\ &40 %%0 %(8;473 ;& Linux s+ap / Solaris

    /de-/sda &4\ ;=&&0 ;3;;0 3=7;%4(8 ; Linux

    /de-/sda8 ( 0 ( ( ( Empt!

    >,ere'

    0l : List t,e partitions of a de-ice)

    0s : List t,e siVe of a partition)

    0u or 0uS or 0u? or 0uC or 0uM : "ccept or report in units of sectors loc*s' c!linders'mega!tes' respecpi-el!1) .,e default is c!linders' at least +,en t,e geometr! is *no+n)

    Listing Linux a Partition SiVe Larger .,an &.?

    .,e fdis* or sfdis* command+ill not list an! partition siVe larger t,an &.?) .o sol-e t,isprolem !ou need to use WNU parted command +it, WP. partitions) It supports Intel E5I/WP.partition tales) Partition .ale WP.1 is a standard for t,e la!out of t,e partition tale on ap,!sical ,ard dis*) It is a part of t,e Extensile 5irm+are Interface E5I1 standard proposed !Intel as a replacement for t,e outdated PC ?IS' one of t,e fe+ remaining relics of t,e originalI?M PC) E5I uses WP. +,ere ?IS uses a Master ?oot $ecord M?$1) In t,is example listpartitions on /de-/sd using t,e parted command:

    http://www.cyberciti.biz/tips/fdisk-unable-to-create-partition-greater-2tb.htmlhttp://www.cyberciti.biz/tips/fdisk-unable-to-create-partition-greater-2tb.htmlhttp://www.cyberciti.biz/tips/fdisk-unable-to-create-partition-greater-2tb.html
  • 5/28/2018 dba important linux commands

    57/97

    parted /de-/sdSample outputs:

    WNU Parted &)

    Using /de-/sd

    >elcome to WNU Parted .!pe ^,elp^ to -ie+ a list of commands)

    parted1

    Set unit t!pe to .? or W? ! t!ping ^unit .?^ or ^unit W?^ at t,e parted1 prompt:parted1 unit .?$parted1 unit W?.o list partitions t!pe print command at t,e parted1 prompt:parted1 print

    Sample outputs:

    Model: "." S.(((34%"S scsi1

    @is* /de-/sd: ((%W?

    Sector siVe logical/p,!sical1: 4%&?/4%&?

    Partition .ale: gpt

    Numer Start End SiVe 5ile s!stem Name 5lags

    % ()((W? ((%W? ((%W? ext8 primar!

    parted1

    .o exit from parted session t!pe ^Duit^ at t,e parted1 prompt:parted1 Duit

    Jo+ @o I List "ll Partitions La!out n "ll ?loc* @e-ices6

    Pass t,e 0l $ 00list option to t,e parted command to lists partition la!out on all loc* de-ices: parted 0lSample outputs:

  • 5/28/2018 dba important linux commands

    58/97

    5ig)(%: S,o+ Linux @is* Partitions >it, WNU parted Command

    lssci command

    Use t,e lsscsi command to s,o+ SCSI de-ices or ,osts1 and t,eir attriutes: lsscsiSample outputs:

    9(:(:(:( dis* "." .SJI?" M#4(3%WS M5(( /de-/sda

    9%:(:(:( cd/d-d M".SJI." ?@0$E U&&" %)%( /de-/sr(

    9&:(:(:( dis* "." S.=4((8&("SW (((8 /de-/sd

    Jo+.o: Use grep Command In Linux / UNIX Examples

    ! NIX C$"5. on "UWUS. &' &((7 &33 CMMEN.S L"S. UP@".E@ UL (' &(%

    in ?"SJ SJELL'LINUX' UNIX

    http://www.cyberciti.biz/faq/debian-ubuntu-linux-list-scsi-devices-hosts-attributes-lsscsi-command/http://www.cyberciti.biz/faq/debian-ubuntu-linux-list-scsi-devices-hosts-attributes-lsscsi-command/http://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#commentshttp://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#commentshttp://www.cyberciti.biz/faq/category/bash-shell/http://www.cyberciti.biz/faq/category/linux/http://www.cyberciti.biz/faq/category/linux/http://www.cyberciti.biz/faq/category/unix/http://www.cyberciti.biz/faq/category/unix/http://www.cyberciti.biz/faq/linux-list-disk-partitions-command/gnu-parted-lists-partitions/http://www.cyberciti.biz/faq/debian-ubuntu-linux-list-scsi-devices-hosts-attributes-lsscsi-command/http://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/#commentshttp://www.cyberciti.biz/faq/category/bash-shell/http://www.cyberciti.biz/faq/category/linux/http://www.cyberciti.biz/faq/category/unix/
  • 5/28/2018 dba important linux commands

    59/97

    Jo+ do I use grep command on Linux' "pple S X' and Unix0li*e operating s!stems6 Can !ougi-e me a simple examples of t,e grep command6

    .,e grep command is used to searc, text or searc,es t,e gi-en file for lines containing a matc,to t,e gi-en strings or +ords) ?! default' grep displa!s t,e matc,ing lines) Use grep to searc,

    for lines of text t,at matc, one or man! regular expressions' and outputs onl! t,e matc,inglines) grep is considered as one of t,e most useful commands on Unix and ot,er Linuxoperating s!stems)

    .utorial details

    @ifficult! Eas! rss 1

    $oot pri-ileges No

    $eDuirements grep

    Estimated completiontime

    %(minutes

    @id !ou *no+6

    .,e name' grep' deri-es from t,e command used to perform a similar operation' using t,eUnix/Linux text editor ed:g/re/p

    .,e grep command s!ntax

    .,e s!ntax is as follo+s:

    grep ^+ord^ filename

    grep ^+ord^ file% file& file

    grep ^string% string&^ filename

    cat ot,erfile G grep ^somet,ing^

    command G grep ^somet,ing^command option% G grep ^data^

    grep 00color ^data^ fileName

    Jo+ do I use grep command to searc, a file6

    http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/feed/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/feed/
  • 5/28/2018 dba important linux commands

    60/97

    Searc, /etc/pass+d file for oo user' enter:2 grep oo /etc/pass+dSample outputs:

    foo:x:%(((:%(((:foo''':/,ome/foo:/in/*s,

    ou can force grep to ignore +ord case i)e matc, oo' ?oo' ? and all ot,er comination +it,t,e 0i option:2 grep 0i oo /etc/pass+d

    Use grep recursi-el!

    ou can searc, recursi-el! i)e) read all files under eac, director! for a string %=&)%3;)%)42 grep 0r %=&)%3;)%)4 /etc/$2 grep 0$ %=&)%3;)%)4 /etc/Sample outputs:

    /etc/ppp/options: ms0+ins %=&)%3;)%)4(

    /etc/ppp/options: ms0+ins %=&)%3;)%)4%

    /etc/Net+or*Manager/s!stem0connections/>ired connection%:addresses%%=&)%3;)%)4Y&8Y%=&)%3;)%)&Y

    ou +ill see result for %=&)%3;)%)4 on a separate line preceded ! t,e name of t,e file suc,as /etc/ppp/options1 in +,ic, it +as found) .,e inclusion of t,e file names in t,e output data cane suppressed ! using t,e 0, option as follo+s:2 grep 0, 0$ %=&)%3;)%)4 /etc/$2 grep 0,$ %=&)%3;)%)4 /etc/Sample outputs:

    ms0+ins %=&)%3;)%)4(

    ms0+ins %=&)%3;)%)4%

    addresses%%=&)%3;)%)4Y&8Y%=&)%3;)%)&Y

    Use grep to searc, +ords onl!

    >,en !ou searc, for oo' grep +ill matc, foooo' oo%&' arfoo4 and more) ou can forcet,e grep command to select onl! t,ose lines containing matc,es t,at form +,ole +ords i)e)matc, onl! oo +ord:2 grep 0+ oo file

    Use grep to searc, & different +ords

  • 5/28/2018 dba important linux commands

    61/97

    Use t,e egrep command as follo+s:2 egrep 0+ ^+ord%G+ord&^ /pat,/to/file

    Count line +,en +ords ,as een matc,ed

    .,e grep can report t,e numer of times t,at t,e pattern ,as een matc,ed for eac, file using0

    c count1 option:2 grep 0c ^+ord^ /pat,/to/filePass t,e 0n option to precede eac, line of output +it, t,e numer of t,e line in t,e text file from+,ic, it +as otained:2 grep 0n ^root^ /etc/pass+dSample outputs:

    %:root:x:(:(:root:/root:/in/as,

    %(8&:rootdoor:x:(:(:rootdoor:/,ome/rootdoor:/in/cs,

    %=:initrootapp:x:(:(:initrootapp:/,ome/initroot:/in/*s,

    Wrep in-ert matc,

    ou can use 0- option to print in-erts t,e matc,Y t,at is' it matc,es onl! t,ose lines t,at do notcontain t,e gi-en +ord) 5or example print all line t,at do not contain t,e +ord ar:2 grep 0- ar /pat,/to/file

    UNIX / Linux pipes and grep command

    grep command often used +it, s,ell pipes) In t,is example' s,o+ t,e name of t,e ,ard dis*de-ices:

    dmesg G egrep ^sG,1d9a0V^@ispla! cpu model name: cat /proc/cpuinfo G grep 0i ^Model^Jo+e-er' ao-e command can e also used as follo+s +it,out s,ell pipe: grep 0i ^Model^ /proc/cpuinfoSample outputs:

    model : (

    model name : Intel$1 Core.M1 i7 CPU ;&( < %)7WJV

    model : (model name : Intel$1 Core.M1 i7 CPU ;&( < %)7WJV

    Jo+ do I list ust t,e names of matc,ing files6

    Use t,e 0l option to list file name +,ose contents mention main1:2 grep 0l ^main^ ])c5inall!' !ou can force grep to displa! output in colors' enter:

    http://bash.cyberciti.biz/guide/Pipeshttp://bash.cyberciti.biz/guide/Pipeshttp://bash.cyberciti.biz/guide/Pipes
  • 5/28/2018 dba important linux commands

    62/97

    2 grep 00color -i-e* /etc/pass+dSample outputs:

    %( Useful du @is* Usage1 Commands to 5ind @is* Usage of 5iles and @irectories

    ?! $a-i Sai-eUnder: CentS' 5edora' Linux Commands'$edJatn: anuar! &%' &(%

    @o+nload our 5ree e?oo*s N> 0 %( 5ree Linux e?oo*s for "dministrators.,e Linux FduH @is* Usage1 is a standard Unix/Linux command' used to c,ec* t,e informationof dis* usage of files and directories on a mac,ine) .,e du command ,as man! parameteroptions t,at can e used to get t,e results in man! formats) .,e du command also displa!s t,efiles and director! siVes in a recursi-el! manner)

    C,ec* @is* Usage of 5iles and 5olders In Linux

    .,is article explains %( useful FduH commands +it, t,eir examples' t,at mig,t ,elps !ou to findout t,e siVes of files and directories in Linux) .,e information pro-ided in t,is article are ta*enfrom t,e man pages of du command)

    $ead "lso:

    %& FdfH Command to C,ec* Linux S!stem @is* Space

    http://www.tecmint.com/author/admin/http://www.tecmint.com/category/linux-distros/centos/http://www.tecmint.com/category/linux-distros/fedora/http://www.tecmint.com/category/linux-commands/http://www.tecmint.com/category/linux-distros/redhat/http://www.tecmint.com/category/linux-distros/redhat/http://www.tecmint.com/10-useful-free-linux-ebooks-for-newbies-and-administrators/http://www.tecmint.com/how-to-check-disk-space-in-linux/http://www.cyberciti.biz/faq/howto-use-grep-command-in-linux-unix/grep_command_examples/http://www.tecmint.com/author/admin/http://www.tecmint.com/category/linux-distros/centos/http://www.tecmint.com/category/linux-distros/fedora/http://www.tecmint.com/category/linux-commands/http://www.tecmint.com/category/linux-distros/redhat/http://www.tecmint.com/10-useful-free-linux-ebooks-for-newbies-and-administrators/http://www.tecmint.com/how-to-check-disk-space-in-linux/
  • 5/28/2018 dba important linux commands

    63/97

    %) .o find out t,e dis* usage summar! of a /,ome/tecmint director! tree and eac, of its sudirectories) Enter t,e command as:

    9root

  • 5/28/2018 dba important linux commands

    64/97

    378M /,ome/tecmint

    8) Using F0aH flag +it, FduH command displa!s t,e dis* usage of all t,e files and directories)

    9root

  • 5/28/2018 dba important linux commands

    65/97

    8)(# /,ome/tecmint/)moVilla/extensions

    % /,ome/tecmint/)moVilla

    8)(# /,ome/tecmint/)as,rc

    37M /,ome/tecmint/Uuntu0%&)%(/uuntu0%&)%(0ser-er0i;3)iso

    37M /,ome/tecmint/Uuntu0%&)%(

    378M /,ome/tecmint

    3) 5ind out t,e dis* usage of a director! tree +it, its sutress in #ilo!te lco*s) Use t,e F0*Hdispla!s siVe in %(&8 !tes units1)

    9root

  • 5/28/2018 dba important linux commands

    66/97

    ;) .,e F0cH flag pro-ides a grand total usage dis* space at t,e last line) If !our director!ta*en378M? space' t,en t,e last last t+o line of t,e output +ould e)

    9root

  • 5/28/2018 dba important linux commands

    67/97

    8)(# /,ome/tecmint/)as,rc

    &8# /,ome/tecmint/P,pfiles0org)tar)V&

    8)(# /,ome/tecmint/geoipupdate)s,

    8)(# /,ome/tecmint/)Vs,rc

    %&(# /,ome/tecmint/goaccess0()8)&)tar)gV)%

    37M /,ome/tecmint/Uuntu0%&)%(/uuntu0%&)%(0ser-er0i;3)iso

    37M /,ome/tecmint/Uuntu0%&)%(

    378M /,ome/tecmint

    %() @ispla! t,e dis* usage ased on modification of time' use t,e flag FtimeH as s,o+n elo+)

    9root

  • 5/28/2018 dba important linux commands

    68/97

    8)(# &(%&0%(0%& &&:& /,ome/tecmint/)Vs,rc

    %&(# &(%0(%0%= %;:& /,ome/tecmint/goaccess0()8)&)tar)gV)%

    37M &(%0(%0%= %;:4% /,ome/tecmint/Uuntu0%&)%(/uuntu0%&)%(0ser-er0i;3)iso

    37M &(%0(%0%= %;:4% /,ome/tecmint/Uuntu0%&)%(

    378M &(%0(%0%= %;:4& /,ome/tecmint

    %& Useful FdfH Commands to C,ec* @is* Space in Linux

    ?! $a-i Sai-eUnder: Clear S' 5edora' Linux Commands'$edJatn: anuar! %4' &(%

    @o+nload our 5ree e?oo*s N> 0 %( 5ree Linux e?oo*s for "dministrators

    n t,e internet !ou +ill find plent! of tools for c,ec*ing dis* space utiliVation in Linux) Jo+e-er'Linux ,as a strong uilt in utilit! called AdfA) .,e AdfA command stand for Fdis* files!stemF' it is

    used to get full summar! of a-ailale and used dis* space usage of file s!stem on Linux s!stem)

    Using A0,A parameter +it, df 0,1 +ill s,o+s t,e file s!stem dis* space statistics in F,umanreadaleH format' means it gi-es t,e details in !tes' mega !tes and giga!te)

    Useful df Command Examples

    .,is article explain a +a! to get t,e full information of Linux dis* space usage +it, t,e ,elp ofAdfA command +it, t,eir practical examples) So' !ou could etter understand t,e usage of df

    command in Linux)

    %) C,ec* 5ile S!stem @is* Space Usage

    .,e FdfH command displa!s t,e information of de-ice name' total loc*s' total dis* space' useddis* space' a-ailale dis* space and mount points on a file s!stem)

    9root

  • 5/28/2018 dba important linux commands

    69/97

    5iles!stem %#0loc*s Used "-ailale UseQ Mounted on

    /de-/cciss/c(d(p& 7;3%%=& &%;4;8( 4%%(4;; &Q /

    /de-/cciss/c(d(p4 &87=7;( &&&78& %&8=7& =4Q /,ome

    /de-/cciss/c(d(p &=744;; &44(7=& &7%=;8 =%Q /data

    /de-/cciss/c(d(p% &=443% &%4% &4;77( ;Q /oot

    tmpfs &47873 ( &47873 (Q /de-/s,m

    &) @ispla! Information of all 5ile S!stem @is* Space Usage

    .,e same as ao-e' ut it also displa!s information of dumm! file s!stems along +it, all t,e files!stem dis* usage and t,eir memor! utiliVation)

    9root

  • 5/28/2018 dba important linux commands

    70/97

    .,e df command pro-ides an option to displa! siVes in Juman $eadale formats ! using A0,Bprints t,e results in ,uman readale format e)g)' %# &M W11)

    9root

  • 5/28/2018 dba important linux commands

    71/97

    3) @ispla! Information of 5ile S!stem in M?

    .o displa! information of all file s!stem usage in M? Mega ?!te1 use t,e option as A0mA)

    9root

  • 5/28/2018 dba important linux commands

    72/97

    /de-/cciss/c(d(p4 38(7%& 7=;3% 43(4(== %Q /,ome

    /de-/cciss/c(d(p 73;488( %;;&8% 3&=7%== %=Q /data

    /de-/cciss/c(d(p% 73(8 8( 73&38 %Q /oot

    tmpfs 383= % 383; %Q /de-/s,m

    =) @ispla! 5ile S!stem .!pe

    If !ou notice all t,e ao-e commands output' !ou +ill see t,ere is no file s!stem t!pe mentionedin t,e results) .o c,ec* t,e file s!stem t!pe of !our s!stem use t,e option A.A) It +ill displa! files!stem t!pe along +it, ot,er information)

    9root

  • 5/28/2018 dba important linux commands

    73/97

    If !ou +ant to displa! file s!stem t!pe t,at doesnBt elongs to ext t!pe use t,e option as A0xA)5or example' t,e follo+ing command +ill onl! displa! ot,er file s!stems t!pes ot,er t,anext)

    9root

  • 5/28/2018 dba important linux commands

    74/97

    0x' 00exclude0t!pe.PE limit listing to file s!stems not of t!pe .PE

    0- ignored1

    00,elp displa! t,is ,elp and exit

    00-ersion output -ersion information and exit

    SITE ma! e or ma! e an integer optionall! follo+ed !1 one of follo+ing:

    *? %(((' # %(&8' M? %(((]%(((' M %(&8]%(&8' and so on for W' .' P' E' T' )

    $eport ugs to ug0coreutils

  • 5/28/2018 dba important linux commands

    75/97

    bsed ^s/unix/linux/^ file)txt

    linux is great os) unix is opensource) unix is free os)

    learn operating s!stem)

    linuxlinux +,ic, one !ou c,oose)

    Jere t,e s specifies t,e sustitution operation) .,e / are delimiters) .,e unix is t,e searc,pattern and t,e linux is t,e replacement string)

    ?! default' t,e sed command replaces t,e first occurrence of t,e pattern in eac, line and it+on^t replace t,e second' t,ird)))occurrence in t,e line)

    &) $eplacing t,e nt, occurrence of a pattern in a line)

    Use t,e /%' /& etc flags to replace t,e first' second occurrence of a pattern in a line) .,e elo+command replaces t,e second occurrence of t,e +ord unix +it, linux in a line)

    bsed ^s/unix/linux/&^ file)txt

    unix is great os) linux is opensource) unix is free os)

    learn operating s!stem)

    unixlinux +,ic, one !ou c,oose)

    ) $eplacing all t,e occurrence of t,e pattern in a line)

    .,e sustitute flag /g gloal replacement1 specifies t,e sed command to replace all t,eoccurrences of t,e string in t,e line)

    bsed ^s/unix/linux/g^ file)txt

    linux is great os) linux is opensource) linux is free os)

    learn operating s!stem)

    linuxlinux +,ic, one !ou c,oose)

    8) $eplacing from nt, occurrence to all occurrences in a line)

  • 5/28/2018 dba important linux commands

    76/97

    Use t,e comination of /%' /& etc and /g to replace all t,e patterns from t,e nt, occurrence of apattern in a line) .,e follo+ing sed command replaces t,e t,ird' fourt,' fift,))) unix +ord +it,linux +ord in a line)

    bsed ^s/unix/linux/g^ file)txt

    unix is great os) unix is opensource) linux is free os)

    learn operating s!stem)

    unixlinux +,ic, one !ou c,oose)

    4) C,anging t,e slas, /1 delimiter

    ou can use an! delimiter ot,er t,an t,e slas,) "s an example if !ou +ant to c,ange t,e +eurl to anot,er url as

    bsed ^s/,ttp:K/K//+++/^ file)txt

    In t,is case t,e url consists t,e delimiter c,aracter +,ic, +e used) In t,at case !ou ,a-e toescape t,e slas, +it, ac*slas, c,aracter' ot,er+ise t,e sustitution +on^t +or*)

    Using too man! ac*slas,es ma*es t,e sed command loo* a+*+ard) In t,is case +e canc,ange t,e delimiter to anot,er c,aracter as s,o+n in t,e elo+ example)

    bsed ^s,ttp://+++^ file)txt

    bsed ^sG,ttp://G+++G^ file)txt

    3) Using as t,e matc,ed string

    .,ere mig,t e cases +,ere !ou +ant to searc, for t,e pattern and replace t,at pattern !adding some extra c,aracters to it) In suc, cases comes in ,and!) .,e represents t,ematc,ed string)

    bsed ^s/unix/_`/^ file)txt

  • 5/28/2018 dba important linux commands

    77/97

    _unix` is great os) unix is opensource) unix is free os)

    learn operating s!stem)

    _unix`linux +,ic, one !ou c,oose)

    bsed ^s/unix/_`/^ file)txt

    _unixunix` is great os) unix is opensource) unix is free os)

    learn operating s!stem)

    _unixunix`linux +,ic, one !ou c,oose)

    7) Using K%'K& and so on to K=

    .,e first pair of parent,esis specified in t,e pattern represents t,e K%' t,e second represents t,eK& and so on) .,e K%'K& can e used in t,e replacement string to ma*e c,anges to t,e sourcestring) "s an example' if !ou +ant to replace t,e +ord unix in a line +it, t+ice as t,e +ord li*eunixunix use t,e sed command as elo+)

    bsed ^s/KunixK1/K%K%/^ file)txt

    unixunix is great os) unix is opensource) unix is free os)

    learn operating s!stem)

    unixunixlinux +,ic, one !ou c,oose)

    .,e parent,esis needs to e escaped +it, t,e ac*slas, c,aracter) "not,er example is if !ou+ant to s+itc, t,e +ords unixlinux as linuxunix' t,e sed command is

    bsed ^s/KunixK1KlinuxK1/K&K%/^ file)txt

    unix is great os) unix is opensource) unix is free os)

    learn operating s!stem)

    linuxunix +,ic, one !ou c,oose)

    "not,er example is s+itc,ing t,e first t,ree c,aracters in a line

  • 5/28/2018 dba important linux commands

    78/97

    bsed ^s/[K)K1K)K1K)K1/KK&K%/^ file)txt

    inux is great os) unix is opensource) unix is free os)

    aelrn operating s!stem)

    inuxlinux +,ic, one !ou c,oose)

    ;) @uplicating t,e replaced line +it, /p flag

    .,e /p print flag prints t,e replaced line t+ice on t,e terminal) If a line does not ,a-e t,e searc,pattern and is not replaced' t,en t,e /p prints t,at line onl! once)

    bsed ^s/unix/linux/p^ file)txt

    linux is great os) unix is opensource) unix is free os)

    linux is great os) unix is opensource) unix is free os)

    learn operating s!stem)

    linuxlinux +,ic, one !ou c,oose)

    linuxlinux +,ic, one !ou c,oose)

    =) Printing onl! t,e replaced lines

    Use t,e 0n option along +it, t,e /p print flag to displa! onl! t,e replaced lines) Jere t,e 0noption suppresses t,e duplicate ro+s generated ! t,e /p flag and prints t,e replaced lines onl!one time)

    bsed 0n ^s/unix/linux/p^ file)txt

    linux is great os) unix is opensource) unix is free os)

    linuxlinux +,ic, one !ou c,oose)

    If !ou use 0n alone +it,out /p' t,en t,e sed does not print an!t,ing)

  • 5/28/2018 dba important linux commands

    79/97

    %() $unning multiple sed commands)

    ou can run multiple sed commands ! piping t,e output of one sed command as input toanot,er sed command)

    bsed ^s/unix/linux/^ file)txtG sed ^s/os/s!stem/^

    linux is great s!stem) unix is opensource) unix is free os)

    learn operating s!stem)

    linuxlinux +,ic, one !ou c,os!steme)

    Sed pro-ides 0e option to run multiple sed commands in a single sed command) .,e ao-e

    output can e ac,ie-ed in a single sed command as s,o+n elo+)

    bsed 0e ^s/unix/linux/^ 0e ^s/os/s!stem/^ file)txt

    linux is great s!stem) unix is opensource) unix is free os)

    learn operating s!stem)

    linuxlinux +,ic, one !ou c,os!steme)

    %%) $eplacing string on a specific line numer)

    ou can restrict t,e sed command to replace t,e string on a specific line numer) "n example is

    bsed ^ s/unix/linux/^ file)txt

    unix is great os) unix is opensource) unix is free os)

    learn operating s!stem)

    linuxlinux +,ic, one !ou c,oose)

    .,e ao-e sed command replaces t,e string onl! on t,e t,ird line)

    %&) $eplacing string on a range of lines)

  • 5/28/2018 dba important linux commands

    80/97

    ou can specif! a range of line numers to t,e sed command for replacing a string)

    bsed ^%' s/unix/linux/^ file)txt

    linux is great os) unix is opensource) unix is free os)

    learn operating s!stem)

    linuxlinux +,ic, one !ou c,oose)

    Jere t,e sed command replaces t,e lines +it, range from % to ) "not,er example is

    bsed ^&'2 s/unix/linux/^ file)txt