TerminalBasics.pdf
(
107 KB
)
Pobierz
457127907 UNPDF
MacOSXTerminalBasicsFAQv2.01
NealParikh/neal@macnn.com
August14,2001
1Introduction
ThisFAQisintendedtobeaquickprimeronMacOSX’sBSDSubsystem.TheBSDSubsystem
isapowerfultoolthatgivesyouanimmensearrayofnewcapabilitiesandaccesstoalargenumber
ofnewapplications.Ifyoulearntousethemwisely,youcandosometrulyincrediblethings.You
havethepower;becareful.
2TableofContents
1.WhyUNIX?
2.What’sDarwin?
3.BasicsofDarwin
4.What’sashell?
5.Runningsystemcommands
6.Runningprograms
7.What’sNetInfo?
8.Basicsofcompilation
9.ProcessManagement
10.Introductiontotexteditors:PicoandEmacs
11.IntroductiontoXWindows/X11
1
3WhyUNIX?
Thatisthemainquestion,isn’tit?ManypeopleareconfusedastowhyApplehaspickedUNIX
inthefirstplace.ThereareseveralreasonswhyApplehaspickedUNIXtobethecoreoftheir
newOS(notinorderofimportance):
1.Thehistoricalreason.MacOSX’srootstracebacktoNeXTSTEP,andthatusedUNIX.
2.Fordevelopers.EveryoneisunfamiliarwiththisOS–especiallyWindowsdeveloperswho
havetoworkonportsofproductstoMacOSX.UNIXprovidesanenvironmentthatthey’re
allcomfortablewith.TheymaynotknowAquawell,buttheyknowUNIXandthusthey
knowthefilesystemandalltherulesofplay(wherenottoinstall,etc).
3.UNIXisestablished.Otherthandevelopers,alotofusersknowUNIX.UNIXwasinvented
inthe1960’s,andit’smaturedconsiderablysincethen.Prettymucheveryonewhostudies
CSinschool/collegemusthaveaworkingknowledgeofUNIX.
4.UNIXisrobust.There’sareasonalmosteveryserverintheworldrunsUNIX.AtNetCraft,
thelongestuptimeofanyserverlistedisaUNIX(Solaris)server,withanuptimeof1100
days.Basically,theadminsetsupApacheandanyotherserversthey’rerunning,andthen
theyjustleavetheserverrunning.Verylowmaintenance.
5.UNIXisflexible.NeverbeforehaveMacusershadtheprivilegeofusinganOSwhere
workingknowledgeofthecoreOSiswidespread,andinfact,theentirecoreOSisopensourced.
Forexample,there’snowayofupgradingtheOS9versionofPersonalWebSharingwithout
Apple’spermission.Theywroteit;youhavetowaitforanupdatefromthem.Ifyoufind
thatApacheorSSH(twooftheserversbundledwithMacOSX)areoutofdate,youcan
justgotoawebsite,downloadthesourcecode,andupdatethatpartoftheOS.Ifyou’rea
DPG4userandyouhaveamodem,you’velikelyheardofLouisGerbarg’sDP/Modemfix
forMacOSX.He’saDarwindeveloper,andallhedidwasbasicallygetthesourcecodefor
thatPPPextensionandjustfixit.Thenhecompileditanddistributedittopeoplewho
neededit,andthissolvedalotofproblemsformanypeople–thiskindofpowerisimpossible
withoutacoreOSthatpeopleknowverywell,andisalsoopensource.
6.Applicationavailability.WhileMicrosoftmaytaketheirsweettimeportingOce10,
therearealotofappsimmediatelyavailableforOSXbecauseit’sUNIX-based.TheGIMP,
forexample,isafreePhotoshopreplacement(therearesomethingsitcan’tdo,ofcourse,
butit’sprettydarngoodforafreeprogram)thatwouldneverhaverunontheMacplatform
ifOSXhadnotbeenUNIX-based.
7.Marketbase.DevelopersandtechiesloveOSXbecausetheydon’thavetousetwomachines
anymore.YoucanrunMSOcewhileyou’recompilingaJavaappfordeploymentonBSD
systems.TheCLIisrequiredforwritingsimpleI/Oapps(inOS9,youhavetodoallthisMac
ToolBoxjunktogetI/Ogoinginanapp–inUNIX,includethestandardI/Olibrary,and
you’reonyourway).MacOSX,andthustheMacplatformonthewhole,isnowavailable
toalotmorepeopleasit’sfinallyaviablesolution.OncemoredevelopersstartusingOSX,
thatmeanstheendusergetsmoreapps.It’sawin-win-winsituation:fordevelopers,you,
andApple.
2
Theremaybeotherreasons,ofcourse,butthisprettymuchcoversit.UNIXisthemostwell-
known,robust,experienced,fast,andflexiblecoreOSApplecouldhavepickedforMacOSX.It’s
achoicethatwillworkwell–it’lltakethemthroughthenextdecade.
4What’sDarwin?
DarwinisanopensourceoperatingsystembasedinpartofBSDUNIXandisinthesamefamily
asFreeBSD,NetBSDandOpenBSD(otherUnices).DarwinwasmeanttobethebaseofMacOS
Xbutitis,onitsown,acompleteoperatingsystem,albeitonedevoidofbenefitslikeaGUI.(Of
course,youcaninstallXfree86ontopofDarwin,whichprovidesfullGUIfacilitiesviathestandard
X11system,butXfree86isnotbundledwithDarwin.)
DarwinistheUNIXcoreofMacOSX.UNIXisanoperatingsystemworld-renownedforits
stability,flexibility,speed,andpower.MacOSXusesaUNIXcore(calledDarwin)toimprove
systemstabilityandresponsiveness.BecauseAquaisessentiallyrunningontopofanotherOS
(Darwin),youcanhavefullaccesstoawidearrayofUNIXtoolswithinMacOSX.Terminalis
yourwindowtoUNIX.
ToseeahistoryofthedevelopmentofvariousUnices,gotohttp://perso.wanadoo.fr/levenez/unix/.
NeXTSTEP,Darwin,andMacOSXareattheveryendofthe12-pagetimeline.
5DarwinBasics
Q:WhatisaTerminal?
A:ATerminalissimplyatext-basedprogramthatisusedtosendcommandstotheOSand
interactwithit.InthecaseofMacOSX,theTerminalprogramallowstheusertointeractwith
theBSDSubsystemdirectly.
Q:WhatcanIdowiththeTerminal?
A:Youcandoalmostanything,becausetheTerminalisbasicallyawindowintoanotherOS.
Macprogramsusuallydon’ttakeadvantageoftheUNIXlayer,andUNIXprogramsrarelytake
advantageoftheMaclayer.IntheTerminal,youcanrunanIRCclientlikeBitchX,browsethe
webwithLinksorLynx,readUsenetnewsgroupswiththeTinnewsreader,playTetrisinemacs,
writeprograms,writedocuments,manageyourfilesystem,runmaintenanceand/orsystemchecks,
inspectnetworktrac,andsoonandsoforth.YoucandoalmostanythinginTerminalthatdoesn’t
requireafull-blownGUIifyou’resoinclined.Infact,manyapplicationsbundledorwrittenforMac
OSXareactuallyjustCocoashellsforUNIXcommandlineapplications:BrickHouse,aprogram
thatletsyouconfigurethebuilt-infirewall,isashellforipfw;Virex7isaCocoashellfortheVirex
7commandlinescanner;TeXShop,theprogramthatthisdocumentiswrittenin,providesaGUI
foraccessingthefullystandardteTeXdistributionoftheTeXtypesettinglanguage;ProjectBuilder
usesgcc,gdb,andotherstandardUNIXprogrammingtoolsandwrapstheminaGUIwithan
editor;CronnixwrapsaGUIaroundthecrontabandmakesiteasiertoedit;andsoonandso
3
forth.Infact,peopleareoftenusingtheTerminalattimeswhentheydon’treallythinktheyare
(albeitindirectly).
Q:I’veheardit’seasytowreckmysystemusingtheTerminal.Isthistrue?
A:Duetofilepermissions,usersareessentiallyinaprotectedspaceanddon’thaveaccesstocritical
systemfilesunlesstheyloginasthesuperuser,orsystemadministratoraccount(root).Youcan,
however,deleteallyourownfiles,butthenagain,youcoulddothatanyway.Youcan’treally
causeanydamageyoucouldn’thavecausedwiththeGUI,althoughoneshouldnotethattyping
acarelessdeletecommandismucheasierthanaccidentallydraggingallyourfilestotheTrash,
selectingEmptyTrash,andclickingtheOKbutton.Thereareno”Areyousure?”prompts;the
shellassumesthatyouknowwhatyou’redoing.Beingcarefulshouldstandyouingoodstead.
6What’sashell?
Q:I’veheardthere’smorethanoneshell(bash/tcsh/zsh/ksh).Whatarethedierences?
A:Totheaverageuser,none.Shellsaremerelyprogramsthattakeininputfromtheuser,and
theyhandlecertainthingsdierent(suchasshellscripting,aliases,commandcompletion).To
readverylengthyessaysonthespecificsofdierentshells,youcanopenTerminalandtypeatthe
prompt”mantcsh”or”manzsh”forinformationonthetwoshellsbundledwithOSX.Usethe
downarrowtoscroll,spaceforpagedown,andqtostopreading.tcshisthedefaultOSXshell.
Sincethisisabeginners’FAQ,wewon’tbedoinganythingthat’sshell-specific,andonthewhole,
youonlyneedtoknowaboutthedierencesbetweenshellswhenyoubeginwritingshellscripts,
althoughtherearealargenumberofshell-specificfeaturesthatdon’tcomeupthatoftenineveryday
use.Readthemanpagesforzshandtcsh(theshellsbundledwithOSX)ifyou’reinterested.bash,
thedefaultshellonLinuxsystems,isn’tincludedinOSX,butyoucandownloadit(eitherassource
orasaprecompiledbinary).
7Runningsystemcommands
Torunasystemcommand,justtypeitsnameattheprompt.Warning:Thereisnoundoin
UNIX.Forexample,ifyoutellthemvcommand(essentiallyrename)torenameafiletoanother
existingfile,itwilljustgetridofthefirstfile.Youcanoverwriteentiredirectoriesifyou’reinas
rootandusecarelesssyntax.Thebottomlineistobevery,verycarefulaboutsyntax(especially
whenmoving,copying,ordeleting–mv,cp,andrmrespectively)andto(a)checkthemanpage
forthecommandand(b)trythecommandoutonsometestfilestomakesureyoudon’tmessup
somethingimportant.Wipingablankfolderwillbemuchbetterthanwipingyourapplications
directory,obviously.Soexperiment,butbecareful,andifyou’reinasrootoryouusethesudo
commandtorunsomethingasroot–thinktwice.
Areadersuggestedusingshellaliasestobypassthisproblemofhavingnoprompt,whichmaybe
agoodideawhileyou’relearning-trainingwheels,ifyouwill.Createa.tcshrcfileinyourhome
directory(/Users/you/.tcshrc)andpastethefollowingintoit:
4
aliasrm’rm-i’
aliasmv’mv-i’
aliascp’cp-i’
NowquitandrelaunchTerminal.Now,whenyouusemv,cp,orrm(explainedbelow),theshell
willgiveyouapromptmakingsureyouwanttodowhatyousayyoudidwhenyouasktodelete
oroverwritefiles.
•man
–themostusefulofall.Type
mancommandname
togetanexplanationofhowtousethat
commandandwhatitis.Type
manman
forinfoonhowtouse
man
.
•ls
–listthecontentsofthecurrentdirectory.
ls-l
willdoamoredetailedlisting(showing
permissions,etc),and
ls-a
willshowhiddenfiles.Youcancombinearguments–i.e.
ls
-al
willshowhiddenfilesanddoalonglisting.
•pwd
–printworkingdirectory.Tellsyouthepathtowhereyouare.InMacOSX,you
canjusttype”.”(noquotes–justtheperiod)toprintworkingdirectory.Foracomplete
listofshortcutcommands(calledaliases,nottobeconfusedwithaliasesinMacOS),type
aliases
.Tomakeyourownaliases,editthe
/usr/share/init/tcsh/aliases
fileifyou
wantthechangetobesystem-wide(forallusers)–otherwise,createa
.tcshrc
fileinyour
homedirectoryandputthealiasesthere.
•cd
–changedirectory.Type
cd/applications
toswitchtotheapplicationsdirectory.One
built-inaliasinMacOSXistojusttype
cd
whichwillalsotakeyoubacktoyourhome
directory.
..
isanicknamefortheparentdirectory,sotogoonelevelupyoucantype
cd..
.
•ps
–processlisting.ThePIDistheprocessID,andit’swhatyouusetoreferencethatspecific
process.Moreonthislater.
•psaux
–completeprocesslisting(itshowsyoueverythingthat’srunningonthesystem,
ratherthanjusttheprocessesthatyouruserhasstarted).
•top
–dynamicallyupdatedprocessviewerapp.Type
q
tostopit.
•more
–ifyoupipeacommandwhoseoutputismorethanonescreenfulinto
more
,itprompts
youtogoontothenextpage.Ifyouwanttolookthroughadirectorylistingof500files,for
example(oreven50),you’llwantto
ls|more
orelseeverythingbutthelastscreenfulwill
justwhizzbyandyouwon’tseeit.
•less
–lessisamoreuser-friendlyversionofmorebecauseitallowsyoutoscrollupthrough
theoutputaswellasdown(usingarrowkeys).lessisoftenbetter,ifnotmore(horriblepun
intended).Usageisexactlythesameasmore.
•cat
-concatenate.Basicallyitdisplaysafile’scontentsandisconvenientifyoujustquickly
wanttoreadthroughafile.IfyouwanttoreadthroughtheINSTALLfileofaUNIXapp,
forexample,you’dtype
catINSTALL
.(Mostinstalldocumentsarelongerthanonescreenful,
soyouwouldlikelyuse
lessINSTALL
inanactualsituation.)
Thisisbasicallywhatyouneedtogetonyourway.TherearesomanyUNIXsystemcommands
thatmorewouldbeunnecessary.Ifyouwanttoknowaboutothercommands(manyarelocated
5
Plik z chomika:
misiekyo
Inne pliki z tego folderu:
TerminalBasics.pdf
(107 KB)
DeveloperTools.pdf
(60 KB)
apple error codes.pdf
(247 KB)
Admin_Guide.pdf
(7361 KB)
Inne foldery tego chomika:
_Zasilacze
Acer
HP, Compaq
SONY
Zgłoś jeśli
naruszono regulamin