Beruflich Dokumente
Kultur Dokumente
Partners
Support
Community
Ubuntu.com
PageHistory
Logintoedit
Search
UsingTheTerminal
Whyusethecommandline?
Contents
1. Whyusethecommandline?
2. StartingaTerminal
1. InUnity
2. InGNOME
3. InXfce(Xubuntu)
4. InKDE(Kubuntu)
5. InLXDE(Lubuntu)
3. Commands
1. sudo:ExecutingCommandswith
TherearemanyvarietiesofLinux,butalmostallofthemusesimilarcommands
ElevatedPrivileges
thatcanbeenteredfromacommandlineinterfaceterminal.
2. File&DirectoryCommands
3. RunningaFileWithinaDirectory
Therearealsomanygraphicaluserinterfaces(GUIs),buteachofthemworks
4. SystemInformationCommands
differentlyandthereislittlestandardizationbetweenthem.Experiencedusers
5. AddingANewUser
whoworkwithmanydifferentLinuxdistributionsthereforefinditeasiertolearn
4. Options
commandsthatcanbeusedinallvarietiesofUbuntuand,indeed,inotherLinux
5. "Man"andgettinghelp
distributionsaswell.
1. Searchingformanfiles
6. OtherUsefulThings
Forthenovice,commandslineinterfacecommandscanappeardaunting:
1. PrettierManualPages
2. Pastingincommands
sudo gobbledegook blah_blah -w -t -h --long-switch aWkward/ComBinationOf
/m
ixedCase/underscores_strokes/and.dots
3.
Saveontyping
4. Changethetext
However,itisimportanttonotethatevenexperiencedusersoftencutandpaste
7. Morewaystorunaterminal
commands(fromaguideormanual)intothecommandlineterminaltheydonot
8. Anextremelyhandytool::Incrementalhistory
memorizethem.
searching
9. Howtocreateupsidedownand/orreversetext
Itisimportant,ofcourse,toknowhowtousethecommandlineterminaland
withyourterminal
anyonewhocanmanagetyping,backspacing,andcuttingandpastingcan
10. MoreInformation
"UnderLinuxthereareGUIs(graphicaluserinterfaces),whereyoucan
pointandclickanddrag,andhopefullygetworkdonewithoutfirstreading
lotsofdocumentation.ThetraditionalUnixenvironmentisaCLI
(commandlineinterface),whereyoutypecommandstotellthecomputer
whattodo.Thatisfasterandmorepowerful,butrequiresfindingoutwhat
thecommandsare."
frommanintro(1)
managethecommandlineterminal(itisnotmoredifficultthanthat).
Thispagewilloutlineafewcraftyshortcutswhichcanmakeusingacommand
lineinterfaceeasier.
StartingaTerminal
InUnity
Unityisthedefaultdesktopenvironmentusedasof11.04.WheresystemsarenotreadyforUnitytheyreverttoGNOMEwhichisalso
usedinpreviousreleasessuchasUbuntu10.04LTS(Lucid),seenextsubsection.
TheeasiestwaytoopentheTerminalistousethe'search'functiononthedash.Oryoucanclickonthe'MoreApps'button,clickonthe
'Seemoreresults'bytheinstalledsection,andfinditinthatlistofapplications.Athirdway,availableafteryouclickonthe'MoreApps'
button,istogotothesearchbar,andseethatthefarrightendofitsays'AllApplications'.Youthenclickonthat,andyou'llseethefull
list.ThenyoucangotoAccessories>Terminalafterthat.So,themethodsinUnityare:
Dash>SearchforTerminal
Dash>MoreApps>'SeeMoreResults'>Terminal
https://help.ubuntu.com/community/UsingTheTerminal
1/9
11/15/2015
Dash>MoreApps>Accessories>Terminal
KeyboardShortcut:Ctrl+Alt+T
InGNOME
GNOMEistheclassicdesktopenvironmentforUbuntu11.04(Natty)andisthedefaultdesktopenvironmentinearlierreleases,suchas
Ubuntu10.04LTS(Lucid).
Applicationsmenu>Accessories>Terminal.
KeyboardShortcut:Ctrl+Alt+T
InXfce(Xubuntu)
Applicationsmenu>System>Terminal.
KeyboardShortcut:Super+T
KeyboardShortcut:Ctrl+Alt+T
InKDE(Kubuntu)
KMenu>System>TerminalProgram(Konsole).
InLXDE(Lubuntu)
Menu>Accessories>LXTerminal.
KeyboardShortcut:Ctrl+Alt+T
Commands
sudo:ExecutingCommandswithElevatedPrivileges
Mostofthefollowingcommandswillneedtobeprefacedwiththesudocommand.Thiselevatesprivilegestotherootuser
administrativeleveltemporarily,whichisnecessarywhenworkingwithdirectoriesorfilesnotownedbyyouruseraccount.When
usingsudoyouwillbepromptedforyourpassword.Onlyuserswithsudo(administrative)privilegeswillbeabletousethis
command.Youshouldneverusenormalsudotostartgraphicalapplicationsasroot.(PleaseseeRootSudoformoreinformation
onusingsudocorrectly.)
File&DirectoryCommands
Thetilde(~)symbolstandsforyourhomedirectory.Ifyouareuser,thenthetilde(~)standsfor/home/user
pwd:Thepwdcommandwillallowyoutoknowinwhichdirectoryyou'relocated(pwdstandsfor"printworkingdirectory").
Example:"pwd"intheDesktopdirectorywillshow"~/Desktop".NotethattheGNOMETerminalalsodisplaysthisinformationin
thetitlebarofitswindow.Ausefulgnemonicis"presentworkingdirectory."
ls:Thelscommandwillshowyou('list')thefilesinyourcurrentdirectory.Usedwithcertainoptions,youcanseesizesoffiles,
whenfilesweremade,andpermissionsoffiles.Example:"ls~"willshowyouthefilesthatareinyourhomedirectory.
cd:Thecdcommandwillallowyoutochangedirectories.Whenyouopenaterminalyouwillbeinyourhomedirectory.Tomove
aroundthefilesystemyouwillusecd.Examples:
Tonavigateintotherootdirectory,use"cd/"
Tonavigatetoyourhomedirectory,use"cd"or"cd~"
Tonavigateuponedirectorylevel,use"cd.."
Tonavigatetothepreviousdirectory(orback),use"cd"
Tonavigatethroughmultiplelevelsofdirectoryatonce,specifythefulldirectorypaththatyouwanttogoto.Forexample,
use,"cd/var/www"togodirectlytothe/wwwsubdirectoryof/var/.Asanotherexample,"cd~/Desktop"willmoveyou
https://help.ubuntu.com/community/UsingTheTerminal
2/9
11/15/2015
totheDesktopsubdirectoryinsideyourhomedirectory.
cp:Thecpcommandwillmakeacopyofafileforyou.Example:"cpfilefoo"willmakeanexactcopyof"file"andnameit"foo",
butthefile"file"willstillbethere.Ifyouarecopyingadirectory,youmustuse"cprdirectoryfoo"(copyrecursively).(To
understandwhat"recursively"means,thinkofitthisway:tocopythedirectoryandallitsfilesandsubdirectoriesandalltheirfiles
andsubdirectoriesofthesubdirectoriesandalltheirfiles,andonandon,"recursively")
mv:Themvcommandwillmoveafiletoadifferentlocationorwillrenameafile.Examplesareasfollows:"mvfilefoo"will
renamethefile"file"to"foo"."mvfoo~/Desktop"willmovethefile"foo"toyourDesktopdirectory,butitwillnotrenameit.You
mustspecifyanewfilenametorenameafile.
Tosaveontyping,youcansubstitute'~'inplaceofthehomedirectory.
Notethatifyouareusingmvwithsudoyoucanusethe~shortcut,becausetheterminalexpandsthe~toyourhome
directory.However,whenyouopenarootshellwithsudoiorsudos,~willrefertotherootaccount'shomedirectory,
notyourown.
rm:Usethiscommandtoremoveordeleteafileinyourdirectory.
rmdir:Thermdircommandwilldeleteanemptydirectory.Todeleteadirectoryandallofitscontentsrecursively,usermr
instead.
mkdir:Themkdircommandwillallowyoutocreatedirectories.Example:"mkdirmusic"willcreateadirectorycalled"music".
man:Themancommandisusedtoshowyouthemanualofothercommands.Try"manman"togetthemanpageformanitself.
Seethe"Man&GettingHelp"sectiondownthepageformoreinformation.
sudo:ThesudocommandisusedtoperformfileoperationsonfilesthattheRootUserwouldonlybeallowedtochange.An
examplewouldbetryingtomoveoneofyourdocumentsthatanotheruseraccidentallymovedto/backtoyourdocuments
directory.Normally,tomovethefile,youwouldtypemv/mydoc.odt~/Documents/mydoc.odt,butyouarenotallowedto
modifyfilesoutsideofyourhomedirectory.Togetaroundthis,youwouldtypesudomv/mydoc.odt~/Documents/mydoc.odt.
Thiswillsuccessfullymovethefilebacktoitscorrectlocation,providedthatyouarenotastandarduser,whohasless
(administrative)abilitythananadministrator.Beaware,though,thatbyusingthesudocommand,youneedtobeextracareful.It
iseasiertodamageyoursystembyusingthesudocommand.Formoreinformationaboutthesudocommand,clickhere.
RunningaFileWithinaDirectory
Soyou'vedecidedtorunafileusingthecommandline?Well...there'sacommandforthattoo!
./filename.extension
Afternavigatingtothefile'sdirectory,thiscommandwillenableanyUbuntuusertorunfilescompiledviaGCCoranyotherprogramming
language.Althoughtheexampleaboveindicatesafilenameextension,pleasenoticethat,differentlyfromsomeotheroperatingsystems,
Ubuntu(andotherLinuxbasedsystems)donotcareaboutfileextensions(theycanbeanything,ornothing).Keepinmindthatthe
'extension'willvarydependinguponthelanguagethesourcecodeiswrittenin.Also,itisnotpossible,forcompiled
languages(likeCandC++)torunthesourcecodedirectlythefilemustbecompiledfirst,whichmeansitwillbetranslated
fromahumanreadableprogramminglanguagetosomethingthecomputercanunderstand.Somepossibleextensions:".c"forC
source,".cpp"forC++,".rb"forRuby,".py"forPython,etc.Also,rememberthat(inthecaseofinterpretedlanguageslikeRuby&
Python)youmusthaveaversionofthatlanguageinstalledonUbuntubeforetryingtorunfileswrittenwithit.
Finally,thefilewillonlybeexecutedifthefilepermissionsarecorrectpleaseseetheFilePermissionshelppagefordetails.
SystemInformationCommands
df:Thedfcommanddisplaysfilesystemdiskspaceusageforallmountedpartitions."dfh"isprobablythemostusefulituses
megabytes(M)andgigabytes(G)insteadofblockstoreport.(hmeans"humanreadable")
du:Theducommanddisplaysthediskusageforadirectory.Itcaneitherdisplaythespaceusedforallsubdirectoriesorthetotal
forthedirectoryyouruniton.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/
smeans"Summary"andhmeans"HumanReadable"
free:Thefreecommanddisplaystheamountoffreeandusedmemoryinthesystem."freem"willgivetheinformationusing
megabytes,whichisprobablymostusefulforcurrentcomputers.
https://help.ubuntu.com/community/UsingTheTerminal
3/9
11/15/2015
top:Thetop('tableofprocesses')commanddisplaysinformationonyourLinuxsystem,runningprocessesandsystemresources,
includingCPU,RAM&swapusageandtotalnumberoftasksbeingrun.Toexittop,press"q".
unamea:Theunamecommandwiththeaoptionprintsallsysteminformation,includingmachinename,kernelname&version,
andafewotherdetails.Mostusefulforcheckingwhichkernelyou'reusing.
lsb_releasea:Thelsb_releasecommandwiththeaoptionprintsversioninformationfortheLinuxreleaseyou'rerunning,for
example:
user@computer:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:
Ubuntu 11.10
Release:
11.10
Codename:
oneiric
ipaddrreportsonyoursystem'snetworkinterfaces.
AddingANewUser
"addusernewuser"commandwillcreateanewgeneralusercalled"newuser"onyoursystem,andtoassignapasswordforthe
newuseraccountuse"passwdnewuser".
Options
Thedefaultbehaviourforacommandmayusuallybemodifiedbyaddingaoptiontothecommand.Thelscommandforexamplehasan
soptionsothat"lss"willincludefilesizesinthelisting.Thereisalsoahoptiontogetthosesizesina"humanreadable"format.
Optionscanbegroupedinclustersso"lssh"isexactlythesamecommandas"lssh".Mostoptionshavealongversion,prefixed
withtwodashesinsteadofone,soeven"lssizehumanreadable"isthesamecommand.
"Man"andgettinghelp
mancommand,infocommandandcommandhelparethemostimportanttoolsatthecommandline.
NearlyeverycommandandapplicationinLinuxwillhaveaman(manual)file,sofindingthemisassimpleastyping"man"command""
tobringupalongermanualentryforthespecifiedcommand.Forexample,"manmv"willbringupthemv(move)manual.
Moveupanddownthemanfilewiththearrowkeys,andquitbacktothecommandpromptwith"q".
"manman"willbringupthemanualentryforthemancommand,whichisagoodplacetostart!
"manintro"isespeciallyusefulitdisplaysthe"Introductiontousercommands"whichisawellwritten,fairlybriefintroductiontothe
Linuxcommandline.
Therearealsoinfopages,whicharegenerallymoreindepththanmanpages.Try"infoinfo"fortheintroductiontoinfopages.
Somesoftwaredeveloperspreferinfotoman(forinstance,GNUdevelopers),soifyoufindaverywidelyusedcommandorappthat
doesn'thaveamanpage,it'sworthcheckingforaninfopage.
Virtuallyallcommandsunderstandtheh(orhelp)optionwhichwillproduceashortusagedescriptionofthecommandandit'soptions,
thenexitbacktothecommandprompt.Try"manh"or"manhelp"toseethisinaction.
Caveat:It'spossible(butrare)thataprogramdoesn'tunderstandthehoptiontomeanhelp.Forthisreason,checkforaman
orinfopagefirst,andtrythelongoptionhelpbeforeh.
Searchingformanfiles
Ifyouaren'tsurewhichcommandorapplicationyouneedtouse,youcantrysearchingthemanfiles.
mankfoowillsearchthemanfilesforfoo.Try"manknautilus"toseehowthisworks.
Notethatthisisthesameasdoingaproposcommand.
manffoosearchesonlythetitlesofyoursystem'smanfiles.Try"manfgnome",forexample.
Notethatthisisthesameasdoingwhatiscommand.
https://help.ubuntu.com/community/UsingTheTerminal
4/9
11/15/2015
OtherUsefulThings
PrettierManualPages
UserswhohaveKonquerorinstalledwillbepleasedtofindtheycanreadandsearchmanpagesinawebbrowsercontext,prettifiedwith
theirchosendesktopfontsandalittlecolour,byvisitingman:/commandinKonqueror'saddressbar.Somepeoplemightfindthislightens
theloadifthere'slotsofdocumentationtoread/search.
Pastingincommands
Often,youwillbereferredtoinstructionsthatrequirecommandstobepastedintotheterminal.Youmightbewonderingwhythetext
you'vecopiedfromawebpageusingCtrl+Cwon'tpasteinwithctrl+V.Surelyyoudon'thavetotypeinallthosenastycommandsand
filenames?Relax.ctrl+shift+VpastesintoaGNOMEterminalyoucanalsodomiddlebuttonclickonyourmouse(bothbuttons
simultaneouslyonatwobuttonmouse)orrightclickandselectPastefromthemenu.However,ifyouwanttoavoidthemouseandyet
pasteit,use"Shift+Insert",topastethecommand.Ifyouhavetocopyitfromanotherterminal/webpage,youcanuse"Ctrl+Insert"to
copy.
Saveontyping
UpArrow
orCtrl+ Scrollsthroughthecommandsyou'veenteredpreviously.
P
Down
Arrowor Takesyoubacktoamorerecentcommand.
Ctrl+N
Enter
Whenyouhavethecommandyouwant.
tab
Averyusefulfeature.Itautocompletesanycommandsorfilenames,ifthere'sonlyoneoption,orelsegivesyoualistof
options.
Searchesforcommandsyou'vealreadytyped.Whenyouhaveenteredaverylong,complexcommandandneedtorepeatit,
Ctrl+R usingthiskeycombinationandthentypingaportionofthecommandwillsearchthroughyourcommandhistory.Whenyou
findit,simplypressEnter.
History
Thehistorycommandshowsaverylonglistofcommandsthatyouhavetyped.Eachcommandisdisplayednexttoa
number.Youcantype!xtoexecuteapreviouslytypedcommandfromthelist(replacetheXwithanumber).Ifyouhistory
outputistoolong,thenusehistory|lessforascrollablelist.
Example:youranhistoryandfoundyouwanttousecommand1967.Simplyenter
!1967
Changethetext
Themousewon'twork.Usetheleft/rightarrowkeystomovearoundtheline.
Whenthecursoriswhereyouwantitintheline,typinginsertstextieitdoesn'tovertypewhat'salreadythere.
Ctrl+AorHome Movesthecursortothestartofaline.
Ctrl+EorEnd
Movesthecursortotheendofaline.
Esc+B
Movestothebeginningofthepreviousorcurrentword.
https://help.ubuntu.com/community/UsingTheTerminal
5/9
11/15/2015
Ctrl+K
Deletesfromthecurrentcursorpositiontotheendoftheline.
Ctrl+U
Deletesfromthestartofthelinetothecurrentcursorposition.
Ctrl+W
Deletesthewordbeforethecursor.
Alt+B
Goesbackonewordatatime.
Alt+F
Movesforwardonewordatatime.
Alt+C
Capitalizesletterwherecursorisandmovestoendofword.
Morewaystorunaterminal
Youcanalsogetitwithafunctionkey
Youcanrunmorethanoneintabsorseparatewindows.
Youcanalsoinstallguake(GNOME),tilda(XFCE/LXDE/Mate)oryakuake(KDE)andhaveaterminalwhichappearsandhideson
shortcutkey.Thiscanbeparticularlyusefulifyouuseterminalalot.Dropdownterminalscanmakethingsaloteasierifyouaretryingto
runadesktopenviromentwithanondefualtwindowmanagerandsomethinggoeswrongdropdownterminalscanruntheorginalwindow
managerreplacetorestoreapreviousoptiontomakethingsmuchlesspainful.
Anextremelyhandytool::Incrementalhistorysearching
Interminalenter:
gedit ~/.inputrc
Thencopypasteandsave:
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char
Fromnowon,andmanyagreethisisthemostusefulterminaltool,itsavesyoualotofwriting/memorizing...
Allyouneedtodotofindapreviouscommandistoentersaythefirsttwoorthreelettersandupwardarrowwilltakeyoutherequickly:
SayIwant:
for f in *.mid ; do timidity "$f"; done
AllIneedtodoisenter:
fo
Andhitupwardarrowcommandwillsoonappear.
Howtocreateupsidedownand/orreversetextwithyour
terminal
Ifyouwishorneedtoeverfliptextupsidedown[verticalflip]"uoppsdnxd"or/andcreatereversetexthereisaterminalwayto
achievethis.
Copy/pasteandsavethefollowingasflip.plinyourhomefolder(thankstoLarsNoodnforscript).
#!/usr/bin/perl
https://help.ubuntu.com/community/UsingTheTerminal
6/9
11/15/2015
use strict;
use warnings;
use utf8;
binmode(STDOUT, ":utf8");
my %flipTable = (
"a" => "\x{0250}",
"b" => "q",
"c" => "\x{0254}",
"d" => "p",
"e" => "\x{01DD}",
"f" => "\x{025F}",
"g" => "\x{0183}",
"h" => "\x{0265}",
"i" => "\x{0131}",
"j" => "\x{027E}",
"k" => "\x{029E}",
"l" => "|",
"m" => "\x{026F}",
"n" => "u",
"o" => "o",
"p" => "d",
"q" => "b",
"r" => "\x{0279}",
"s" => "s",
"t" => "\x{0287}",
"u" => "n",
"v" => "\x{028C}",
"w" => "\x{028D}",
"x" => "x",
"y" => "\x{028E}",
"z" => "z",
"A" => "\x{0250}",
"B" => "q",
"C" => "\x{0254}",
"D" => "p",
"E" => "\x{01DD}",
"F" => "\x{025F}",
"G" => "\x{0183}",
"H" => "\x{0265}",
"I" => "\x{0131}",
"J" => "\x{027E}",
"K" => "\x{029E}",
"L" => "|",
"M" => "\x{026F}",
"N" => "u",
"O" => "o",
"P" => "d",
"Q" => "b",
"R" => "\x{0279}",
"S" => "s",
"T" => "\x{0287}",
"U" => "n",
"V" => "\x{028C}",
"W" => "\x{028D}",
"X" => "x",
"Y" => "\x{028E}",
"Z" => "z",
"." => "\x{02D9}",
"[" => "]",
"'" => ",",
"," => "'",
"(" => ")",
"{" => "}",
"?" => "\x{00BF}",
"!" => "\x{00A1}",
"\"" => ",",
"<" => ">",
"_" => "\x{203E}",
";" => "\x{061B}",
"\x{203F}" => "\x{2040}",
"\x{2045}" => "\x{2046}",
"\x{2234}" => "\x{2235}",
"\r" => "\n",
" " => " "
);
while ( <> ) {
my $string = reverse( $_ );
while ($string =~ /(.)/g) {
print $flipTable{$1};
}
https://help.ubuntu.com/community/UsingTheTerminal
7/9
11/15/2015
}
Thentosetitup:
sudo mv flip.pl /bin/
cd /bin/
sudo chown yourusername flip.pl && sudo chmod +x flip.pl
Thenopenterminalandenter:
flip.pl
else
perl /bin/flip.pl
Writewhatyouwantandhitreturn
CopyandpastewhereveryouwanttextdocumentorInternetforum,etc...
upuunonouuounopxunosdpudo
==================
Ifyouwanttoreversebacktofront,writeyourtextinatexteditorandsaveasmytexttothehomefolder.
Thenenter:
rev mytext
Copyandpastetheresult,tluserehtetsapdnaypoc.
Andofcourseyoucancombinebothfortrulycrypticresults,odupdssn
MoreInformation
AptGetHowtousingaptgettoinstallpackagesfromthecommandline.
CommandlineRepositoryEditingaddingtheUniverse/Multiverserepositoriesthroughthecommandline.
grepHowtogrepisapowerfulcommandlinesearchtool.
findHowtolocatefilesonthecommandline.
CommandlineHowtolongerandmorecompletethanthisbasicguide,butstillunfinished.
HowToReadlineinformationonsomemoreadvancedcustomizationforthecommandline.
FormoredetailedtutorialsontheLinuxcommandline,pleasesee:
http://linuxtutorial.todolistme.netAbeginnersguidetoeffectiveuseofthecommandline.
http://mywiki.wooledge.org/BashGuideBashguidesuitableforbeginners.Oneofthefewtoalsoteachgoodpractice.
http://linuxcommand.org/BasicBashtutorials,includingBashscripting.
http://linuxsurvival.com/index.phpJavabasedtutorials.
http://rute.2038bug.com/index.html.gzAmassiveonlinebookaboutsystemadministration,almostallfromthecommandline.
http://www.ss64.com/bash/Agoodlistacommands.
http://tinyurl.com/ycyg4mkListingofthreehelpfulsitesfrombeginnertoadvancedscripting.
UbuntuguideconciseanduptodateinformationforbothcommandlineandGUIusersofUbuntu.
KubuntuguideconciseanduptodateinformationforbothcommandlineandGUIusersofKubuntu
HeadbacktoUserDocumentation
https://help.ubuntu.com/community/UsingTheTerminal
8/9
11/15/2015
CategoryCommandLine
UsingTheTerminal(lastedited2015111321:00:37bywalterorlin@user0c9h109.cable.mindspring.com[24.152.132.9]:walterorlin)
https://help.ubuntu.com/community/UsingTheTerminal
9/9