Starting A Terminal: in Unity
Starting A Terminal: in Unity
Forthenovice,commandslineinterfacecommandscanappeardaunting:
sudo gobbledegook blah_blah -w -t -h --long-switch aWkward/ComBinationOf/mixedCase/underscores_strokes/and.dots
StartingaTerminal
InUnity
UnityisthedefaultDesktopEnvironmentusedin11.04.WheresystemsarenotreadyforUnitythey reverttoGnomewhichisalsousedinpreviousreleasessuchasUbuntu10.04LTS(Lucid),seenext subsection. TheeasiestwaytoopentheTerminalistousethe'search'functiononthedash.Oryoucanclickonthe 'MoreApps'button,clickonthe'Seemoreresults'bytheinstalledsection,andfinditinthatlistof applications.Athirdway,availableafteryouclickonthe'MoreApps'button,istogotothesearchbar, andseethatthefarrightendofitsays'AllApplications'.Youthenclickonthat,andyou'llseethefull list.ThenyoucangotoAccessories>Terminalafterthat.So,themethodsinUnityare: Dash>SearchforTerminal Dash>MoreApps>'SeeMoreResults'>Terminal
Dash>MoreApps>Accessories>Terminal KeyboardShortcut:Ctrl+Alt+T
InGnome
GnomeistheClassicDesktopEnvironmentforUbuntu11.04(Natty)andisthedefaultDEinearlier releases,suchasUbuntu10.04LTS(Lucid). Applicationsmenu>Accessories>Terminal. KeyboardShortcut:Ctrl+Alt+T
InXfce(Xubuntu)
Applicationsmenu>System>Terminal.
InKDE(Kubuntu)
KMenu>System>TerminalProgram(Konsole).
InLXDE(Lubuntu)
Menu>Accessories>LXTerminal.
Commands
sudo:ExecutingCommandswithElevatedPrivileges
Mostofthefollowingcommandswillneedtobeprefacedwiththesudocommand.This elevatesprivilegestotherootuseradministrativeleveltemporarily,whichisnecessarywhen workingwithdirectoriesorfilesnotownedbyyouruseraccount.Whenusingsudoyouwillbe promptedforyourpassword.Onlyuserswithsudo(administrative)privilegeswillbeabletouse thiscommand.YoushouldneverusenormalsudotostartgraphicalapplicationsasRoot(Please seeRootSudoformoreinformationonusingsudocorrectly.)
File&DirectoryCommands
Thetilde(~)symbolstandsforyourhomedirectory.Ifyouareuser,thenthetilde(~)standsfor /home/user
pwd:Thepwdcommandwillallowyoutoknowinwhichdirectoryyou'relocated(pwdstands for"printworkingdirectory").Example:"pwd"intheDesktopdirectorywillshow "~/Desktop".NotethattheGnomeTerminalalsodisplaysthisinformationinthetitlebarofits window.Ausefulgnemonicis"presentworkingdirectory." ls:Thelscommandwillshowyou('list')thefilesinyourcurrentdirectory.Usedwithcertain options,youcanseesizesoffiles,whenfilesweremade,andpermissionsoffiles.Example:"ls ~"willshowyouthefilesthatareinyourhomedirectory. cd:Thecdcommandwillallowyoutochangedirectories.Whenyouopenaterminalyouwill beinyourhomedirectory.Tomovearoundthefilesystemyouwillusecd.Examples: Tonavigateintotherootdirectory,use"cd/" Tonavigatetoyourhomedirectory,use"cd"or"cd~" Tonavigateuponedirectorylevel,use"cd.." Tonavigatetothepreviousdirectory(orback),use"cd" Tonavigatethroughmultiplelevelsofdirectoryatonce,specifythefulldirectorypath thatyouwanttogoto.Forexample,use,"cd/var/www"togodirectlytothe/www subdirectoryof/var/.Asanotherexample,"cd~/Desktop"willmoveyoutothe Desktopsubdirectoryinsideyourhomedirectory. cp:Thecpcommandwillmakeacopyofafileforyou.Example:"cpfilefoo"willmakean exactcopyof"file"andnameit"foo",butthefile"file"willstillbethere.Ifyouarecopyinga directory,youmustuse"cprdirectoryfoo"(copyrecursively).(Tounderstandwhat "recursively"means,thinkofitthisway:tocopythedirectoryandallitsfilesandsubdirectories andalltheirfilesandsubdirectoriesofthesubdirectoriesandalltheirfiles,andonandon, "recursively") mv:Themvcommandwillmoveafiletoadifferentlocationorwillrenameafile.Examples areasfollows:"mvfilefoo"willrenamethefile"file"to"foo"."mvfoo~/Desktop"will movethefile"foo"toyourDesktopdirectorybutwillnotrenameit.Youmustspecifyanewfile nametorenameafile. Tosaveontyping,youcansubstitute'~'inplaceofthehomedirectory. Notethatifyouareusingmvwithsudoyoucanusethe~shortcut,becausetheterminal expandsthe~toyourhomedirectory.However,whenyouopenarootshellwithsudoi orsudos,~willrefertotherootaccount'shomedirectory,notyourown. rm:Usethiscommandtoremoveordeleteafileinyourdirectory. rmdir:Thermdircommandwilldeleteanemptydirectory.Todeleteadirectoryandallofits contentsrecursively,usermrinstead.
RunningaFileWithinaDirectory
Soyou'vedecidedtorunafileusingthecommandline?Well...there'sacommandforthattoo! ./filename.extension Afternavigatingtothefile'sparentdirectory,thiscommandwillenableanyUbuntuusertoparsefiles compiledviagccoranyotherprogramminglanguage.Keepinmindthatthe'extension'willvary dependinguponthelanguagethesourcecodeiswrittenin.Forexample:".c"forCsource,".cpp" forC++,".rb"forRuby,".py"forpython,etc.Also,rememberthat(inthecaseofinterpretedlanguages likeRuby&Python)youmusthaveaversionofthatlanguageinstalledonUbuntubeforetryingto runfileswrittenwithit.
SystemInformationCommands
df:Thedfcommanddisplaysfilesystemdiskspaceusageforallmountedpartitions."dfh"is probablythemostusefulitusesmegabytes(M)andgigabytes(G)insteadofblockstoreport. (hmeans"humanreadable") du:Theducommanddisplaysthediskusageforadirectory.Itcaneitherdisplaythespaceused forallsubdirectoriesorthetotalforthedirectoryyouruniton.Example:
user@users-desktop:~$ du /media/floppy 1032 /media/floppy/files 1036 /media/floppy/ user@users-desktop:~$ du -sh /media/floppy 1.1M /media/floppy/
ipaddrreportsonyoursystem'snetworkinterfaces.
AddingANewUser
"addusernewuser"commandwillcreateanewgeneralusercalled"newuser"onyoursystem, andtoassignapasswordforthenewuseraccountuse"passwdnewuser".
Options
Thedefaultbehaviourforacommandmayusuallybemodifiedbyaddingaoptiontothecommand. Thelscommandforexamplehasansoptionsothat"lss"willincludefilesizesinthelisting.There isalsoahoptiontogetthosesizesina"humanreadable"format. Optionscanbegroupedinclustersso"lssh"isexactlythesamecommandas"lssh".Mostoptions havealongversion,prefixedwithtwodashesinsteadofone,soeven"lssizehumanreadable"is thesamecommand.
"Man"andgettinghelp
mancommand,infocommandandcommandhelparethemostimportanttoolsatthecommand line. NearlyeverycommandandapplicationinLinuxwillhaveaman(manual)file,sofindingthemisas simpleastyping"man"command""tobringupalongermanualentryforthespecifiedcommand. Forexample,"manmv"willbringupthemv(Move)manual. Moveupanddownthemanfilewiththearrowkeys,andquitbacktothecommandpromptwith"q". "manman"willbringupthemanualentryforthemancommand,whichisagoodplacetostart! "manintro"isespeciallyusefulitdisplaysthe"Introductiontousercommands"whichisawell written,fairlybriefintroductiontotheLinuxcommandline.
Searchingformanfiles
Ifyouaren'tsurewhichcommandorapplicationyouneedtouse,youcantrysearchingthemanfiles. mankfoowillsearchthemanfilesforfoo.Try"manknautilus"toseehowthisworks. Notethatthisisthesameasdoingaproposcommand. manffoosearchesonlythetitlesofyoursystem'smanfiles.Try"manfgnome",for example. Notethatthisisthesameasdoingwhatiscommand.
OtherUsefulThings
PrettierManualPages
UserswhohaveKonquerorinstalledwillbepleasedtofindtheycanreadandsearchmanpagesina webbrowsercontext,prettifiedwiththeirchosendesktopfontsandalittlecolour,byvisiting man:/commandinKonqueror'saddressbar.Somepeoplemightfindthislightenstheloadifthere'slots ofdocumentationtoread/search.
Pastingincommands
Often,youwillbereferredtoinstructionsthatrequirecommandstobepastedintotheterminal.You mightbewonderingwhythetextyou'vecopiedfromawebpageusingctrl+Cwon'tpasteinwith ctrl+V.Surelyyoudon'thavetotypeinallthosenastycommandsandfilenames?Relax.ctrl+shift+V pastesintoaGnometerminal;youcanalsodoMiddleButtonClickonyourmouse(bothbuttons simultaneouslyonatwobuttonmouse)orRightClickandselectPastefromthemenu.However,ifyou
wanttoavoidthemouseandyetpasteit,use"Shift+Insert",topastethecommand.Ifyouhavetocopy itfromanotherterminal/webpage,youcanuse"Ctrl+Insert"tocopy.
Saveontyping
UpArrow Scrollsthroughthecommandsyou'veenteredpreviously. orctrl+p Down Arrowor ctrl+n Enter tab
Takesyoubacktoamorerecentcommand.
Whenyouhavethecommandyouwant. Averyusefulfeature.Itautocompletesanycommandsorfilenames,ifthere'sonlyone option,orelsegivesyoualistofoptions. Searchesforcommandsyou'vealreadytyped.Whenyouhaveenteredaverylong, complexcommandandneedtorepeatit,usingthiskeycombinationandthentypinga portionofthecommandwillsearchthroughyourcommandhistory.Whenyoufindit, simplypressEnter. Thehistorycommandshowsaverylonglistofcommandsthatyouhavetyped.Each commandisdisplayednexttoanumber.Youcantype!xtoexecuteapreviouslytyped commandfromthelist(replacetheXwithanumber).Ifyouhistoryoutputistoolong, thenusehistory|lessforascrollablelist.
ctrl+r
History
Changethetext
Themousewon'twork.UsetheLeft/Rightarrowkeystomovearoundtheline. Whenthecursoriswhereyouwantitintheline,typinginsertstextieitdoesn'tovertypewhat's alreadythere. ctrl+aorHome Movesthecursortothestartofaline. ctrl+eorEnd esc+b Movesthecursortotheendofaline. Movestothebeginningofthepreviousorcurrentword.
Morewaystorunaterminal
Youcanalsogetitwithafunctionkey Youcanrunmorethanoneintabsorseparatewindows Youcanalsoinstallguake(Gnome),tilda(XFCE/LXDE)oryakuake(KDE)andhaveaterminal whichappearsandhidesonshortcutkey.Thiscanbeparticularlyusefulifyouuseterminalalot
MoreInformation
AptGetHowto usingaptgettoinstallpackagesfromthecommandline. CommandlineRepositoryEditing addingtheUniverse/Multiverserepositoriesthroughthe commandline. grepHowto grepisapowerfulcommandlinesearchtool. findHowto locatefilesonthecommandline. CommandlineHowto longerandmorecompletethanthisbasicguide,butstillunfinished. HowToReadline informationonsomemoreadvancedcustomizationforthecommandline. FormoredetailedtutorialsontheLinuxcommandline,pleasesee: http://mywiki.wooledge.org/BashGuide Bashguidesuitableforbeginners.Oneofthefewto alsoteachgoodpractice. http://linuxcommand.org/ basicBASHtutorials,includingBASHscripting http://linuxsurvival.com/index.php Javabasedtutorials http://rute.2038bug.com/index.html.gz amassiveonlinebookaboutsystemadministration, almostallfromthecommandline. http://www.ss64.com/bash/ agoodlistacommands. http://tinyurl.com/ycyg4mk Listingof3helpfulsitesfrombeginnertoadvancedscripting