Linux_Notes by Jitendra Sir

Embed Size (px)

Citation preview

  • 8/11/2019 Linux_Notes by Jitendra Sir

    1/125Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. 1

    Linux Commands

    Introduction: Unix is the first oerating s!ste" in the #orld, de$eloed %! &e" 'ho"son and(ennis Ritchie in 1)*) at Bell La% %! +'' Co"an!.

    FSF: -ree soft#are foundation organiation, the! start a ro/ect %! na"e 0NU. 'he "ain ai" ofthis ro/ect is to de$elo such a .2. that can run on an! latfor". 3n 1))1, a student Linux'ar$alds de$eloed a kernel na"ed Linus &ernel lus 0NU alication called Linux .2.

    Linux is an oen source technolog!. (ifferent co"anies that ro$ide Linux in "arket areRedhat, 2u2e, 4andrake, 'ur%o, &noix, U%untu etc.

    Linux Features:

    5 Linux is the fastest oerating s!ste" in the #orld. 3t runs 6 to 7 ti"es faster than #indo#s .2.

    5 Linux is the $er! secured .2. Because there is no an! ro%le" of $irus.

    5 Linux file for"at is text for"at and #indo#s file for"at is %inar! for"at.

    5 Linux is $er! relia%le oerating s!ste" %ecause kernel of Linux is $er! sta%le as co"areto #indo#s kernel not crashed easil!.

    5 'he linux kernel is $er! s"all8 it can store in flo! disk.

    5 Linux sues the x9#indo#s s!ste" #hich is ad$anced net#ork #indo#ing s!ste". Usingthis s!ste" #e can disla! outut of an! #orkstation "onitor attached in the net#ork.

    Linux Advantages:

    5 irus Proof

    5 Crash Proof

    5 Econo"ical

    5 4ultiuser, 4ulti deskto and "ultitasking

    What is the shell?

    'he shell in Linux is the interface through #hich !ou #ill carr! out "ost of !our #ork. ;hile itsee"s in out#ard aearance to %e unsohisticated, a lot of o#er is a$aila%le to the shell user, %! itsa%ilit! to co"%ine co""ands.

    Available shells in Linux

    + nu"%er of different shells are a$aila%le in Linux, #hich cater for different needs. +t a %asicle$el, the! all allo# !ou to enter co""ands, and redirect the outut of the co""ands to thearoriate lace, %e it a file, or !our ter"inal.

    'here are t#o "a/or schools of shells8 thesh fa"il!, and the csh fa"il!. ;hen onl! using the shellas an interacti$e tool, the! are all reasona%l! si"ilar, #ith so"e shells ro$iding facilities to "akeinteracti$e use easier

  • 8/11/2019 Linux_Notes by Jitendra Sir

    2/125Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. 6

    2o"e of the co""on t!es of shells are listed %elo#.

    Linux shells

    Na"e -eatures 2tartu -iles

    sh Basic shell and al#a!s a$aila%le .rofile

    %ash Co"letion, aliasing, histor! and al"ostal#a!s a$aila%le

    .%ash?rofile

    .%ashrc

    .inutrc

    ksh Co"letion, aliasing, histor! and Non9standard .rofile

    sh Co"etion, aliasing, histor! and Non9standard .shen$

    .rofile

    .shrc

    .login

    csh Co"letion, aliasing, histor! and al"ostal#a!s a$aila%le

    .cshrc

    .login

    tcsh Co"letion, aliasing, histor! and al"ostal#a!s a$aila%le

    .tcshrc

    .login

    Linux Filesystem:

    'he files!ste" in Linux can %e seen as a tree, or hierarchical structure. E$er!thing starts #ith the

    root di r ec to r y, also kno#n asslash and /.

    Example Linux ilesystem layout@

    @%in @etc @ho"e @%oot @de$ @te" @ot @"nt @usr

    @ho"e@/itendra @ho"e@ra/esh @usr@local @usr@%in

    @ho"e@/itendra@ro/ects @ho"e@ra/esh@ro/ects

    (2 $@s Linux

  • 8/11/2019 Linux_Notes by Jitendra Sir

    3/125Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. 7

    3f !ou are a%le to na$igate through 429(2 #ill %e a%le to ick u on the na$igation of L3NUA inthe follo#ing chart #e ha$e listed se$eral of the $arious si"ilarities of (2 and L3NUA.

    !"S LI#$%

    attri% ch"od

    %acku tar, gi, %i6, i

    dir ls

    cls clear co! c

    del r"

    deltree r" R or r"dir

    edit $i, $i", ico

    for"at fdfor"at, "ount, u"ount

    "o$e @ rena"e "$

    t!e less fileD

    cd cd, chdir

    "ore file "ore file

    "d "kdir #in startx or xter"

    ls: (isla! all the files and directories resent in the current director!.

    Usages 2!ntax9ls otionsFG-ilesF

    tions:9l :9 (isla! all the files, directories, their "ode. Nu"%er of links, o#ner of the file, grou of

    the o#ner, file sie, "odified date and ti"e and filena"e.

    9t : (isla! files list %! last "odification ti"e9a : (isla! all the files along #ith hidden files.9d : (isla! director! files instead of contents.

    9 : Puts a

  • 8/11/2019 Linux_Notes by Jitendra Sir

    4/125Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. K

    ls &l more :9 (isla! all the co""ands age #ise

    /itendraH n t s e r $ e rIF ls 9l "ore total OKOK9r#9r#9r99 1 /itendra /itendra 716 Jan 1 K:K6 addstring.c

    9r#xr#xr9x 1 /itendra /itendra O Jan 1 K:K6 a.out9r#9r#9r99 1 /itendra /itendra O7OO*O Jan K K:6 %acku.tar.g

    dr#x999999 6 /itendra /itendra K)* Jan 7 *:O ccna

    9r#9r99r99 1 /itendra /itendra *61 +r 6 ): client.l9r#9r99r99 1 /itendra /itendra KK7 +r 1 :KM c.l9r#9r#9r99 1 /itendra /itendra K1 Jan 1 K:6K distance.c

    9r#9r99r99 1 /itendra /itendra 7*1 Jan 1 :1K factorial.c9r#9r#9r99 1 /itendra /itendra *1 Jan 16 :76 filehandling.c

    9r#9r#9r99 1 /itendra /itendra 16 -e% 1 16:61 file.l9r#9r99r99 1 /itendra /itendra 617 Jan 1 :1K future$alue.c

    994ore99

    ls &a : (isla! files list including hidden

  • 8/11/2019 Linux_Notes by Jitendra Sir

    5/125Jitendra Rathi, Lecturer, Engineering College Bikaner Page No.

    rmdir cs@language cs@ackage cs : Re"o$e "ultile directories at the sa"e ti"e.

    p)d :9 (isla! ath of resent #orking director!

    logout or *d :9 for logout the current session

    + ro"t :9 Nor"al User, ro"t :9 2uer$isor or Root user

    su :9 3t is use to gain suer user ri$ilege, it asks the root

    ass#ord./itendraH n t s e r $ e rIF suPass#ord: r oo t Hn t s e r $ e rgo$indcF exitexit /itendraH n t s e r $ e rIF

    more filena"e : (isla! file contents Page #ise el and ress VD to Vuit fro" helman shutdo)n :9 >el of 2hutdo#n Co""andman ls &l :9 >el of a articular co""and

    .istory: 'he histor! co""and is use to "aniulate the re$iousl! entered co""ands histor! list.3t erfor"s se$eral oerations related to re$iousl! executed co""ands recorted in the histor! listand these recorded co""ands referred to as en e$ent. +ll the e$ents are nu"%ered starting fro" 1

    #ith histor! co""and. ;e can secif! e$ent nu"%er in a ositi$e for" or in a negati$e for".E$ent

  • 8/11/2019 Linux_Notes by Jitendra Sir

    6/125Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. *

    /itendra c H n t s e r $ e rIF

    4E@ho"e@staff@go$indc go$ind c H n t s e r $ e rIF

    .o) to ma(e a !os command in Linux

    cls

  • 8/11/2019 Linux_Notes by Jitendra Sir

    7/125Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. M

    co""and.DZDclear

  • 8/11/2019 Linux_Notes by Jitendra Sir

    8/125Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. O

    D[

    cls :9 Clears the screen

    date :9 (isla! current s!ste" date and ti"eW\" : (isla! onl! 4onth Nu"%er W\h : (isla! 4onth Na"eW\] : (isla! ]ear

  • 8/11/2019 Linux_Notes by Jitendra Sir

    9/125

    #ote:#ere cal command displays calendar of Oct. +o. and Dec. '00,. -

    Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. )

    Note:By default bc command cant display decimal places

    scale6 : 2ecif! nu"%er of deci"al laces.ibase6 : Con$erts Binar! Nu"%er into (eci"al Nu"%er.obase6 : Con$erts (eci"al Nu"%er into Binar! Nu"%er.obase1* : Con$erts (eci"al Nu"%er into >exadeci"al Nu"%er.

    /itendraH n t s e r $ e rIF %c

    9V i%ase6111166/itendraH n t s e r $ e rIF %c9V o%ase61K111

    /itendraH n t s e r $ e rIF %c9V o%ase1*1KE

    /itendraH n t s e r $ e rIF

    cal :9 (isla! calendar of current "onth and!ear. Usages s!ntax:

    cal otionsF "onthF

    !earF tions:9s (isla! 2unda! as first colu"n.

    9" (isla! 4onda! as first colu"n.97 (isla! re$ious@current@next "onthQs calendar.

    9! (isla! 16 "onths calendar of current !ear.

    /itendraH n t s e r $ e rIF calJune 61

    2u 4o 'u ;e 'h -r 2a1 6 7 K

    * M O ) 1 11 1617 1K 1 1* 1M 1O 1)6 61 66 67 6K 6 6*6M 6O 6) 7

    /itendraH n t s e r $ e rIF cal 97 11 6)cto%er 6) No$e"%er 6) (ece"%er 6)

    2u 4o 'u ;e 'h -r 2a 2u 4o 'u ;e 'h -r 2a 2u 4o 'u ;e 'h -r 2a1 6 7 1 6 7 K * M 1 6 7 K

    K * M O ) 1 O ) 1 11 16 17 1K * M O ) 1 11 1611 16 17 1K 1 1* 1M 1 1* 1M 1O 1) 6 61 17 1K 1 1* 1M 1O 1)1O 1) 6 61 66 67 6K 66 67 6K 6 6* 6M 6O 6 61 66 67 6K 6 6*6 6* 6M 6O 6) 7 71 6) 7 6M 6O 6) 7 71

    /itendraH n t s e r $ e rIF

    mailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntservermailto:ganesh@ntserver
  • 8/11/2019 Linux_Notes by Jitendra Sir

    10/125Jitendra Rathi, Lecturer, Engineering College Bikaner Page No. 1

    cal ) 1M6 :9 (isla! calendar of secified "onth and !ears

  • 8/11/2019 Linux_Notes by Jitendra Sir

    11/125

    )hoami :9 (isla! current login statusgo$indc W ts@1 Jun 16:1 : (isla! #ith header otion9u : (isla! "ore detail

    /itendraH n t s e r $ e rIF #ho/itendra ts@ Jun 16:76 uN+4E L3NE '34E 3(LE P3( C44EN'

    /itendra ts@ Jun 16:76 . 1OOM)

  • 8/11/2019 Linux_Notes by Jitendra Sir

    12/125

    #ote: 4hen a user send a message then on the receier side its loos lie5

    go$ind c H n t s e r $ e rIF /itendraH n t s e r $ e rIF4essage fro"/itendraH n t s e r $ e ron ts@ at16:) ... >elloare !ou %us! or can !ou gi$e "e "inutes right no#E-

    )rite user1 user6 usern :9 2end "essages to "ultile users

    mesg y7n :9 ! +ccet "essages fro" other usersn CanQt recei$e an! "essage fro" other users

    /itendraH n t s e r $ e rIF #rite go$indc

    #rite: go$indc has "essages disa%led

    /itendraHntser$er IF

    ortune :9 (isla! Jocks rando"l!.

    cp 2ource -ileD 'arget -ileD :9 Co! a file

    Co! a (irector! along #ith all the su%directories and files.c r 2ource (irNa"eD 'arget (irNa"eDc rf 2ource (irNa"eD 'arget (irNa"eD

    'he& 2#itch is use to forcefull! co!, it re"o$es existing files on destination ath. ;e also use&8

    instead of&r otion.

    c i "!file !ourfile : 3f target file is alread! exist then asks for o$er#riting.

    #ote:9 'he 3p

  • 8/11/2019 Linux_Notes by Jitendra Sir

    13/125

    N u " e r ic P e r "i ss io n s :C>4( can also to attri%uted %! using Nu"eric Per"issions:

    K read %! o#nerK read %! grouK read %! an!%od!

  • 8/11/2019 Linux_Notes by Jitendra Sir

    14/125

    characters in the text %eing disla!ed

  • 8/11/2019 Linux_Notes by Jitendra Sir

    15/125

    vi 9ext Editor

    $i is the standard Linux text editor that can %e used to create and "odif! text files. i usages .exrc file tto change the default %eha$ior. 'his file 4E@.$i"rc location.

    'he $i editor has three "odes, co""and "ode, insert@text "ode and Ex 4ode@.

    1. Command mode: 'his is the default "ode. ;hen #e oen an existing file or create a ne# one th$i auto"aticall! goes into this "ode.

    6. Insert79ext 5ode: 'ext is inserted into the docu"ent. 'his "ode is in$oked %! ressing the i

  • 8/11/2019 Linux_Notes by Jitendra Sir

    16/125

    Cursor movement: 'he follo#ing ke!s are used in co""and "ode to "o$e current cursor osition.

    h k / l

    =eystro(es Action

    h 4o$e cursor one character left k 4o$e cursor one line u

    1k 4o$e cursor ten lines u/ 4o$e cursor one line do#nl 4o$e cursor one character right #

    4o$e one #ord right# 4o$e cursor ahead #ords% 4o$e cursor %ack a #ord at a ti"e

    B 4o$e cursor %ack a #ord at ti"e% 4o$e cursor %ack #ords

    e 4o$e cursor to end of #orde 4o$e cursor ahead to the end of the th #ord

    4o$e to the first line on the screen4 4o$e to the "iddle line on the screen

    L 4o$e to the last line on the screen.:fx 4o$es to the cursor to the secified character x in the for#ard direction.

    :-x 4o$es to the cursor to the secified character x in the %ack#ard direction.8tx 4o$e cursor /ust %efore the secified character x in the for#ard direction.

    :'x 4o$es the cursor /ust after the secified character x in the %ack#ard direction. 04o$e cursor to the %eginning of the last line in the file

    0 4o$e cursor to the %eginning of the th line in the fileCtrlWd 2croll do#n one half of a ageCtrlWu 2croll u one half of a age. CtrlWf

    2croll for#ard one age CtrlW%2croll %ack#ard one age

    _. 4o$e cursor to re$iousl! "odified line.Ta 4o$e cursor to line "ark a^ generated %! "arking #ith ke!stroke "a^T+ 4o$e cursor to line "ark ^a^

  • 8/11/2019 Linux_Notes by Jitendra Sir

    17/125

    !eleting 9ext: 'o delete text fro" $i editor then $i co""and line "ode ro$ides thefollo#ing co""ands to delete text to #ord seed u.

    x (elete character under cursor osition and the text on the right hand side shifted toleft to fill u sace. 3f cursor ositioned at the end of line then delete character fro"left.

    x Reeat factor, it delete fi$e character fro" right hand side and text shifted to left.

    A (elete character %efore cursor osition.dd (elete the entire line #here cursor is ositioned.1dd (eletes current line and %elo# nine lines.dd (elete nu"%er of lines fro" cursor osition.CtrlW# (elete entire #ord fro" cursor osition toleft. ( or d (elete fro" cursor osition to end of line.d# (elete a #ord fro" cursor osition.Kd# (elete K ;ords

    8epeating Character: 'o reeat a character "ultile ti"es then in the insert "ode t!e acharacter i.e. 7> and then ress ESC ke! and then enter 0a>

  • 8/11/2019 Linux_Notes by Jitendra Sir

    18/125

    Copying7an(ing text 4y:9 'he ! oerator !anks@coies text and it #orks in the sa"e #a! as oerad #orks, and the P or P co""and are used to astes coied text at current cursor osition. E1!! !ank@co! 1 lines fro" cursor osition to for#ard direction and then "o$e cursor at arorilace and then ress O or P co""and to aste the copied text.

    Changing text 4c:9 'o change the text then

  • 8/11/2019 Linux_Notes by Jitendra Sir

    19/125

    Inserting ile G command output into existing ile:9 'o inserts the contents of a file at certain

    location into currentl! oened file then in ex"ode

  • 8/11/2019 Linux_Notes by Jitendra Sir

    20/125

    Note5: To switch /etween files then unsaed te6t is deleted so that use 5 set auto write or 5set aw

    command to sae automatically while switching /etween files.

    Splitting )indo):9 $i editor ro$ides the facilit! to slit a #indo# into "ultile #indo#s. +

    #indo# can %e e"t! #indo#s or slit a sa"e file into searate #indo#s.

    :sEnterF 'o slit existing #indo# into t#o #indo#s.

    :ne#EnterF en a ne# %lank #indo#.Note5 : The CTRL+W is use to switch /etween windows and CTRL-W+ is use to increase the si;e

    of current window and CTRL-W- is use to decrease the si;e of current window.

    :on : 4ake current #indo# in full screen re"o$e all other #indo#.

    Note5: ! is use to

  • 8/11/2019 Linux_Notes by Jitendra Sir

    21/125

    c6!! : Co! 6 lines into na"ed %uffer c.

    :e ne#file.c : 2#itch into ne#file.c

    0 : 4o$e cursor at %otto" of file

    c : Paste text 6 lines fro" na"ed %uffer c.

    $ndo multiple deletions using numbered buers: 'he undo co""and

  • 8/11/2019 Linux_Notes by Jitendra Sir

    22/125

    Exa"le:-irst "o$e cursor at aroriate lace i.e. 10, 4o$e cursor at 1

    th

    line.

    "a 4ark #ith la%el na"e a0 4o$e cursor at

    thline of the

    file. "% 4ark location #ith la%el

    na"e %.Ta 4o$e cursor at "arked locationa

    T% 4o$e cursor at "arked location%

    Note: $i also ro$ides dou%led TQ

  • 8/11/2019 Linux_Notes by Jitendra Sir

    23/125

    taglength tl (efault. 2et significant characters

    lineli"it6KO* 4axi"u" file sie to edit

    #rascan@no#rascan #s@no#s Breaks line if too long

    #ra"argin@no#ra"argin #"@no#" (efine right "argin for line #raing.

    list@nolist (isla! all 'a%s@Ends of lines.

    %gdark

    %glight

    34: choose color sche"e for ^dark^ or ^light^

    console %ackground.

  • 8/11/2019 Linux_Notes by Jitendra Sir

    24/125

    5apping (eys o (eyboard 4map : 'he "a co""and is use to assign a ke! #ith a seVuenceof co""ands. 3t is useful to con$ert a seVuence of ke!strokes into a "acro.

    'o "a the ke! t #ith :)Enter; #hich is use to sa$e %uffered text onto disk.

    :"a t :#b4 b4 reresents the EN'ERF ke!:"a K :cc \b4 4a function ke! -K to co"ile the current c rogra". #O?%".e6rc (or .imrc for im) file so that theyare always aaila/le on i or im startup.

    ;3L(C+R(2 :9 'here are t#o #ildcards, na"el! and `. Unix shell ro$ides so"e "ore

    #ildcards. a%cF 4atch one character #hich should %e either a,% or ca%cF 4atch one character #hich is not a,% or c.9tF 4atch one character #hich falls #ithin the range 9t9tF 4atch one character #hich does not fall #ithin the range 9t.

    eg. ls 3id uni?/MN; or ls my203O;eg. mv unix3@;9)elve; 7north

    9o Change File Writes:

    chmod * filena"e

    K read, 6 ;rite KW6 * for user and re"aining t#o %!tes for grou and others

  • 8/11/2019 Linux_Notes by Jitendra Sir

    25/125

    cat a1.txt :9 (isla!s 4essage Per"ission (enied %ecause user canQt ha$e #rites to excessthis file.

    5ultiple Shell in Linux

    1. %ash Bourne shell : 'his is the (efault shell6. %sh %ash shell7. ksh korn shell

    K. csh c shell

    Note5 @S# shell generally use for @ programming and in uni6 the default shell is BS#

    Ctrl B Alt B F/ 0o into CU3

  • 8/11/2019 Linux_Notes by Jitendra Sir

    26/125

    'ask BarCtrl B Alt B FP 0o into 0U3

  • 8/11/2019 Linux_Notes by Jitendra Sir

    27/125

    netcon : 'o Configure Net#orking

    iconig eth : 'o check the 3 +ddress

    sc( @de$@hda : Check rectif! the disk integrit!

    e1sc( @de$@hda : Check rectif! the disk integrit!

    Note: Thefsc and e$fsc /oth commands are same /ut e$fsc is more powerful.

    init @1@* : >alt the s!ste"1 Boot s!ste" into single user "ode* Re%oot the 2!ste"

    pass)d : 'o change the Pass#ord

    linuxcon : 'o configure e$er!thing in Linux

  • 8/11/2019 Linux_Notes by Jitendra Sir

    28/125

    gun@ip a%c.txt.g : Unco"ress file

  • 8/11/2019 Linux_Notes by Jitendra Sir

    29/125

    e"7.txt:*e"M.txt:7gre l "anager `.txte".txte"1.txte".txtgre e "anagerS e sales"anS eS directorS e".txtgre f atternfilena"e e".txt

    gre n T"anagerQ e".txtgre $ T"anagerQ e".txtgre a+FgarFarF#alS e".txt :9 Regular exression is used to secif! a grou ofcharacter enclosed #ithin a air of rectangular %rackets;.

    Asteris( > :9 'he #ild card > is used to searches a attern #ith gre. i.e. s> searches s ss sss ssssGG. 'he ` "arks the re$ious character occurred ero or "ore ti"es.

    gre +aFg`arFarF#alS e".txt

    9he ' !ot :9 'he ' "atches a single character like shell . i.e. DQ' it "atches fi$e attern

    %eginning #ith a #hich is eVuilent to shellQs .

    'he . along #ith `

  • 8/11/2019 Linux_Notes by Jitendra Sir

    30/125

    sed options Kaddress actionR iles4s

    #ote:9 'he address and action are enclosed #ithin single Vuotes. 'he address can %e secified int#o #a!s:9

    1. secif! one or t#o lines like 7,K6. 2ecif! a 7

  • 8/11/2019 Linux_Notes by Jitendra Sir

    31/125

    sed n f inst1.txt f inst6.txt std.txt

    sed d e T@director@Q f inst1.txt f inst6.txt std.txt

    Context Addressing :9 'he attern "ust %e %ounded %! a 7 on either side and #e can also secif! o"e (irectoriesBro#sa%le noCreate "ode **K

    (irector! "ode MM4ax connections K

    ;rita%le !es

  • 8/11/2019 Linux_Notes by Jitendra Sir

    60/125

    rintersFCo""ent +ll PrintersPath @$ar@sool@sa"%aBro#sa%le no0uest ok noPrinta%le !es

    netlogonF

    co""ent Net#ork Logon 2er$icesath @ho"e@share@netlogonguest ok no#rita%le no%ro#sea%le noshare "odes noroot reexec @ho"e@share@scrits@"akelogonscrit.1 \U \L \0root ostexec r" @ho"e@share@netlogon@\u.%at

    ProfilesFath @ho"e@share@rofiles

    %ro#sea%le noguest ok !es#ritea%le !esroot reexec @%in@"kdir @ho"e@share@rofiles@\U8 Y

    @%in@cho#n \U @ho"e@share@rofiles@\U8 Y@%in@ch"od M @ho"e@share@rofiles@\U

    LearningFco""ent -ile Pro$ided %! 'eachers to 2tudentsath @ho"e@share@learning#ritea%le no

    %ro#sea%le !esread onl! !esu%lic !esforce create "ode **K

    force director! "ode MM

    PrintersFco""ent >P ) Printer in Co"uter La%

    ath @$ar@sool@sa"%a%ro#sea%le !esguest ok no

    rinta%le !esuse client dri$ers !es

    Installing Hoot Image When boot loader is crupted

    1. Boot fro" Linux C( 11' Choose Linux 8escue : Select #e)t)or(ing 7# to #"M' chroot 7mnt7sysimageN' grub3install 7dev7hda

  • 8/11/2019 Linux_Notes by Jitendra Sir

    61/125

    D' reboot

    9o conigure A!SL ac(age : 3nstall r9oe Package and the configurefollo#ing ara"eters:91. userid 6. Net#ork 3nterface

    2ource soft#are de$elo"ent

    and -ree erating 2!ste"

  • 8/11/2019 Linux_Notes by Jitendra Sir

    62/125

    $ser E$er!one. -ro" ho"e users to

    de$eloers and co"uter

    enthusiasts alike.

    Unix oerating s!ste"s #ere

    de$eloed "ainl! for

    "ainfra"es, ser$ers and

    #orkstations excet 2A,

    ;hich is designed for

    e$er!one. 'he Unix

    en$iron"ent and the client9

    ser$er rogra" "odel #ereessential ele"ents in the

    de$elo"ent of the 3nternet

    5anuacturer Linux kernel is de$eloed %!

    the co""unit!. Linus

    'or$alds o$ersees things.

    'hree %iggest distri%utions are

    2olaris e#lett Packard. +nd

    +le 4akes 2A, an unix

    %ased os..

    $sage Linux can %e installed on a#ide $ariet! of co"uter

    hard#are, ranging fro"

    "o%ile hones, ta%let

    co"uters and $ideo ga"e

    consoles, to "ainfra"es and

    suerco"uters.

    'he UN3A oerating s!ste" isused in internet ser$ers,

    #orkstations PCs.

    Back%one of the "a/orit! of

    finance infrastructure and

    "an! 6Kx7* high a$aila%ilit!

    solutions.

    !evelopment and

    !istribution

    Linux is de$eloed %! en

    2ource de$elo"ent i.e.

    through sharing and

    colla%oration of code and

    features through foru"s etc

    and it is distri%uted %! $arious

    $endors.

    Unix s!ste"s are di$ided into

    $arious other fla$ors, "ostl!

    de$eloed %! +'' as #ell as

    $arious co""ercial $endors

    and non9rofit organiations.

    \$I Linux t!icall! ro$ides t#o

    0U3s, &(E and 0no"e. But

    there are "illions of

    alternati$es such as LA(E,

    Afce, Unit!, 4ate, t#", ect.

    3nitiall! Unix #as a co""and

    %ased 2, %ut later a 0U3 #as

    created called Co""on

    (eskto En$iron"ent. 4ost

    distri%utions no# shi #ith

    0no"e.

    File system support Ext6, Ext7, ExtK, Jfs,

    Reiser-2, Afs, Btrfs, -+',

    -+'76, N'-2

    /fs, gfs, hfs, hfsW, ufs, xfs, fs

    for"at

    9ext mode interace

    B+2> ell=

    is the Linux default shell. 3t

    can suort "ultile

    co""and interreters.

    riginall! the Bourne 2hell.

    No# it_s co"ati%le #ith

    "an! others including B+2>,

    &orn C.

  • 8/11/2019 Linux_Notes by Jitendra Sir

    63/125

    rice -ree %ut suort is a$aila%le

    for a rice.

    2o"e free for de$elo"ent

    use at,

    (e%ian, +rchlinux,+ndroid

    etc.

    2 A, 2olaris, +ll Linux

    Architectures

    riginall! de$eloed for

    3ntel_s xO* hard#are, orts

    a$aila%le for o$er t#o doen

    CPU t!es including +R4

    3nsired %! 43N3A

  • 8/11/2019 Linux_Notes by Jitendra Sir

    64/125

  • 8/11/2019 Linux_Notes by Jitendra Sir

    65/125

    !ierence bet)een Linux and Windo)s

    Linux Windo)s

    What is it?

    Linux is an exa"le of en

    2ource soft#are de$elo"ent

    and -ree erating 2!ste"

  • 8/11/2019 Linux_Notes by Jitendra Sir

    66/125

    \$I Linux t!icall! ro$ides t#o0U3s, &(E and 0no"e. But

    there are "illions of

    alternati$es such as LA(E,

    Afce, Unit!, 4ate, t#", ect.

    'he ;indo#s 0U3 is an

    integral co"onent of the 2

    and is not relacea%le. 'his

    can %e a con #hen it co"es to

    ;indo#s O_s 4etro

    File system support Ext6, Ext7, ExtK, Jfs,

    Reiser-2, Afs, Btrfs, -+',

    -+'76, N'-2 -+'

    -+'76, N'-2, ex-+'

    9ext mode interace B+2> ell=

    is the Linux default shell. 3t

    can suort "ultile

    co""and interreters.

    ;indo#s uses a co""and

    shell and each $ersion of

    ;indo#s has a single

    co""and interreter #ith dos9

    like co""ands, recentl! there

    is the addition of the otional

    Po#er2hell that uses "ore

    Unix9like co""ands.

    rice -ree %ut suort is a$aila%le

    for a rice.

    9K

    Security Linux has had a%out *91

    $iruses listed till date. None of

    the" acti$el! sreading

    no#ada!s.

    +ccording to (r. Nic Peeling

    and (r Julian 2atchell_s

    +nal!sis of the 3"act of

    en 2ource 2oft#areS there

    ha$e %een "ore than *,$iruses in ;indo#s. +nti

    irus cost a%out 6 to K

    9hreat detection and

    solution

    3n case of Linux, threat

    detection and solution is $er!

    fast, as Linux is "ainl!

    co""unit! dri$en and

    +fter detecting a "a/or threat

    in ;indo#s 2, 4icrosoft

    generall! releases a atch that

    can fix the ro%le" and it can

  • 8/11/2019 Linux_Notes by Jitendra Sir

    67/125

  • 8/11/2019 Linux_Notes by Jitendra Sir

    68/125

    under the "odel of free and

    oen source soft#are

    de$elo"ent and distri%ution.

    'he defining co"onent of

    Linux is the Linux kernel, an

    oerating s!ste" kernel first

    released

    "arketed, and sold %!

    4icrosoft. 4icrosoft

    introduced an oerating

    en$iron"ent na"ed ;indo#s

    on No$e"%er 6, 1)O as a

    grahical oerating s!ste"

    shell for 429(2.

    Supported platorms

    +ll Po#erPC: $ersions 1. 9 N'

    K.8 (EC +lha: $ersions 1. 9

    N' K.8 43P2 RK:

    $ersions 1. 9 N' K.8 3+976:

    $ersions 1. 9 O8 3+9*K:

    $ersion AP8 xO*9*K: $ersions

    AP 9 O8 +R4: $ersion R'8

    Source model en 2ource Closed @ 2hared source

    9erminal 4ulti 'er"inal ;indo#s 99999999

    Components of Linux System

    Linux erating 2!ste" has ri"aril! three co"onents

    =ernel9 &ernel is the core art of Linux. 3t is resonsi%le for all "a/or acti$ities of this

    oerating s!ste". 3t is consists of $arious "odules and it interacts directl! #ith the underl!inghard#are. &ernel ro$ides the reVuired a%straction to hide lo# le$el hard#are details to

    s!ste" or alication rogra"s.

    System Library9 2!ste" li%raries are secial functions or rogra"s using #hich alication

    rogra"s or s!ste" utilities accesses &ernel_s features. 'hese li%raries i"le"ents "ost of thefunctionalities of the oerating s!ste" and do not reVuires kernel "odule_s code access rights.

    System $tility9 2!ste" Utilit! rogra"s are resonsi%le to do secialied, indi$idual le$el

    tasks.

  • 8/11/2019 Linux_Notes by Jitendra Sir

    69/125

    Kernel Mode vs User Mode

    &ernel co"onent code executes in a secial ri$ileged "ode called (ernel mode#ith full access toall resources of the co"uter. 'his code reresents a single rocess, executes in single address saceand do not reVuire an! context s#itch and hence is $er! efficient and fast. &ernel runs each rocessesand ro$ides s!ste" ser$ices to rocesses, ro$ides rotected access to hard#areQs to rocesses.

    2uort code #hich is not reVuired to run in kernel "ode is in 2!ste" Li%rar!. User rogra"s andother s!ste" rogra"s #orks in $ser 5ode#hich has no access to s!ste" hard#ares and kernelcode. User rogra"s@ utilities use 2!ste" li%raries to access &ernel functions to get s!ste"_s lo# le$eltasks.

    Basic Features-ollo#ing are so"e of the i"ortant features of Linux erating 2!ste".

    ortable9 Porta%ilit! "eans soft#ares can #orks on different t!es of hard#ares in sa"e

    #a!.Linux kernel and alication rogra"s suorts their installation on an! kind of hard#arelatfor".

    "pen Source9 Linux source code is freel! a$aila%le and it is co""unit! %ased de$elo"ent

    ro/ect. 4ultile tea"Qs #orks in colla%oration to enhance the caa%ilit! of Linux oeratings!ste" and it is continuousl! e$ol$ing.

    5ulti3$ser9 Linux is a "ultiuser s!ste" "eans "ultile users can access s!ste" resources

    like "e"or!@ ra"@ alication rogra"s at sa"e ti"e.

    5ultiprogramming9 Linux is a "ultirogra""ing s!ste" "eans "ultile alications can

    run at sa"e ti"e.

    .ierarchical File System9 Linux ro$ides a standard file structure in #hich s!ste" files@ user

    files are arranged.

    Shell9 Linux ro$ides a secial interreter rogra" #hich can %e used to execute co""ands

    of the oerating s!ste". 3t can %e used to do $arious t!es of oerations, call alicationrogra"s etc.

  • 8/11/2019 Linux_Notes by Jitendra Sir

    70/125

    Security9 Linux ro$ides user securit! using authentication features like ass#ord rotection@

    controlled access to secific files@ encr!tion of data.

    Architecture

    Linux 2!ste" +rchitecture is consists of follo#ing la!ers

    .ard)are layer9 >ard#are consists of all eriheral de$ices ((@ CPU etc=.

    =ernel9 Core co"onent of erating 2!ste", interacts directl! #ith hard#are, ro$ides lo#le$el ser$ices to uer la!er co"onents.

    Shell9 +n interface to kernel, hiding co"lexit! of kernel_s functions fro" users. 'akes

    co""ands fro" user and executes kernel_s functions.

    $tilities9 Utilit! rogra"s gi$ing user "ost of the functionalities of an oerating s!ste"s.

    What is inger?

    finger co""and is used to looku infor"ation a%out an user.

    Syntax

    finger 9l"sF user1 user6 G.. F

    /' [ie) detail about a particular user

    finger co""and #ill disla! login, userna"e, ho"e director!, shell infor"ation a%out a articularuser as sho#n %elo#.

    + inger sathiya

    Login: sathiya #ame: 4null

  • 8/11/2019 Linux_Notes by Jitendra Sir

    71/125

    !irectory: 7home7sathiya Shell: 7bin7bash

    "n since 5on #ov / /_:ND 4IS9 on :0 4messages o

    "n since 5on #ov / /_:N 4IS9 on pts70 rom :0'0

    #e) mail received Fri 5ay P /0:MM 10/0 4IS9

    $nread since Sat un P /1:DO 100_ 4IS9

    #o lan'

    1' [ie) login details and Idle status about an user

    ]ou can use finger 9s otion to $ie# the login detail for a articular user.+ inger 3s root

    Login #ame 9ty Idle Login 9ime "ice "ice hone

    root root >/ /Od Wed /P:ND

    root root >1 Md Fri /:DM

    root root >M 5on 10:10

    root root >ta 1 9ue /D:NM

    root root >tb 1 9ue /D:NN

    Syntax and Options

    Short

    Option

    Option Description

    -s

    !isplay the userRs login name< real name< terminal name and )rite status idle time

    &m

    ;nly print information about the user and host associated with standard input

    (the terminalwhere the command was issued) 3his method adheres to the

    !;7standard

    &p,&&proces

    s

    !rint acti%e processes spawned by init

    &4,

    &&count6isplays all login names, and a count of all logged-on users

    &r,

    &&runlev

    el

    !rint the current runle%el

    &s,&&short

    !rint only name, line, and time "elds 3his is the default

    &t,

    &&time

    !rint the last time the system cloc$was changed, if the information is

    a%ailable

    &1, &',

    &&mes%

    dd a characterwhich indicates the state of the terminal line 858 if the

    terminal is writable, 8&8 if it is not, or 868 if a bad line is encountered

    &u,

    &&users!rint the idle time for each user, and the process 76

    &&messa%

    e

    ame as &1

    &&

    'rita+leame as &1

    &&help 6isplay a help message, and e+it

    &&

    version6isplay %ersion information, and e+it

    Linux / Unix Command: w

    Command Library

    !AM*w - show who is logged on and what they are doing

    http://www.computerhope.com/jargon/d/dns.htmhttp://www.computerhope.com/jargon/s/stdin.htmhttp://www.computerhope.com/jargon/t/terminal.htmhttp://www.computerhope.com/jargon/p/posix.htmhttp://www.computerhope.com/unix/telinit.htmhttp://www.computerhope.com/jargon/r/runlevel.htmhttp://www.computerhope.com/jargon/c/clock.htmhttp://www.computerhope.com/jargon/c/charact.htmhttp://linux.about.com/library/cmd/blcmdl.htmhttp://www.computerhope.com/jargon/d/dns.htmhttp://www.computerhope.com/jargon/s/stdin.htmhttp://www.computerhope.com/jargon/t/terminal.htmhttp://www.computerhope.com/jargon/p/posix.htmhttp://www.computerhope.com/unix/telinit.htmhttp://www.computerhope.com/jargon/r/runlevel.htmhttp://www.computerhope.com/jargon/c/clock.htmhttp://www.computerhope.com/jargon/c/charact.htmhttp://linux.about.com/library/cmd/blcmdl.htm
  • 8/11/2019 Linux_Notes by Jitendra Sir

    84/125

  • 8/11/2019 Linux_Notes by Jitendra Sir

    85/125

  • 8/11/2019 Linux_Notes by Jitendra Sir

    86/125

    &&

    messa%

    e

    ame as &1

    &&

    'rita+leame as &1

    &&help 6isplay a help message, and e+it

    &&version

    6isplay %ersion information, and e+it

    Notes

    3fCI%is secified, )hogathers its infor"ation fro" this file. ther#ise, it reads fro" a default filelocation

    (isla!s ^all^ infor"ation, and headers a%o$e each colu"n of data, for exa"le:

    N",; LIN; TI,; I*L; PI* O,,;NT ;FIT '!()!)!7 7: !5( idCsi termC e9itC system boot '!()!)!7 7: r1n)le6el ' '!()!)!7 7: lastC+ '!()!)!7 7:! !27 idCl' termC e9itCLO>IN tty2 '!()!)!7 7:! '&4 idC2LO>IN tty5 '!()!)!7 7:! '&& idC5LO>IN tty( '!()!)!7 7:! '&7 idC(LO>IN tty' '!()!)!7 7:! '&5 idC'LO>IN tty! '!()!)!7 7:! '&( idC!

    LO>IN tty% '!()!)!7 7:! '&2 idC% #ts/ '!()!)!7 !!:%! '&!! idCts/ termC e9itCl1cy G #ts/! '!()!)!7 '':(' 0 224 -:0 #ts/' '!()!)!& ':!( idC/' termC e9itC #ts/% '!()!)!& ':& idC/% termC e9itC #ts/( '!()!)!7 '!:% idC/( termC e9itCl1cy G #ts/ '!()!)!7 '':! !:( 2%% -:0

    s a 1inu+ user, sometimes it is re4uired to $now some basic information li$e

  • 8/11/2019 Linux_Notes by Jitendra Sir

    87/125

    3ime of last system boot

    1ist of users logged-in

    :urrent run le%el etc

    3hough this type of information can be obtained from %arious "les in the 1inu+ system

    but there is a command line utility 'who' that does e+actly the same for you 7n this

    article, we will discuss the capabilities and features pro%ided by the 'who' command

    3he basic synta+ of the who command is

    who DOPTIONE000 D =IL; H "! "' E

    *xamples of 7'ho7 command

    89 :et the information on currently lo%%ed in users

    3his is done by simply running the 'who' command (without any options) :onsider the

    following e+ample

    $ whohimansh1 tty7 '!')&)7 5:%% -:himansh1 #ts/ '!')&)7 2:(7 -:0himansh1 #ts/! '!')&)7 7:5& -:0

    ;9 :et the time of last system +oot

    3he is done using the -b option :onsider the following e+ample

    $ who )b system boot '!')&)7 5:%'

    o we see that the abo%e output gi%es the e+act date and time of last system boot

    IN tty( '!')&)7 5:%' !%4 idC(LO>IN tty5 '!')&)7 5:%' !%!% idC5

    LO>IN tty' '!')&)7 5:%' !%'' idC'LO>IN tty% '!')&)7 5:%' !%'( idC%LO>IN tty2 '!')&)7 5:%' !%'7 idC2LO>IN tty! '!')&)7 5:%' !(4' idC!

    o we see that information related to system login processes was displayed in the

    output

    =9 :et the hostname and user associated 'ith stdin

    3his is done using the -m option :onsider the following e+ample

  • 8/11/2019 Linux_Notes by Jitendra Sir

    88/125

    $ who )mhimansh1 #ts/! '!')&)7 7:5& -:0

    o we see that the rele%ant information was produced in the output

    >9 :et the current run level

    3his is done using the -r option :onsider the following e+ample

    $ who )r r1n)le6el ' '!')&)7 5:%'

    o we see that the information related to current run le%el (which is 0) was produced in

    the output

    ?9 :et the list of user lo%%ed in

    3his is done using the -u option :onsider the following e+ample

    $ who )1

    himansh1 tty7 '!')&)7 5:%% old !2!4 -:himansh1 #ts/ '!')&)7 2:(7 :%! '%%2 -:0himansh1 #ts/! '!')&)7 7:5& 0 '%%2 -:0

    o we see that a list of logged-in users was produced in the output

    @9 :et num+er of users lo%%ed&in and their user names

    3his is done using the -4 option :onsider the following e+ample

    $ who )himansh1 himansh1 himansh1 1sersC%

    o we see that information related to number of logged-in users and their user names

    was produced in the output

    /9 :et all the information

    3his is done using the -a option :onsider the following e+ample

    $ who )a system boot '!')&)7 5:%'

    r1n)le6el ' '!')&)7 5:%'LO>IN tty( '!')&)7 5:%' !%4 idC(LO>IN tty5 '!')&)7 5:%' !%!% idC5LO>IN tty' '!')&)7 5:%' !%'' idC'LO>IN tty% '!')&)7 5:%' !%'( idC%LO>IN tty2 '!')&)7 5:%' !%'7 idC2LO>IN tty! '!')&)7 5:%' !(4' idC!himansh1 G tty7 '!')&)7 5:%% old !2!4 -:himansh1 G #ts/ '!')&)7 2:(7 0 '%%2 -:0himansh1 G #ts/! '!')&)7 7:5& 0 '%%2 -:0

    o we see that all the information that 'who' can print is produced in output

  • 8/11/2019 Linux_Notes by Jitendra Sir

    89/125

    Linux 0 Unix 'ho Command *xamples 1o List Users on

    1he Systems

    %!Nix Crafton Januar! 6M, 617 co""entsL+2' UP(+'E( Januar! 6M, 61K

    in Co""ands, Linux, UN3A

    3 a" a ne# Linux and Unix s!ste" user. >o# do 3 disla! #ho is logged on "! Linux or Unix9likeoerating s!ste" using shell ro"t

    ]ou need to use whoco""and to disla! users #ho are currentl! logged in !our ser$er.

    'ho commanddetails

    6escription@ind who is on the

    system

    :ategory 2ser 7nformation

    6iculty Aasy

    Boot pri%ileges >o

    Astimated completion

    time ?m

    Contents

    ynta+

    A+amples

    how list of user logged in

    @ind time of last boot

    1ist dead processes

    1ist login processes

    :ount all login names

    how current runle%el

    how all info about logged on users

    ;ptions

    http://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#commentshttp://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#commentshttp://www.cyberciti.biz/faq/category/commands/http://www.cyberciti.biz/faq/category/linux/http://www.cyberciti.biz/faq/category/unix/http://www.cyberciti.biz/faq/linux-unix-commands/user-information/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#1http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#2http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#3http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#4http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#5http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#6http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#7http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#8http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#9http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#10http://www.cyberciti.biz/tips/about-ushttp://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#commentshttp://www.cyberciti.biz/faq/category/commands/http://www.cyberciti.biz/faq/category/linux/http://www.cyberciti.biz/faq/category/unix/http://www.cyberciti.biz/faq/linux-unix-commands/user-information/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#1http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#2http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#3http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#4http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#5http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#6http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#7http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#8http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#9http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#10
  • 8/11/2019 Linux_Notes by Jitendra Sir

    90/125

    Cideo

    ee also

    3his command is useful to "nd out the following information

    5 3ime of last system boot

    0 :urrent run le%el

    D 1ist of logged in users and more

    "urpose

    !isplay )ho is on the system'

    Syntax

    'he %asic s!ntax is as follo#s:

    whowho am i

    who Do#tionsE D=ileEwho ))hel#who ))6ersionwho H gre# J1serNameBereJ

    ;here,

    7f no non-options pro%ided, who displays the following information for each usercurrently logged on

    o login name

    o terminal line

    o login time

    o remote hostname or display

    7f you gi%e one non-option argument, who uses that instead of a default system-maintained "le such s %arrunutmp as the name of the "le containing the recordof users logged on

    7f gi%en two non-option arguments, who prints only the entry for the user runningit preceded by the hostname 3raditionally, the two arguments gi%en are 'am i', asin 'who am i'

    'ho command examples

    'o sho# a list of all the users currentl! logged in to the s!ste", t!e:$ who

    2a"le oututs:

    http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#11http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#12http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#11http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/#12
  • 8/11/2019 Linux_Notes by Jitendra Sir

    91/125

    -ig. 1: 3dentif!ing #ho is logged on !our ser$er

    3he sample output in this e+ample shows that the user %i%e$ is logged in on ptsE, and

    has been on since 5F5E on 0G 9anuary 3o display line of column headings pass the )B

    option

    $ who )B3o show only hostname and user associated with stdin (usually $eyboard), enter$ who )m

    3o show acti%e processes spawned by init$ who )#

    3o show user's message status as H, - or I, enter$ who )T

    Sho' or list users lo%%ed in

    '!e the co""and:

    $ who )1

    Sho' time of last system +oot

    'o disla! ti"e of last s!ste" %oot ass the )botion to #ho co""and:$ who )b

    2a"le oututs:

    system boot '!()!)5 !:'

    'he outut in this exa"le, sho#s that the s!ste" #as %ooted since 1:6 on Januar!.

    http://www.cyberciti.biz/faq/unix-linux-who-command-examples-syntax-usage/who-command-output/
  • 8/11/2019 Linux_Notes by Jitendra Sir

    92/125

    Sho' dead processes on the system

    ]ou need ass the )dotion to #ho co""and:$ who )d

    R$ who )d )B

    2a"le oututs:

    N",; LIN; TI,; I*L; PI* O,,;NT ;FIT #ts/! '!()!)!! 4:!7 524( idCts/! termC e9itC

    #ts/' '!()!)5 !5:(2 !!7 idCts/' termC e9itC #ts/' '!()!)& %:%! %2!( idC/' termC e9itC #ts/! '!()!)!! !2:5( 2(554 idC/! termC e9itC #ts/% '!()!)!! !7:!% !5&!& idC/% termC e9itC #ts/( '!()!)'5 !!:' (2&7 idCts/( termC e9itC

    Sho' system lo%in processes

    'o /ust disla! s!ste" login rocesses ass the )lotion:$ who )l

    R$ who )l )B

    2a"le oututs:

    N",; LIN; TI,; I*L; PI* O,,;NTLO>IN tty' '!()!)5 !:% &75 idC'LO>IN tty! '!()!)5 !:% &7(& idC!LO>IN tty% '!()!)5 !:% &75' idC%LO>IN /de6/tty+! '!()!)5 !:% &7(7 idC6/ttLO>IN tty( '!()!)5 !:% &75( idC(LO>IN tty5 '!()!)5 !:% &752 idC5LO>IN tty2 '!()!)5 !:% &75& idC2

    Count all lo%in names and num+er of users lo%%ed on the system

    'o count all login na"es and nu"%er of users logged on:$ who )

    2a"le oututs:

    -ig.6: (isla!ing and counting all users logged on

    Display the current runlevel

    'o disla! the current s!ste" runle$el, t!e:$ who )r

    2a"le oututs:

    r1n)le6el % '!()!)5 !:'

    http://www.cyberciti.biz/howto/question/linux/unix-linux-find-out-runlevel.phphttp://www.cyberciti.biz/faq/?attachment_id=18464http://www.cyberciti.biz/howto/question/linux/unix-linux-find-out-runlevel.php
  • 8/11/2019 Linux_Notes by Jitendra Sir

    93/125

    ]ou can co"%ine )r and )botions as follo#s:$ who )r )b

    2a"le oututs:

    system boot '!()!)5 !:' r1n)le6el % '!()!)5 !:'

    Display all

    'he )ais sa"e as sa"e as )bd#rtT1otions as discussed earlier:

    2a"le oututs:N",; LIN; TI,; I*L; PI* O,,;NT ;FIT system boot '!()!)5 !:' r1n)le6el % '!()!)5 !:'LO>IN tty' '!()!)5 !:% &75 idC'LO>IN tty! '!()!)5 !:% &7(& idC!LO>IN tty% '!()!)5 !:% &75' idC%LO>IN /de6/tty+! '!()!)5 !:% &7(7 idC6/ttLO>IN tty( '!()!)5 !:% &75( idC(LO>IN tty5 '!()!)5 !:% &752 idC5LO>IN tty2 '!()!)5 !:% &75& idC2root G #ts/ '!()!)'7 %:%7 0 !!!(4 -!0!020!' #ts/! '!()!)!! 4:!7 524( idCts/! termC e9itC

    #ts/' '!()!)5 !5:(2 !!7 idCts/' termC e9itC #ts/' '!()!)& %:%! %2!( idC/' termC e9itC #ts/! '!()!)!! !2:5( 2(554 idC/! termC e9itC #ts/% '!()!)!! !7:!% !5&!& idC/% termC e9itC #ts/( '!()!)'5 !!:' (2&7 idCts/( termC e9itC

    'ho command options

    ;ptio

    n6escription

    -a ame as -b -d --login -p -r -t -3 -u

    -b 3ime of last system boot

    -d !rint dead processes

    -H !rint line of column headings

    -l !rint system login processes

    -m;nly hostname and user associated

    with stdin

    -p !rint acti%e processes spawned by init

    -qll login names and number of users

    logged on

    -r !rint current runle%el

    -t !rint last system cloc$ change

    -T dd user's message status as H, - or I

  • 8/11/2019 Linux_Notes by Jitendra Sir

    94/125

    -u 1ist users logged in

    Linux )hoco""and sho#s #ho is logged on to the s!ste". 'his is a useful co""and for a Linuxs!ste" ad"inistrator %ecause the! can check ho# "an! users currentl! logged in the s!ste" and #ho

    the! are. 'he Linux #ho co""and offers so"e otions that user can use to see "ore details a%outusers such as login ti"e, ter"inal used and rocess id. >o#e$er that is not the onl! things the #hoco""and can do. ;e can also use Linux #ho co""and to check #hen #as the Linux s!ste" last%ooted and the current s!ste"_s run le$el.

    Linux 'ho command examples

    ;e alread! kno# #hat Linux #ho co""and can do, no# it_s ti"e to see so"e exa"les. Belo# arethe Linux #ho co""and exa"les run #ith otions regularl! used %! s!ste" ad"inistrator.

    Pro%a%l! the #ell kno#n Linux #ho co""and_s otion is the am i. ;hen in$oke )ho am ifro" aLinux co""and line ter"inal IN tty5 '4)7)2 !4:!7 ((%' idC5

    LO>IN tty( '4)7)2 !4:!7 ((%! idC(

    LO>IN tty2 '4)7)2 !4:!7 (((! idC2

    LO>IN tty' '4)7)2 !4:!7 ((%& idC'

    Linux #ho co""and rint s!ste" login rocesses. (on_t get confuse #ith this otion. ;hen runningwho :l, _#ho_ list onl! the entries that corresond to rocesses $ia #hich the s!ste" is #aiting for auser to login. 'he user na"e is al#a!sOJI+.

    Linux #ho 9" co""and exa"le:

  • 8/11/2019 Linux_Notes by Jitendra Sir

    95/125

    l1Kar@1b1nt1:~$ who )m

    l1Kar #ts/ '4)7)2 '!:'& -:0

    'he Linux #ho 9" co""and rints onl! hostna"e and user associated #ith stdin. 3t the sa"e asrunning who am ico""and.

    Linux #ho 9V co""and exa"le:

    l1Kar@1b1nt1:~$ who )

    root l1Kar l1Kar 1sersC%

    'he Linux #ho 9V co""and rints all login na"es and the nu"%er of users logged on. Using 9Votion #ill o$errides all other otions.

    Linux #ho 9r co""and exa"le:

    l1Kar@1b1nt1:~$ who )r

    r1n)le6el ' '4)7)2 !4:!7 lastC

    'he Linux #ho 9r co""and rints s!ste"_s current runle$el.

    Linux #ho 9' co""and exa"le:

    l1Kar@1b1nt1:~$ who )T

    root ) tty! '4)7)2 '':2

    l1Kar G tty7 '4)7)2 !4:!7 -:

    l1Kar G #ts/ '4)7)2 '!:'& -:0

    +fter each login na"e, Linux #ho 9' co""and rints a character indicating the user_s "essage status,#hich:

    H means allowing `write' messages

    - means disallowing `write' messages

    I means cannot "nd terminal de%ice

    Linux #ho 9u co""and exa"le:

    l1Kar@1b1nt1:~$ who )1

    root tty! '4)7)2 '':2 :7 5(25

    l1Kar tty7 '4)7)2 !4:!7 old 552 -:

    l1Kar #ts/ '4)7)2 '!:'& 0 254 -:0

    'he Linux #ho 9u co""and lists users logged in. +fter the login ti"e, the #ho co""and rints thenu"%er of hours and "inutes that the user has %een idle.

    9means the user was acti%e in the last minute

    oldmeans the user has been idle for more than 0F hours

    Linux #ho 9% co""and exa"le:

    l1Kar@1b1nt1:~$ who )b

    system boot '4)7)2 !4:!7

    'he Linux #ho 9% co""and rints the date and ti"e of last s!ste" %oot.

  • 8/11/2019 Linux_Notes by Jitendra Sir

    96/125

    Linux #ho 9a co""and exa"le:

    l1Kar@1b1nt1:~$ who )a

    system boot '4)7)2 !4:!7

    r1n)le6el ' '4)7)2 !4:!7 lastC

    LO>IN tty% '4)7)2 !4:!7 ((%4 idC%

    LO>IN tty5 '4)7)2 !4:!7 ((%' idC5

    LO>IN tty( '4)7)2 !4:!7 ((%! idC(

    LO>IN tty2 '4)7)2 !4:!7 (((! idC2

    LO>IN tty' '4)7)2 !4:!7 ((%& idC'root ) tty! '4)7)2 '':2 :%' 5(25

    l1Kar G tty7 '4)7)2 !4:!7 old 552 -:

    l1Kar G #ts/ '4)7)2 '':%4 0 24%& -:0

    'he Linux #ho 9a co""and is the sa"e as in$oke )ho 3b 3d 33login 3p 3r 3t 39 3u.

    Linux / Unix Command: who

    Command Library

    !AM*who - show who is logged on

    S!O"S#S'ho[OPTION] [ FILE | ARG1 ARG2 ]

    D*SC-#"1#O!&a, &&all

    same as &+&d&&lo%in&p&r&t&1&u

    &+, &&+oot

    time of last system boot

    &d, &&dead

    print dead processes

    &2, &&headin%

    print line of column headings

    &i, &&idle

    add idle time as J;2BK7>23A, or old (deprecated, use &u)

    &&lo%in

    print system login processes (e4ui%alent to 2 &l)

    &l, &&loo3up

    http://linux.about.com/library/cmd/blcmdl.htmhttp://linux.about.com/library/cmd/blcmdl.htm
  • 8/11/2019 Linux_Notes by Jitendra Sir

    97/125

    attempt to canonicali=e hostnames %ia 6> (-l is deprecated, use &&loo3up)

    &m

    only hostname and user associated with stdin

    &p, &&process

    print acti%e processes spawned by init

    &4, &&count

    all login names and number of users logged on

    &r, &&runlevel

    print current runle%el

    &s, &&short

    print only name, line, and time (default)

    &t, &&time

    print last system cloc$ change

    &1, &', &&mes%

    add user's message status as H, - or I

    &u, &&users

    list users logged in

    &&messa%e

    same as &1

    &&'rita+le

    same as &1

    &&help

    display this help and e+it

    &&version

    output %ersion information and e+it

    3f -3LE is not secified, use @$ar@run@ut". @$ar@log@#t" as -3LE is co""on. 3f +R01 +R06 gi$en,3mresu"ed: Xa" i_ or X"o" likes_ are usual.

  • 8/11/2019 Linux_Notes by Jitendra Sir

    98/125

    1he 'hatis Command

    'he whatisco""andro$ides $er! %rief descritions of command lineprogramso#e$er, aroos is "oreo#erful in that its argu"ents are not li"ited to co"lete #ords %ut can also%estrings

  • 8/11/2019 Linux_Notes by Jitendra Sir

    99/125

    is generated auto"aticall! %! the maewhatisrogra". 3ts location $ariesaccording to the articular s!ste"8 in the case of Red >at Linux), forexa"le, its full athis @$ar@cache@"an@#hatis.

    3f desired, the data%ase can %e $ie#ed using a co""and such as thefollo#ing:

    cat /6ar/cache/man/whatis H less

    3n this co""and the outut of cat "ar"cache"man"whatisispipedormally, output will be

    truncated to the terminal width to a%oid ugly results from poorly-

    http://www.linfo.org/linuxdef.htmlhttp://www.linfo.org/absolute_pathname.htmlhttp://www.linfo.org/pipes.htmlhttp://www.computerhope.com/unix/uman.htmhttp://www.computerhope.com/jargon/w/wildcard.htmhttp://www.computerhope.com/jargon/r/regex.htmhttp://www.computerhope.com/jargon/r/regex.htmhttp://www.computerhope.com/jargon/s/shell.htmhttp://www.computerhope.com/jargon/d/database.htmhttp://www.computerhope.com/jargon/c/cron.htmhttp://www.linfo.org/linuxdef.htmlhttp://www.linfo.org/absolute_pathname.htmlhttp://www.linfo.org/pipes.htmlhttp://www.computerhope.com/unix/uman.htmhttp://www.computerhope.com/jargon/w/wildcard.htmhttp://www.computerhope.com/jargon/r/regex.htmhttp://www.computerhope.com/jargon/s/shell.htmhttp://www.computerhope.com/jargon/d/database.htmhttp://www.computerhope.com/jargon/c/cron.htm
  • 8/11/2019 Linux_Notes by Jitendra Sir

    100/125

    written >KA sections

    &slist, &&sections

    list, &&sectionlist

    earch only the gi%en manual sections listis a colon- or comma-

    separated list of sections 7f an entry in listis a simple section, for

    e+ample 8

  • 8/11/2019 Linux_Notes by Jitendra Sir

    101/125

    *nvironment

    SS1*M7f SS1*Mis set, it will ha%e the same eMect as if it had been speci"ed as

    the argument to the &moption

    MA!"A1

    2

    7f MA!"A12is set, its %alue is interpreted as the colon-delimited manual

    page hierarchy search path to use

    MA!G#D12

    7f MA!G#D12is set, its %alue is used as the terminal width (see the &&lon%

    option) 7f it is not set, the terminal width will be calculated using an ioctlifa%ailable, the %alue of COLUM!S, or falling bac$ to NE characters if all else

    fails

    *xampleswhatis whatis

    #9 Linux 'hatis Command

    ;hatis co""and is helful to get %rief infor"ation a%out Linux co""ands or functions. ;hatisco""and disla!s "an age single line descrition for co""and that "atches string assed as a

    co""and line argu"ent to #hatis co""and. ;hatis co""and searches for string in its indexdata%ases #hich is "aintained %! "and% rogra". ;hatis co""and icks short descrition of N+4Esection of "an age of co""and that "atches to inut gi$en to the #hatis co""and.

    ;hatis ro$ides se$eral co""and line otions to hel user in getting %rief infor"ation of secificLinux co""ands as er their need or interest.

    2!ntax:

    $ whatis D)o#tionsE

    -or exa"le, here is the outut of #hatis co""and, #hen it is run #ithout an! otion.

    $ whatis write

    write -! ) send a message to another 1serwrite -' ) write to a file descri#tor

    3t disla!s %rief infor"ation a%out #riteS fro" "an ages.

    /' \et inormation rom speciic sections o man pages using 3s option

    3f #e #ant to get Linux co""and infor"ation fro" secific section of "an ages, then #e canro$ide sections list using 9s or sections or sectionS otion. 3t #ill restrict #hatis co""and todisla! %rief infor"ation fro" secified "an age section onl!.

    $ whatis )s !3' o#eno#en -! ) start a #rogram on a new 6irt1al terminal -T0o#en -' ) o#en and #ossibly create a file or de6ice

    3t disla!s oen co""and and function %rief infor"ation fro" "an age sections 1 and 6.

    $ whatis )s ' o#eno#en -' ) o#en and #ossibly create a file or de6ice

    3t disla!s oen function %rief infor"ation fro" "an age section 6.

    1' Search inormation through )ild3cards using 3) option

    3f #e #ant to search Linux co""ands or functions infor"ation using #ild card, then #hatis co""andgi$es 9# or #ildcardS otion. 3t #ill "ake !our search secific as er userQs need.

    $ whatis )w JabMJ

  • 8/11/2019 Linux_Notes by Jitendra Sir

    102/125

    abort -% ) ca1se abnormal #rocess terminationabs -% ) com#1te the absol1te 6al1e of an integer

    3t disla!s %rief infor"ation of Linux co""ands or functions #hich start fro" a%S.

    $ whatis )w JabJabs -% ) com#1te the absol1te 6al1e of an integer

    3t disla!s %rief infor"ation of Linux co""ands or functions #hich start fro" a%S and follo#ed %!an! single character.

    M' Search inormation through regular expressions using 3r option

    3f #e #ant to search Linux co""ands or functions infor"ation using regular exressions, then #hatisco""and gi$es 9r or regexS otion. 3t #ill gi$e flexi%ilit! to custo"ie !our search for Linuxco""ands or functions throughout the Linux s!ste".

    $ whatis )r JQabJabort -% ) ca1se abnormal #rocess terminationabs -% ) com#1te the absol1te 6al1e of an integer

    3t disla!s %rief infor"ation of Linux co""ands or functions #hich start fro" a%S.

    $ whatis )r Jab$Janacrontab -5 ) config1ration file for anacron

    baobab -! ) " gra#hical tool to analyse disk 1sagecrontab -! ) maintain crontab files for indi6id1al 1sers -i9ie roncrontab -5 ) tables for dri6ing cronfstab -5 ) static information abo1t the filesystemsinittab -5 ) init daemon config1rationswab -% ) swa# adacent bytestc)stab -& ) >eneric siKe table mani#1lations

    3t disla!s %rief infor"ation of Linux co""ands or functions #hich ends #ith a%S.

    N' !isable trimmed output using 3l option

    0enerall! #hatis co""and tri"s long outut of Linux co""ands or functions infor"ation to a$oidNot goodS outut disla! on ter"inal that is going %e!ond screen. 'o allo# #hatis co""and to sho#co"lete outut on screen, 9l or longS otion can %e used.

    $ whatis ssh)im#ort)idssh)im#ort)id -! ) retrie6e one or more #1blic keys from a #1blic keyser6er-La1nch#ad0net by defa1lt and a##end them to the c1rrent 1serJs a1thoriKedRkeysfile -or some other s#ecifie000

    3t disla!s tri""ed outut of %rief infor"ation of Linux co""and.

    $ whatis )l ssh)im#ort)idssh)im#ort)id -! ) retrie6e one or more #1blic keys from a #1blic keyser6er-La1nch#ad0net by defa1lt and a##end them to the c1rrent 1serJs a1thoriKedRkeysfile -or some other s#ecified file

    3t disla!s co"lete outut of %rief infor"ation of Linux co""and.

    D' 8estrict search up to speciied path using 35 option

    B! default, #hatis co""and uses 4+NP+'> en$iron"ent $aria%le. But #hatis ro$ides 94 or "anathS otion to restrict search u to secified ath of "an ages.

    $ whatis ), /1sr/share/man he9d1m#he9d1m# -! ) "+II3 decimal3 he9adecimal3 octal d1m#

    3t disla!s %rief infor"ation of Linux hexdu" co""and fro" "an ages a$aila%le at ath@usr@share@"an.

    $ whatis ), /1sr/man he9d1m#

  • 8/11/2019 Linux_Notes by Jitendra Sir

    103/125

    he9d1m#: nothing a##ro#riate0

    3t could not find %rief infor"ation of Linux hexdu" co""and fro" secified ath @usr@"an.

    II' Linux )hereis Command

    ;hereis co""and is helful tolocate%inar!, source and "anual ages of co""ands in the Linuxs!ste". 3t is $er! si"le utilit! and ro$ides se$eral otions #hich are gi$en %elo# #ith exa"les.

    2!ntax:$ whereis D)o#tionsE

    -or exa"le, #hereis co""and is run #ithout an! otion.

    $ whereis o#eno#en: /bin/o#en /1sr/share/man/man!/o#en0!0gK /1sr/share/man/man'/o#en0'0gK

    3t locates %inar!, source and "an ages of oenS co""and and here it disla!ed aths #here %inar!,"an ages of oen co""and is a$aila%le in the s!ste".

    ' Locate binaries using 3b option

    3f #e #ant to locate %inar! of Linux co""and, use 9%S otion.

    $ whereis )b whereiswhereis: /1sr/bin/whereis /1sr/bin/F!!/whereis

    3t locates %inar! of #hereisS co""and and disla!s aths #here %inar! of co""and is a$aila%le inthe s!ste".

    P' Locate man pages or a command using 3m option

    3f #e #ant to locate "an age of Linux co""and, use 9"S otion.

    $ whereis )m whereiswhereis: /1sr/share/man/man!/whereis0!0gK

    3t locates "an age of #hereisS co""and and disla!s ath #here "an age of co""and is

    a$aila%le in the s!ste".

    _' Locate source o a command using 3s option

    3f #e #ant to locate source of Linux co""and, use 9sS otion.

    $ whereis )s whereiswhereis:

    3t locates source of #hereisS co""and, %ut source of #hereisS co""and does not exist in thes!ste", so it did not disla! ath for source of co""and in the s!ste".

    O' Locate unusual entries using 3u option

    'his otion is so"ething different that searches for unusual entries. 'hese entries are those co""and#hose source, %inar! or "an age does not exist in the s!ste" as er otions 9%"sFS secified along#ith uS.

    $ whereis )m )1 wcgre#wcgre#:

    3t checks if secified co""and

  • 8/11/2019 Linux_Notes by Jitendra Sir

    104/125

    >ere, #hereis co""and #ith sa"e otions is alied on greS co""and #hose "an age exists inthe s!ste", so #hereis returned nothing and exits nor"all!.

    /0' Locate binaries in a speciied path using 3H option

    3f user #ants to search for %inar! and #ants to li"it the scoe of search for #hereis co""and u tosecified ath, then use 9BS otion.

    $ whereis )S /bin )f forRloo#forRloo#: /bin/forRloo#

    3t locates %inar! of for?looS user rogra" fro" ath @%inS.

    $ whereis )S /1sr )f o#eno#en: /1sr/share/man/man!/o#en0!0gK /1sr/share/man/man'/o#en0'0gK

    3f oen co""andQs %inar! is not found at secified ath, then it is not sho#n %ut #hereis co""and %!default searches for other t!es ere, it is o%ser$ed that #hereis co""and is disla!ing "an age of oenS co""and #hich isa$aila%le in secified ath onl!. But, #hereis co""and %! default searches for other t!es

  • 8/11/2019 Linux_Notes by Jitendra Sir

    105/125

    +%o$e #ill search disla! the executa%le echoS fro" all aths set in P+'> en$iron"ent $aria%leand disla!s the first ath #here echo executa%le is found. 3t "a! %e case that executa%le is laced atother aths of P+'> en$iron"ent $aria%le as #ell. 'o get all aths #here executa%le is resent in thes!ste", 9aS otion can %e used.

    $ which )a echo/1sr/sbin/echo/bin/echo

    D

    !AM*whatis - search the whatis database for complete words

    S!O"S#S'hatis$eyword

    D*SC-#"1#O!whatis searches a set of database "les containing short descriptions of system

    commands for $eywords and displays the result on the standard output ;nly complete

    word matches are displayed

    'he #hatis data%ase is created using the co""and @usr@s%in@"ake#hatis.

    'hatis

    )hatisdisla!s short "an age descritions. Unlike

    %6amples5

    $whatis infoinfo -! ) read Info doc1mentsinfo -5 ) readable online doc1mentation$whatis chmodchmod -! ) change file modeschmod3 fchmod -' ) change mode of file

    Ghat is 'hereis 6

    ;hereis co""and is used to find out #here the %inar!, source, and "an age files for a co""and islocated.

    7 #hereis Exa"les

    Find 'hereis a U!#H command

    ;hen !ou #ant to find out #here a secific Unix co""and exists

  • 8/11/2019 Linux_Notes by Jitendra Sir

    106/125

    ls: /bin/ls /1sr/share/man/man!/ls0!0gK /1sr/share/man/man!#/ls0!#0gK

    Find 'hereis a U!#H command executa+le is located

    ;hen !ou #ant to kno# onl! #here the executa%le for a secific co""and is a$aila%le, use 9% otion.'his is "ore hand!, and !ou are "ost likel! %e using #hereis co""and to find out the location ofonl! executa%les.

    $ whereis )b lsls: /bin/ls

    Chan%e the search location of 'hereis command

    ;hen !ou #ant to search an executa%le fro" a ath other than the #hereis default ath, !ou can use9B otion and gi$e ath as argu"ent to it.

    $ whereis )1 )S /tm# )f lsmklsmk: /tm#/lsmk

    'his searches for the executa%le ls"k in the @t" director!, and disla!s it, if it is a$aila%le.

    Syntax and Options

    Short

    Option Option Description

    -b earch only for binaries

    -m earch only for manual sections

    -s earch only for sources

    -u

    earch for unusual entries "le is said to be unusual if it does not ha%e one entry

    of each re4uested type 3hus Owhereis -m -uP as$s for those "les in the current

    directory which ha%e no documentation

    -L :hange or otherwise limit the places where whereis searches for binaries

    -K :hange or otherwise limit the places where whereis searches for manual sections

    - :hange or otherwise limit the places where whereis searches for sources

    -f

    3erminate the last directory list and signals the start of "le names, and must be

    used when any of the -L, -K, or - options are used

    A+out 'hereis

    Locates the%inar!, source, and "anualage files for a co""and.

    Syntaxwhereis D)bms1E D)S,+ directory000 )fE filename000

    Description

    )hereislocates source@%inar! and "anuals sections for secified files. 'he sulied na"es arefirst stried of leadingathna"eco"onents and an!

  • 8/11/2019 Linux_Notes by Jitendra Sir

    107/125

    ^'ext^, for exa"le, ^'c^. Prefixes of ^s'^ resulting fro" use of source code control are alsohandled. )hereisthen atte"ts to locate the desired rogra" in a list of standard Linuxlaces.

    Options

    &+ earch only for binaries

    &

    mearch only for manual sections

    &s earch only for sources

    &u

    earch for unusual entries "le is said to be unusual if it does not ha%e one

    entry of each re4uested type @or e+ample, 8'hereis &m &u I8 as$s for those

    "les in the current directorywhich ha%e no documentation

    &B:hange or otherwise limit the places where 'hereissearches for binaries

    &

    M

    :hange or otherwise limit the places where whereis searches for manual

    sections

    &S :hange or otherwise limit the places where whereis searches for sources

    &f3erminate the last directory list and signals the start of "le names, and must be

    used when any of the &B, &M, or &Soptions are used

    *xampleswhereis #erl

    List the directories #here the perlsource files, docu"entation, and %inaries are stored.

    whereis )1 ), /1sr/man/man! )+ /1sr/src )f M

    -ind all files in the current director! #hich are not docu"ented in 7usr7man7man/, #hosesource resides in 7usr7src.

    a" a ne# Linux and Unix9like s!ste" co""and line user. >o# do 3 find and locate the %inar!,source, and "anual age files for a gi$en co""and

    ]ou need to use the whereisco""and to find the source, %inar!, and "anuals sections for

    secified co""ands or files.

    'hereis command

    details

    6escription1ocating command or

    program

    :ategory earching

    6iculty Aasy

    Boot pri%ileges >o

    Astimated completion 5Em

    http://www.computerhope.com/jargon/l/linux.htmhttp://www.computerhope.com/jargon/c/currentd.htmhttp://www.computerhope.com/jargon/p/perl.htmhttp://www.cyberciti.biz/faq/linux-unix-commands/searching/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/http://www.computerhope.com/jargon/l/linux.htmhttp://www.computerhope.com/jargon/c/currentd.htmhttp://www.computerhope.com/jargon/p/perl.htmhttp://www.cyberciti.biz/faq/linux-unix-commands/searching/http://www.cyberciti.biz/faq/tutorial-difficulty-level/easy/
  • 8/11/2019 Linux_Notes by Jitendra Sir

    108/125

    time

    Contents

    ynta+

    A+amples

    earch only for binaries

    earch only for manual sections

    earch only for sources

    earches for unusual "les

    1imit the searches for binaries to speci"cdirectories

    ;ptions

    ee also

    binary is nothing but an e+ecutable from of a command such as ls or program

    such as Qimp 2se this command to "nd out

    5 3he location of a binary "le

    0 3he location of source code

    D 3he location of man page

    "urpose

    -ind the binary< source code and man pagefor secified rogra" or co""and.

    Syntax

    'he %asic s!ntax is as follo#s:

    whereis command

    R

    whereis #rogram

    R

    whereis Do#tionsE #rogram

    R

    whereis )S,+ directory )f command

    'hereis command examples

    'o find out the location of the executa%le, source code and "an age for the date co""and,t!e:$ whereis date

    http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#1http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#2http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#3http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#4http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#5http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#6http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#7http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#7http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#8http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#9http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#1http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#2http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#3http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#4http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#5http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#6http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#7http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#7http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#8http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/#9
  • 8/11/2019 Linux_Notes by Jitendra Sir

    109/125

    2a"le oututs:

    +ni"ated gif 1: #hereis co""and running on "! (e%ian %ased ser$er

    2o' do # only search for +inary $les6

    Pass the )botion as follo#s:$ whereis )b date

    2o' do # only search for manual sections $les6

    Pass the )motion as follo#s:$ whereis )m date

    2o' do # only search for source code $les6

    Pass the )sotion as follo#s:$ whereis )s date

    2o' do # only Search for unusual entries6

    + file is said to %e unusual if it does not ha$e one entr! of each reVuested t!e. 'hus thefollo#ing exa"le, asks for those files in the current director! #hich ha$e no docu"entation:$ whereis )m )1 M

    2o' can # limit the searches for +inaries to speci$c directories6

    ]ou can ass the follo#ing otion to li"it li"it the laces #here #hereis searches for files:

    -B /path/to/dir 1imit the places where whereis searches for binaries

    -M /path/to/dir 1imit the places where whereis searches for manual

    http://www.cyberciti.biz/faq/unix-linux-whereis-command-examples-to-locate-binary/whereis-command-demo/
  • 8/11/2019 Linux_Notes by Jitendra Sir

    110/125

    sections

    -S /path/to/dir 1imit the places where whereis searches for sources

    ]ou "ust ass the )fotion #hen an! of the 9B, 94, or 92 otions are used. 'he )fotion

    ter"inate the last director! list and signals the start of file na"es. 3n this exa"le, li"it searchfor %inar! files in @%in@ director! onl! for ls and gcc co""ands:$ whereis )S /bin )f ls gcc

    2a"le oututs:ls: /bin/ls /1sr/share/man/man!/ls0!0gKgcc:

    'here is no outut for the gcc co""and since it is located in @usr@%in@ director!. 'o find all ofthe files in the @s%in@ director! that either are not docu"ented in the @usr@"an@"anO director! ordo not ha$e source in the @root@src director!, enter: cd /sbin whereis )1 ), /1sr/man/man&/ )+ /root/src/ )f M

    'hereis command options

    -ro" the #hereis

  • 8/11/2019 Linux_Notes by Jitendra Sir

    111/125

    S!O"S#S'hereis[ &+msu] [ &BMS#ire!tory &f] "lename

    D*SC-#"1#O!'hereislocates sourcebinary and manuals sections for speci"ed "les 3he

    supplied names are "rst stripped of leading pathname components and any

    (single) trailing e+tension of the form 9e$t%for e+ample, 9c !re"+es of s9resultingfrom use of source code control are also dealt with 'hereisthen attempts to

    locate the desired program in a list of standard 1inu+ places

    O"1#O!S&+

    Search only for +inaries9

    &m

    earch only for manual sections

    &s

    earch only for sources

    &u

    earch for unusual entries "le is said to be unusual if it does not ha%e one

    entry of each re4uested type 3hus `'hereis &m &u I' as$s for those "les

    in the current directory which ha%e no documentation

    &B

    :hange or otherwise limit the places where 'hereissearches for binaries

    &M

    :hange or otherwise limit the places where 'hereissearches for manual

    sections

    &S

    :hange or otherwise limit the places where 'hereissearches for sources

    &f

    3erminate the last directory list and signals the start of "le names, and must

    be used when any of the &B, &M, or &Soptions are used

    *HAM"L*

    ind all files in 7usr7bin#hich are not docu"ented in 7usr7man7man/#ith source in 7usr7src:example% cd /usr/bin

  • 8/11/2019 Linux_Notes by Jitendra Sir

    112/125

    example% whereis -u -M /usr/man/man1 -S /usr/src -f

    'he whereisco""andis used to locate the /inary,thesource codeand the online manual pagefor an! secifiedrogra".

    + %inar! is ane6ecuta/le

  • 8/11/2019 Linux_Notes by Jitendra Sir

    113/125

    files=, at least on so"e s!ste"s, as can %e seen %! running the follo#ing:

    whereis s#ell

    2e$eral otions are a$aila%le to li"it the t!e of results returned %! #hereis

  • 8/11/2019 Linux_Notes by Jitendra Sir

    114/125

    &&s3ip&alias

    7gnore option `--read-alias', if any 3his is useful to e+plicity search for

    normal binaries, while using the `--read-alias' option in an alias or function

    for which

    &&read&functions

    Bead shell function de"nitions from stdin, reporting matching ones on

    stdout 3his is useful in combination with using a shell function for which

    itself @or e+ample

    'hich() declare &f J 'hich &&read&functions

    e+port -f which

    &&s3ip&functions

    7gnore option `--read-functions', if any 3his is useful to e+plicity search for

    normal binaries, while using the `--read-functions' option in an alias or

    function for which

    &&s3ip&dot

    $ip directories in "A12that start with a dot

    &&s3ip&tilde

    $ip directories in "A12that start with a tilde and e+ecutables which reside

    in the 2OM*directory

    &&sho'&dot

    7f a directory in "A12starts with a dot and a matching e+ecutable was

    found for that path, then print 8programname8 rather than the full path

    &&sho'&tilde

    ;utput a tilde when a directory matches the 2OM*directory 3his option is

    ignored when which is in%o$ed as root

    &&tty&only

    top processing options on the right if not on tty

    &&version&v&,

    !rint %ersion information on standard output then e+it successfully

    &&help

    !rint usage information on standard output then e+it successfully

    -*1U-! ,ALU*Ghichreturns the number of failed arguments, or -5 when no `programname' was

  • 8/11/2019 Linux_Notes by Jitendra Sir

    115/125

    gi%en

    *HAM"L*3he recommended way to use this utility is by adding an alias (: shell) or shell

    function (Lourne shell) for 'hichli$e the following

    %aFsh:

    which - -aliasU declare )f H /1sr/bin/which ))tty)only ))read)alias ))read)f1nctions ))show)tilde ))show)dot $@Ve9#ort )f which

    tFcsh:

    alias which Jalias H /1sr/bin/which ))tty)only ))read)alias ))show)dot))show)tildeJ

    'his #ill rint the reada%le I@ and .@ #hen starting #hich fro" !our ro"t, #hile still rintingthe full ath #hen used fro" a scrit:

    which '~/bin/' echo Wwhich 'W/home/carlo/bin/'

    8; Linux Ghich Command Ghatis Command

    Ghereis Command *xamples

    %! >i"anshu +rora on +ril 67, 617

    'his Linux tutorial #ill exlain the three ;S co""ands. 'he three ;Ss are #hatis, #hereisand #hich co""ands.

    ]ou alread! kno# ho# to use find co""andto efficientl! fo find a file.

    No#, these three ; co""ands #ill hel !ou to locate "ore stuff fro" Linux co""and line.

    #9 Linux 'hatis Command

    ;hatis co""and is helful to get %rief infor"ation a%out Linux co""ands or functions.;hatis co""and disla!s "an age single line descrition for co""and that "atches string

    assed as a co""and line argu"ent to #hatis co""and. ;hatis co""and searches for stringin its index data%ases #hich is "aintained %! "and% rogra". ;hatis co""and icks shortdescrition of N+4E section of "an age of co""and that "atches to inut gi$en to the#hatis co""and.

    ;hatis ro$ides se$eral co""and line otions to hel user in getting %rief infor"ation ofsecific Linux co""ands as er their need or interest.

    2!ntax:

    $ whatis D)o#tionsE

    http://www.thegeekstuff.com/2009/03/15-practical-linux-find-command-examples/
  • 8/11/2019 Linux_Notes by Jitendra Sir

    116/125

  • 8/11/2019 Linux_Notes by Jitendra Sir

    117/125

    small so that you can lea%e it running throughout your entire login session 7n the

    initial window there are three options (elwill pop up a window with on-line help,

    )uitwill e+it, and *anual Pa+ewill pop up a window with a manual page browser

    in it 3yping :ontrol- will pop up a window prompting for a speci"c manual page

    to display Sou may display more than one manual page browser window at a time

    from a single e+ecution of$man

    -or further infor"ation on using6man, lease read the on9line hel infor"ation. 4ost of this

    "anual #ill discuss custo"iation of6man.

    Options

    A"an suorts all standard 'oolkit co""and line argu"ents = for "anual ages. 3f "anual ages exist in that director!then the! are added to list of "anual ages for the corresonding "enu ite". + "enu ite" isonl! disla!ed for those sections that actuall! contain "anual ages.

    *irectory +ection Name))))))))) ))))))))))))man! -! 8ser ommandsman' -' +ystem allsman% -% +1bro1tines

    http://www.x.org/archive/X11R7.5/doc/man/man1/xman.1.html#toc3http://www.x.org/archive/X11R7.5/doc/man/man1/xman.1.html#toc3http://www.x.org/archive/X11R7.5/doc/man/man1/X.1.htmlhttp://www.x.org/archive/X11R7.5/doc/man/man1/xman.1.html#toc4
  • 8/11/2019 Linux_Notes by Jitendra Sir

    118/125

    man( -( *e6icesman5 -5 =ile =ormatsman2 -2 >amesman7 -7 ,iscellaneo1sman& -& +ys0 "dministrationmanl -l Localmann -n Newmano -o Old

    @or instance, a user has three directories in her manual path and each contain a

    directory called man/ ll these manual pages will appear alphabetically sortedwhen the user selects the menu item called 0/u3routines 7f there is no directory

    called manoin any of the directories in her K>!3J, or there are no manual

    pages in any of the directories called manothen no menu item will be displayed

    for the section called 0oOl#

    Bsd and Linux Systems

    3n ne#er B2( and Linux s!ste"s,Kman#ill search for a file na"ed"etc"man.conf#hich #illcontain the list of directories containing "anual ages. 2ee man.conf

  • 8/11/2019 Linux_Notes by Jitendra Sir

    119/125

    5-5 =ile =ormats2-2 >ames7-7 ,iscellaneo1s&-& +ys0 "dministrationl-l Localn-n Newo-o Old

    man will read any section that is of the from man5!hara!ter6, where

    TcharacterU is an upper or lower case letter (they are treated distinctly) or a

    numeral (E-V) Le warned, howe%er, that man(5)and catman(N)will not searchdirectories that are non-standard

    Gid%ets7n order to specify resources, it is useful to $now the hierarchy of the widgets

    which compose$man 7n the notation below, indentation indicates hierarchical

    structure 3he widget class name is gi%en "rst, followed by the widget instance

    name

    Fman 9man (This widget is never used) To#Le6el+hell to#So9 =orm form Label to#Label ommand hel#S1tton ommand 1itS1tton ommand man#ageS1tton Transient+hell search *ialogAidgetlass dialog Label label Te9t 6al1e ommand man1alPage ommand a#ro#os

    ommand cancel Transient+hell #lease+tandSy Label label To#Le6el+hell man1alSrowser Paned ,an#ageR#ane Paned horiKPane ,en1S1tton o#tions ,en1S1tton sections Label man1alSrowser iew#ort directory List directory

    List directory0

    0 -one for each section30 created on the fly

    0 +crollSyLine man1alPage +im#le,en1 o#tion,en1 +meS+S dis#lay*irectory +meS+S dis#lay,an1alPage +meS+S hel# +meS+S search +meS+S showSoth+creens +meS+S remo6eThis,an#age +meS+S o#enNew,an#age +meS+S showersion +meS+S 1it

    http://www.x.org/archive/X11R7.5/doc/man/man1/xman.1.html#toc7http://www.x.org/archive/X11R7.5/doc/man/man1/man.1.htmlhttp://www.x.org/archive/X11R7.5/doc/man/man8/catman.8.htmlhttp://www.x.org/archive/X11R7.5/doc/man/man1/xman.1.html#toc7
  • 8/11/2019 Linux_Notes by Jitendra Sir

    120/125

    +im#le,en1 section,en1 +meS+S Xname of section 0 0 -one for each section 0 Transient+hell search *ialogAidgetlass dialog Label label Te9t 6al1e ommand man1alPage

    ommand a#ro#os ommand cancel Transient+hell #lease+tandSy Label label Transient+hell likeTo+a6e *ialog dialog Label label Te9t 6al1e ommand yes ommand no To#Le6el+hell hel# Paned ,an#ageR#ane Paned horiKPane

    ,en1S1tton o#tions ,en1S1tton sections Label man1alSrowser +crollSyLine man1alPage +im#le,en1 o#tion,en1 +meS+S dis#lay*irectory +meS+S dis#lay,an1alPage +meS+S hel# +meS+S search +meS+S showSoth+creens +meS+S remo6eThis,an#age +meS+S o#enNew,an#age +meS+S showersion +meS+S 1it

    Application -esources$manhas the following application-speci"c resources which allow customi=ations

    uni4ue to$man

    manualFont!ormal(:lass Font)

    3he font to use for normal te+t in the manual pages

    manualFontBold(:lass Font)

    3he font to use for bold te+t in the manual pages

    manualFont#talic(:lass Font)

    3he font to use for italic te+t in the manual pages

    directoryFont!ormal(:lass Font)

    3he font to use for the directory te+t

    +othSho'n(:lass Boolean)

    Aither `true' or `false,' speci"es whether or not you want both the directory

    http://www.x.org/archive/X11R7.5/doc/man/man1/xman.1.html#toc8http://www.x.org/archive/X11R7.5/doc/man/man1/xman.1.html#toc8http://www.x.org/archive/X11R7.5/doc/man/man1/xman.1.html#toc8
  • 8/11/2019 Linux_Notes by Jitendra Sir

    121/125

    and the manual page shown at start up

    directory2ei%ht(:lass Directory2ei%ht)

    3he height in pi+els of the directory, when the directory and the manual

    page are shown simultaneously

    topCursor(:lass Cursor)

    3he cursor to use in the top bo+

    helpCursor(:lass Cursor)

    3he cursor to use in the help window

    manpa%eCursor(:lass Cursor)

    3he cursor to use in the manual page window

    search*ntryCursor(:lass Cursor)

    3he cursor to use in the search entry te+t widget

    pointerColor(:lass Fore%round)

    3his is the color of all the cursors (pointers) speci"ed abo%e 3he name was

    chosen to be compatible with +term

    helpFile(:lass File)

    2se this rather than the system default help"le

    topBox(:lass Boolean)

    Aither `true' or `false,' determines whether the top bo+ (containing the help,

    4uit and manual page buttons) or a manual page is put on the screen at

    start-up 3he default is true

    verticalList(:lass Boolean)

    Aither `true' or `false,' determines whether the directory listing is %ertically

    or hori=ontally organi=ed 3he default is hori=ontal (false)

    :lo+al Actions'mande"nes all user interaction through global actions 3his allows the user tomodify the translation table of any widget, and bind any e%ent to the new user

    action 3he list of actions supported by$manare

    :oto"a%e(page)

    Rhen used in a manual page display window this will allow the user to mo%e

    between a directory and manual page display 3hea+eargument can be

    either Directoryor Manual"a%e

    http://www.x.org/archive/X11R7.5/doc/man/man1/xman.1.html#toc9http://www.x.org/archive/X11R7.5/doc/man/man1/GotoPage.p.htmlhttp://www.x.org/archive/X11R7.5/doc/man/man1/xman.1.html#toc9http://www.x.org/archive/X11R7.5/doc/man/man1/GotoPage.p.html
  • 8/11/2019 Linux_Notes by Jitendra Sir

    122/125

    uit()

    3his action may be used anywhere, and will e+it +man

    Search(type, action)

    ;nly useful when used in a search popup, this action will cause the search

    widget to perform the named search type on the string in the search

    popup's %alue widget 3his action will also pop down the search widget 3hetyeargument can be either Apropos, Manpa%eor Cancel 7f an a!tionof

    Openis speci"ed then +man will open a new manual page to display the

    results of the search, otherwise +man will attempt to display the results in

    the parent of the search popup

    "opup2elp()

    3his action may be used anywhere, and will popup the help widget

    "opupSearch()

    3his action may be used anywhere e+cept in a help window 7t will cause thesearch popup to become acti%e and %isible on the screen, allowing the user

    search for a manual page

    Create!e'Manpa%e()

    3his action may be used anywhere, and will create a new manual page

    display window

    -emove1hisManpa%e()

    3his action may be used in any manual page or help display window Rhen

    called it will remo%e the window, and clean up all resources associated with

    it

    SaveFormatted"a%e(action)

    3his action can only be used in the li3e1oSavepopup widget, and tells

    +man whether to Saveor Cancela sa%e of the manual page that has #ust

    been formatted

    Sho',ersion()

    3his action may be called from any manual page or help display window,and will cause the informational display line to show the current %ersion of

    +man

    Files5manath #ire!tory6manT!hara!terU

    5manath #ire!tory6catT!hara!terU

    5manath #ire!tory6mandesc

    http://www.x.org/archive/X11R7.5/doc/man/man1/xman.1.html#toc10
  • 8/11/2019 Linux_Notes by Jitendra Sir

    123/125

    usrshare55app-defaultsman

    speci"es re4uired resources

    tmp

    'mancreates temporary "les in tmp for all unformatted man pages and all

    apropos searches

    Hman

    Contents

    5 7ntroduction

    0 Bunning +man

    D earching +man

    F 1aunchers

    (iscussion thread for this #iki can %e found here

    #ntroduction

    'he original docu"entation for all Linux s!ste"s #as a set of files collecti$el! kno#n as the^"an ages^ that for"ed a readil! a$aila%le "anual descri%ing the actions and otions for eachco""and. 'he co""and ^"an^ follo#ed %! an otional section nu"%er and the na"e of the

    co""and for #hich infor"ation #as desired %rings u the ^"an age^ for that co""and,allo#ing !ou to learn "ore a%out it.

    Unfortunatel! in toda!_s #orld, "an! of the "an ages are