unix interview questions _ informatica reference

9
7/8/2015 Unix Interview Questions | Informatica Reference https://informaticareference.wordpress.com/category/unixinterviewquestions/page/2/ 1/9 Informatica Reference Entries (RSS) Comments (RSS) Archive for the ‘Unix Interview Questions’ Category Write a script to creat a menu using case? Posted by: informaticareference on: 12/29/2011 In: Unix Interview Questions Leave a Comment $vi menu_case.sh clear tput cut 10 25 echo “main menu” tput cut 11 25 echo “————” tput cut 12 25 echo “1.Date ” tput cut 13 25 echo “2.All files” tput cut 13 25 echo “3.All Users” tput cut 14 25 echo “4.No items found” read choice case $choice in 1)echo “Today Date ::” `date` ;; 2)ls ‑f ;; 3)finger ;; *)exit ;; esac :wq

Upload: bobby

Post on 10-Sep-2015

4 views

Category:

Documents


1 download

DESCRIPTION

Unix Interview questions

TRANSCRIPT

  • 7/8/2015 UnixInterviewQuestions|InformaticaReference

    https://informaticareference.wordpress.com/category/unixinterviewquestions/page/2/ 1/9

    InformaticaReference

    Entries(RSS)Comments(RSS)

    ArchivefortheUnixInterviewQuestionsCategory

    Writeascripttocreatamenuusingcase?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $vimenu_case.shcleartputcut1025echomainmenutputcut1125echotputcut1225echo1.Datetputcut1325echo2.Allfilestputcut1325echo3.AllUserstputcut1425echo4.Noitemsfoundreadchoicecase$choicein1)echoTodayDate::`date`;;2)lsf;;3)finger;;*)exit;;esac:wq

  • 7/8/2015 UnixInterviewQuestions|InformaticaReference

    https://informaticareference.wordpress.com/category/unixinterviewquestions/page/2/ 2/9

    Writeascripttocheckthegiventypeofcharacter?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $vichar_type.shechoenteracharacterreadcharcase$charin[az])echolowercase;;[AZ])echouppercase;;[09])echoDigit;;?)echospecialcharacter;;*)echoEnteredmorethanonecharacter;;esac:wq

    Writeascripttocheckthegiventwofileareequalornot?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $vitwofiles_same.shechoenterfirstfilereadf1echoentersecondfilereadf2x=`cmp$f1$f2`if[z$x]thenechobotharesameelseechobotharenotsamefi:wq

  • 7/8/2015 UnixInterviewQuestions|InformaticaReference

    https://informaticareference.wordpress.com/category/unixinterviewquestions/page/2/ 3/9

    Writeascriptopenthegivenfile?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $viopen_file.shechoenterfilename:readfnameif[e$fname]thenif[f$fname]thenif[r$fname]thencat$fnameelsechmodu+r$fnamecat$fnameelseitisnotaregularfileelseechoItisnotaregualrfileelseechofiledoesntexistfi:wq

    Writeascripttocheckthegiventypeoffile?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $vitype_file.shechoenterfilename:readfnameif[e$fname]thenif[f$fname]thenechoregularfileelseechodirectoryfileelif[l$fname]then

  • 7/8/2015 UnixInterviewQuestions|InformaticaReference

    https://informaticareference.wordpress.com/category/unixinterviewquestions/page/2/ 4/9

    echolinkfileelif[b$fnameoc$fname]thenechoDevicefilefi:wq

    Writeascripttocheckthegivenuserisloggedinornot?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $videlete.shechoenterloginname:readlnameifwho|grep$lname>/dev/nullthenechouserisonlineelseechouserisofflinefi:wq

    Writeascripttodeletethegivenfile?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $videlete.shechoenterfilename:readfnameifrm$fnamethenechodeletedthefileelseechofileisnotexistedfi:wq

  • 7/8/2015 UnixInterviewQuestions|InformaticaReference

    https://informaticareference.wordpress.com/category/unixinterviewquestions/page/2/ 5/9

    Writeascripttoaccepttwostringsandcheckthegivenstringsareequalornot?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $vitwo_strings.shechoenterfirststring:reads1echoentersecondstring:reads2if[$s1=$s2]thenechoequalelseechonotequalfi:wq

    Writeascripttocheckthegivennumberisevenoroddnumber?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $vieven_odd.shechoenteranumber:readnif[`expr$n%2`=0]thenechoenterednumber:evennumberelseechoenterednumber:oddnumberfi:wq

    Writeascripttocheckthegivnnumberispositiveornegative?

  • 7/8/2015 UnixInterviewQuestions|InformaticaReference

    https://informaticareference.wordpress.com/category/unixinterviewquestions/page/2/ 6/9

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $vipos_neg.shechoenteranumber:readnif[$ngt0]thenechoenterednumber:positivenumberelseechoenterednumber:negativenumberfi:wq

    Writeascripttodeleteduplicatelinesfromafile?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $viduplicate.shechoenterafilenametodeletereadfnamesort$fname|uniqueu>tempmvtemp$fnameechofilewithuniquelinescat$fname:wq

    Writeascripttodeletetheblanklines?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $viblank_lines.shechoenterafilenametodeletereadfnamegrepv^$$fname>tempmvtemp$fnameechoafterdeletingthelinescat$fname:wq

  • 7/8/2015 UnixInterviewQuestions|InformaticaReference

    https://informaticareference.wordpress.com/category/unixinterviewquestions/page/2/ 7/9

    Writeashellscripttoopenagivenfile?

    Postedby:informaticareferenceon:12/29/2011

    In:UnixInterviewQuestionsLeaveaComment

    $viopen.shechoenterafilenametoopenreadfnamecat$fname:wq

    **Howtoexcutreshellscript?$./open.shor$shopen.sh

    UnixInterviewQuestionsPart1

    Postedby:informaticareferenceon:12/26/2011

    In:UnixInterviewQuestionsLeaveaComment

    1.Howtodisplaythe10thlineofafile?head10filename|tail1

    2.Howtoremovetheheaderfromafile?sedi1dfilename

    3.Howtoremovethefooterfromafile?sedi$dfilename

    4.Writeacommandtofindthelengthofalineinafile?Thebelowcommandcanbeusedtogetalinefromafile.sednpfilenameWewillseehowtofindthelengthof10thlineinafilesedn10pfilename|wcc

    5.HowtogetthenthwordofalineinUnix?cutfd

    6.Howtoreverseastringinunix?echojava|rev

    7.HowtogetthelastwordfromalineinUnixfile?echounixisgood|rev|cutf1d|rev

    8.HowtoreplacethenthlineinafilewithanewlineinUnix?

  • 7/8/2015 UnixInterviewQuestions|InformaticaReference

    https://informaticareference.wordpress.com/category/unixinterviewquestions/page/2/ 8/9

    8.HowtoreplacethenthlineinafilewithanewlineinUnix?sedi10dfilename#dstandsfordeletesedi10inewinsertedlinefilename#istandsforinsert

    9.HowtocheckifthelastcommandwassuccessfulinUnix?echo$?

    10.Writecommandtolistallthelinksfromadirectory?lslrt|grep^l

    11.HowwillyoufindwhichoperatingsystemyoursystemisrunningoninUNIX?unamea

    12.Createareadonlyfileinyourhomedirectory?touchfile;chmod400file

    13.HowdoyouseecommandlinehistoryinUNIX?Thehistorycommandcanbeusedtogetthelistofcommandsthatweareexecuted.

    14.Howtodisplaythefirst20linesofafile?Bydefault,theheadcommanddisplaysthefirst10linesfromafile.Ifwechangetheoptionofhead,thenwecandisplayasmanylinesaswewant.head20filenameAnalternativesolutionisusingthesedcommandsed21,$dfilenameThedoptionheredeletesthelinesfrom21totheendofthefile

    15.Writeacommandtoprintthelastlineofafile?Thetailcommandcanbeusedtodisplaythelastlinesfromafile.tail1filenameAlternativesolutionsare:sedn$pfilenameawkEND{print$0}filename

    Refer:http://www.folkstalk.com/2011/11/topunixinterviewquestionspart1.html

    InformaticaReferenceCreateafreewebsiteorblogatWordPress.com.TheAlbeoTheme.

    Follow

    FollowInformaticaReference

    BuildawebsitewithWordPress.com

  • 7/8/2015 UnixInterviewQuestions|InformaticaReference

    https://informaticareference.wordpress.com/category/unixinterviewquestions/page/2/ 9/9