Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Practical: EidPB WS2016/17
EinführungindieProgrammierungfürBioinforma2ker
Introduc2ontoProgrammingforBioinforma2cs
Prof.B.Rost,Dr.L.Richter
Ins2tutfürInforma2kI12
Practical: EidPB WS2016/17
VorlesungstermineTermin Thema Termin Thema
24.10.2016 Organisation 12.12.2016 tba
31.10.2016 Linux/Java 19.12.2016 tba
07.11.2016 Linux/Java 09.01.2017 tba
14.11.2016 Shell/Java 16.01.2017 tba
22.11.2016 tba 23.01.2017 Fragestunde
29.11.2016 tba 30.01.2017 Fragestunde
5.11.2016 tba 07.02.2016 Prüfung
Es wird zwei Arbeitsblätter mit Bewertung geben. Wer aus beiden Blättern insgesamt 50% der Punkte erreicht, bekomment einen Notenbonus von 0,3 bei Bestehen der Abschlussprüfung.
Practical: EidPB WS2016/17
SystemStatus
● Gettheseizure(usespace)ofaharddisk:df: diskfreeshowstheavailablespaceonfilesystemsandtheusedspace
● spaceconsump2onoffilesanddirectories:du: diskusageshowsyouthespaceconsump2onoffiles,manyop2onstoimprovethereadability
● mountedfilesystems(drives):mount
Practical: EidPB WS2016/17
SystemStatusII
● Displaytheenvironmentvariables:env:environmentdisplaysthenameandthevaluesoftheenvironmentvariablesofyourshell
● showthesytem2me:date
● 2meconsump2onofaprogram:time
● logged-inuserandprocesses:who ● terminalseNngs:stty ifyourterminalismisconfigured:stty sane
Practical: EidPB WS2016/17
Processes● process:Ac2vitywhichgetscompu2ng2mefromtheopera2ngsystem
● characterizedby:ownnID,parent-ID,consumedcpu2me,used(virtual)memory,status
● canruninfrontorasbackground
● canrunwithoutcontrolterminal(demonprocess)
Practical: EidPB WS2016/17
Processes2● ps:reportprocessstatusps[op2ons]
● Op2ons:-u UIDprozessesforuserUID, w/oUIDforallusers-a allprocesseshavingaterminal-x showsprocessesw/ocontrolterminal-l verboseinforma2ons(long)-f displayastree
Practical: EidPB WS2016/17
Prozesses3● kill:killprocesseskill-SignalPID
● Op2ons:Signal 15(terminate,controlledstop), 9(abort,immediatestop)
● killallProgNamefinishesallprocessesofprogramProgName,assumedyouhavepermissiontodoso
● top: toolforonlinedisplayofac2veprocesses
Practical: EidPB WS2016/17
Piping
● Manytoolsuseasstandardoutputdevicethescreenandasstandardinputdevicethekeyboard
● Thesestandardchannelscanberedirectedandcombinedintoaseriesofconnectedprocessingsteps
Practical: EidPB WS2016/17
SimpleIn/OutputRedirec2on
● Redirectscreenoutputintoafile:myProgram>myPutputFile
● Redirec2onofkeyboardinputfromafile:myProgram<mInputFile
● Combina2onofboth:mProgram>mOutputFile<mInputFile
Practical: EidPB WS2016/17
Piping
● Pipesisamechanismprovidedbytheopera2ngsystemtoautoma2callyconnectprogramsintoaseries:Prog1 | Prog2 | Prog3i.e.putputofprogram1isdirectlyusedasinputforprogram2andtheoutputofprogram2isusedbyprogram3
● Goal:manysmallbutspecializedtoolscanbeconnectedtofullfillcomplextasks
Practical: EidPB WS2016/17
Filtering
● Inaseriesofconnectedprogramsnormallythereisaprocessingateachstep.I.e.certaindataaremodifiedorfilteredsothisisalsocalledfiltering.
Practical: EidPB WS2016/17
grep● grep:getregularexpression● Searchforpa`ernsininput:- Pa`ernareregularexpressions- regularexpressionsimilartothoseinPerl
● Input:filesorstandardinput
● Op2ons:-c countsoccurrences(count)-r searchdirectoriesrecursively-e specifyapa`ern-v alllinesthatdonotmatch....
Practical: EidPB WS2016/17
find● findfindfiles● searchesthefilesystemstar2ngatacertainpointfor(specified)files
● thedesiredfilesaspecifiedbycondi2ons
● Condi2ons/Op2ons:-name,-type,-size,-c2me,-m2me,-depth.-follow,etc.
Practical: EidPB WS2016/17
locate/which
● locate:findingfiles- usesitsowndatabase- thedatabaseisregularlyupdatedbyacronjob- supportssearchpa`ern,too- fasterthanfind,butdependsfromitsdatabase
● which:findsexecutableprograminthesearchpath,programsarefoundiftheyresideinadirectorylistedinthePATHvariable
Practical: EidPB WS2016/17
Archiving● (g)zip:compressingoffiles(g)unzip:resp.foruncompressing
● tar:tapearchivetar -directive [options]- combinewithg(un)ziptocompressarchives- mostimportantdirec2ves:c,x,tc createanewarchivex extractanexis2ngarchivet listthecontentsofanexis2ngarchive
- Ex.:tar-czfarchiv.tgzdirectory/tocreateancompres-sedarchivecontainingdirectoryinthefilearchiv.tgztar-xzfarchiv.tgzunpackanduncompressarchiv.tgztodirectorydirectory
Practical: EidPB WS2016/17
ExamplesforPiping
● find /usr/local/include -name "*.h" | grep gnu |wc –l countsthenumberofheaderfileshaving“gnu” inthefilename“grep gnu *” wouldsearchthefilecontentsfor “gnu”
● cd ; ls .* | wc –l countshiddenfilesinyourhomedirectory
Practical: EidPB WS2016/17
ExamplesforPiping2
● cat /etc/passwd/ | grep system | less searches /etc/passwd foralllinecontaining“system”anddisplaythemwiththepagerless
● cd; find -type f | grep -c mp3 countsallmp3fileinyourhomedirectory
Practical: EidPB WS2016/17
Addi2onalTools
● teefileName:readfromstandardinputandwritestostandardoutputandtothefilefileNameyoucan“tap”thepipelineatthispoint
● sort:inputlinesaresortednumericallyoralphanumerically(default),dependingontheselectedop2on(n:numerically,r:reverse)
Practical: EidPB WS2016/17
MoreExamples
● cat /etc/passwd | cut -f1,5 -d:● find . -name *.pl | wc
● cd; du -h --max-depth=3 | sort -rn | less
● cd; grep -lvir gnu * | wc –l searchesfilesinyourhomefortheoccurenceof “gnu” andcountsthelines
Practical: EidPB WS2016/17
ViI
● verypowerfultexteditor● availableon(nearly)allUNIXmachines
● nowadays:vim(viimproved)
● nowgraphicaluserinterfaceneeded● needsli`leresource
● s2llworkswhensystemsrespondsslowly
Practical: EidPB WS2016/17
Vi–SourcesforHelp
● h`p://www.vim.org● manpage
● Helpsystem:“:help”
● vimtutor
Practical: EidPB WS2016/17
Vi–ModesandBasics
● commandmode(normalmode)● commandlinemode(exmode)
● insertmode
● visualmode(vimonly)● commandmode->insertmode:insert/editcommand
● insertmode->commandmode:ESCAPE,CTRL-C
● commandlinemodecommandmode:RETURN
Practical: EidPB WS2016/17
Vi–naviga2on
● naviga2on:cursorkeysorh,j,k,l(leg,down,upright)
● gg:startofdocument,G:endofdocument
● 0beginofline,wnextword,eendofword,$endofline
● precededbyrepeaternumberlike:5w,2j
Practical: EidPB WS2016/17
Vi–edit
● Insert:i–agercursor,I–startofline● Erase:x–eraseatcursor,X–erasebeforecursor
● Append:a–appendatcursor,A–appendatendofline
● o:appendinnewlineager,O:appendinnewlinebeforecursor
● r:replacesinglecharacter,c+posi2oner:change
● u:undo,“.”:repeatlastcommand
Practical: EidPB WS2016/17
Morecomplexcommands
● fullcommandsyntax:[“register][counter]command[cursor positioner]
● saveandexit:ZZor:wq● exitwithoutsave:“:q!”(forcequit)
Practical: EidPB WS2016/17
MakeLifeeasier
● :set showcmd toshowyourtypedcommands!● :set nu displaylinenumers!
● :syntax on toenablesyntaxhighligh2ng!
● :set hls / nohls toenablesearchhighligh2ng!
Practical: EidPB WS2016/17
VersionControl
● Whatisversioncontrol● Whycontrolisnecessaryanduseful
● Versioncontroltools:cvs,svn,gith`p://cvs.nongnu.org/h`p://subversion.apache.org/h`p://git-scm.com/documenta2on
Practical: EidPB WS2016/17
TheShell
● commandinterpreterbetweenyouandtheopera2ngsystem
● manyflavours:sh,csh,tscsh,ksh,zsh,.....
● Linux:bash
● offers:simpledatastructures,jobcontrol,history,controlstructures
● wildcardexpansion
● commandlineedi2ng
Practical: EidPB WS2016/17
ShellStart-Up
● asaloginshell(typicallywhenyouloginin)thefollowingconfigura2onfilesaresearchedinthegivenorder: /etc/profile ~/.bash_profile(fromherefirstmatchisexecuted) ~/.bash_login ~/.profile
● otherwise:~/.bashrc
Practical: EidPB WS2016/17
ExitStatus/ReturnValue
● otherthaninmostprogramminglanguagesunix(andshell)commandsreturn0onproperexecu2onbutavaluedifferentfrom0toindicateanerrorstate
● theexitstatusisstoredinthevariable‘?’
● youcanprintitwith‘echo$?’
Practical: EidPB WS2016/17
ShellProgrammingin10seconds
● Sofarcovered:Singleinstruc2ons,instruc2onsequences(piping)
● S2llmissing:Variables,controlstructures
● Theseareprovidedbytheshell
● determineyourshell:echo $SHELL!
Practical: EidPB WS2016/17
ShellProgrammingII● makeascriptexecutable:#!/bin/bash(she-bangline)andsetx-bitorbashyourScriptfile!
● Howtodefineavariable:VariableName=Value(nowhitespacearound=)VariableName:[a-zA-Z_][a-zA-Z0-9_]*Value:unquotedstringwithoutwhitespaceorquotedstringifitcontainswhitespaceor$VariableName!
Practical: EidPB WS2016/17
ShellProgrammingIII
● simpleoutput:echo!● forma`edoutput:printf!
● enabletracemodewithset–x,evenmoreverbosewith–v
● specialvariables:- $#numberofarguments(commandline&func2on)- $*,$@listofallcommandlinearguments- “$*”onestring,“$@”listofprotectedstrings
Practical: EidPB WS2016/17
ShellProgrammingIV
● shiftreturnfirstposi2onalparameter(dele2ng)● arithme2cswithin$(( )),operatorslikeinC
● Exitstatus:Exitsstatus0indicatessuccess!$?holdstheexitstatusofthelastcommandexitnreturnsimmediatelyexitstatusn!
Practical: EidPB WS2016/17
ShellProgrammingV
● if-elif-else-fi● ifpipeline[pipeline...]thencommand-if-true-1[elifpipeline][pipeline...]thencommand-if-true-2[elsecommands-in-all-other-cases]fi
Practical: EidPB WS2016/17
ShellProgrammingVI
● test[expression] or[[expression]]!● -d fileisthisadirectory?!
● -e filedoesfileexists?!
● -h fileisthisasymboliclink?● -s fileisnotempty?
● -x fileisexecutable?
● ...!
Practical: EidPB WS2016/17
ShellProgrammingVII
● Loops:forandwhileloops● foriinlistdocommands...done!
● whilecondi2on/untilcondi2ondo commandsdone!
Practical: EidPB WS2016/17
Thankyouforyoura`en2on