Some Useful Linux Commands Contents 1 Introduction 2
Total Page:16
File Type:pdf, Size:1020Kb
SomeUsefulLinuxCommands Contents 1Introduction 2ShorthandattheCommandPrompt 3TypicalDotFiles 4UsefulFiles 5ImportantDirectories 6ImportantBashShellVariables 7ImportantDaemonsandStartupServices 8WindowManagers 9AlphabeticalListofPrincipalCommands 10NotesonApplications 10.1MailTransferAgents(MTAs) 10.2MailUserAgents(MUAs) 10.3Editors 10.4Other 11SomeNiftySlogans 12References 1Introduction ThisismyownsummaryofusefulLinuxabbreviations,directories,files,andco mmands.Iusemyownannotationstorecallusefuloptionsandargumentsthatare notnecessarilydocumentedineasytofindplaces.Iquiteoftencallupthisf ilewhenIcan'trememberthesyntaxofacommandthatIuseoften(butnotofte nenoughtorememberthesyntax!).Ialsoeditorializeontherelativeusefulnes sofdifferenttypesofprograms. Thisdocumentisworkinprogress.Sendsuggestedchangesandcorrectionstoamb [email protected] O'ReillyhasjustpublishedonlineanalphabeticallistofcommandsfromLinuxi naNutshell.Itisavailablehere.Itcontainsmoredetailedexplanationsofma nyofthecommandslistedhere. 2ShorthandattheCommandPrompt Someofthesearespecifictothebashshell.Ihavenotexperimentedenoughwit hothershellstoknowwhicharecommontoallshells.Seealsothe``BashRefer enceCard'',SSC(2000),availableonline. /rootdirectory ./currentdirectory ./command_namerunacommandinthecurrentdirectorywhenthecurrentdirecto ryisnotonthepath ../parentdirectory ~homedirectory $typicalpromptwhenloggedinasordinaryuser #typicalpromptwhenloggedinasrootorsuperuser !repeatspecifiedcommand !!repeatpreviouscommand ^^repeatpreviouscommandwithsubstitution &runaprograminbackgroundmode [Tab][Tab]printsalistofallavailablecommands.Thisisjustanexampleof autocompletewithnorestrictiononthefirstletter. x[Tab][Tab]printsalistofallavailablecompletionsforacommand,whereth ebeginningis``x'' [Alt][Ctrl][F1]switchtothefirstvirtualtextconsole [Alt][Ctrl][Fn]switchtothenthvirtualtextconsole.Typically,thereares ixonaLinuxPCsystem. [Alt][Ctrl][F7]switchtothefirstGUIconsole,ifthereisonerunning.Ift hegraphicalconsolefreezes,onecanswitchtoanongraphicalconsole,killthe processthatisgivingproblems,andswitchbacktothegraphicalconsoleusing thisshortcut. [ArrowUp]scrollthroughthecommandhistory(inbash) [Shift][PageUp]scrollterminaloutputup.Thisalsoworksattheloginprompt ,soyoucanscrollthroughyourbootmessages. [Shift][PageDown]scrollterminaloutputdown [Ctrl][Alt][+]switchtonextXserverresolution(iftheserverissetupfor morethanoneresolution) [Ctrl][Alt][]changetopreviousXserverresolution [Ctrl][Alt][BkSpc]killthecurrentXserver.Usedwhennormalexitisnotpos sible. [Ctrl][Alt][Del]shutdownthesystemandreboot [Ctrl]ckillthecurrentprocess [Ctrl]dlogoutfromthecurrentterminal [Ctrl]sstoptransfertocurrentterminal [Ctrl]qresumetransfertocurrentterminal.Thisshouldbetriedifthetermi nalstopsresponding. [Ctrl]zsendcurrentprocesstothebackground resetrestoreaterminaltoitsdefaultsettings [Leftmousebutton]Holddownleftmousebuttonanddragtohighlighttext.Rele asingthebuttoncopiestheregiontothetextbufferunderXand(ifgpmisins talled)inconsolemode. [Middlemousebutton]Copiestextfromthetextbufferandinsertsitatthecur sorlocation.Withatwobuttonmouse,clickonbothbuttonssimultaneously.It isnecessaryforthreebuttonemulationtobeenabled,eitherundergpmorinXF 86Config. 3TypicalDotFiles Thereissomeredundancyacrosstheseprograms.Forexample,thelookandbehavi orofemacscanbecustomizedbyusinngthe.emacsfile,butalsobyaddingthe appropriatemodificationstothe.Xdefaultsfile.Defaultversionsofthesefile sareofteninstalledinusers'homedirectorieswhenthesoftwarepackagesthat usethemareinstalled.Ifaprogramdoesn'tfinditsconfigurationfileinthe user'shomedirectory,itwilloftenfallbackonasytemwidedefaultconfigur ationfileinstalledinoneofthesubdirectoriesthatthepackagelivesin. .bash_logoutfileexecutedbybashshellonlogout .bash_profileinitializationofbashshellrunonlyonlogin.Bashlooksfirst fora.bash_profilefilewhenstartedasaloginshellorwiththeloginoptio n.Ifitdoesnotfind.bash_profile,itlooksfor.bash_login.Ifitdoesn'tfi ndthat,itlooksfor.profile.Systemwidefunctionsandaliasesgoin/etc/bas hrcanddefaultenvironmentvariablesgoin/etc/profile. .bashrcinitializationcommandrunwhenbashshellstartsupasanonloginsh ell .cshrcinitializationcommandsthatarerunautomatically(likeautoexec.bat) whenCshellisinitiated .emacsconfigurationfileforemacseditor .fvwmrcconfigurationfileforfvwmwindowmanager .fvwm2rcconfigurationfileforfvwm2windowmanager .jedrcconfigurationfileforthejedtexteditor .lessrctypicallycontainskeybindingsforcursormovementwiththelesscomm and .logininitializationfilewhenuserlogsin .logoutcommandsrunwhenuserlogsout .wm_stylegiveschoiceofdefaultwindowmanagerifoneisnotspecifiedinst artx .XdefaultssetsupXresourcesforindividualuser.Thebehaviorofmanydiffe rentapplicationprogramscanbechangedbymodifyingthisfile. .xinitrcinitializationfilewhenrunningstartx.Canbeusedtoactivateappl ications,runagivenwindowmanager,andmodifytheappearanceoftherootwind ow. .xsessionconfigurationfileforxdm 4UsefulFiles /boot/vmlinuzthetypicallocationandnameoftheLinuxkernel.IntheSlackw aredistribution,thekernelislocatedat/vmlinuz. /dev/fd0firstfloppydiskdrive /dev/fd0H1440driverforthefirstfloppydriveinhighdensitymode.Generall y,thisisinvokedwhenformattingafloppydriveforaparticulardensity.Slac kwarecomeswithdriversthatallowforformattinga3.5"diskettewithupto1. 7MBofspace.RedHatandMandrakedonotcontainthesedevicedriverfilesbyd efault. /dev/fd1secondfloppydiskdrive /dev/hdafirstIDEharddrive /dev/hdconmanymachines,theIDEcdromdrive.Mostoften,thereisasymboli clinkcalled/dev/cdromwhichisjustalinktothetruecdromdriverfile. /dev/nullusedwhenyouwanttosendoutputintooblivion /etc/aliasesfilecontainingaliasesusedbysendmailandotherMTAs(mailtra nsportagents).Afterupdatingthisfile,itisnecessarytorunthenewaliases utilityforthechangestobepassedtosendmail. /etc/bashrcsystemwidedefaultfunctionsandaliasesforthebashshell /etc/conf.modulesaliasesandoptionsforconfigurablemodules /etc/crontabshellscripttorundifferentcommandsperiodically(hourly,dail y,weekly,monthly,etc.) /etc/DIR_COLORSusedtostorecolorsfordifferentfiletypeswhenusinglsco mmand.Thedircolorscommandusesthisfilewhenthereisnota.dir_colorsfile intheuser'shomedirectory.Usedinconjunctionwiththeevalcommand(seebe low). /etc/exportsspecifieshoststowhichfilesystemscanbeexportedusingNFS. Manexportscontainsinformationonhowtosetupthisfileforremoteusers. /etc/fstabcontainsinformationonpartitionsandfilesystemsusedbysystemt omountdifferentpartitionsanddevicesonthedirectorytree /etc/HOSTNAMEstoresthenameofthehostcomputer /etc/hostscontainsalistofhostnamesandabsoluteIPaddresses. /etc/hosts.allowhostsallowed(bythetcpddaemon)toaccessInternetservice s /etc/hosts.denyhostsforbidden(bythetcpddaemon)toaccessInternetservic es /etc/groupsimilarto/etc/passwdbutforgroups /etc/inetd.confconfigurestheinetddaemontotellitwhatTCP/IPservicesto provide(whichdaemonstoloadatboottime).AgoodstarttosecuringaLinux boxistoturnofftheseservicesunlesstheyarenecessary. /etc/inittabrunsdifferentprogramsandprocessesonstartup.Thisistypical lytheprogramwhichisresponsiblefor,amongotherthings,settingthedefault runlevel,runningtherc.sysinitscriptcontainedin/etc/rc.d,settingupvirt ualloginterminals,bringingdownthesysteminanorderlyfashioninresponse to[Ctrl][Alt][Del],runningthercscriptin/etc/rc.d,andrunningxdmforag raphicalloginprompt(onlyifthedefaultrunlevelissetforagraphicallogin ). /etc/issuepreloginmessage.Thisisoftenoverwittenbythe/etc/rc.d/rc.Ss cript(inSlackware)orbythe/etc/rc.d/rc.localscript(inMandrakeandRedHa t,andperhapsotherrpmbaseddistributions).Therelevantlinesshouldbecomm entedout(orchanged)inthesescriptsifacustompreloginmessageisdesired . /etc/lilo.confconfigurationfileforlilobootloader /etc/motdmessageofthedayfile,printedimmediatelyafterlogin.Thisisof tenoverwrittenby/etc/rc.d/rc.S(Slackware)or/etc/rc.d/rc.local(Mandrake/Re dHat)onstartup.Seetheremarksinconnectionwith/etc/issue. /etc/mtabshowscurrentlymounteddevicesandpartitionsandtheirstatus /etc/passwdcontainspasswordsandotherinformationconcerninguserswhoare registeredtousethesystem.Forobvioussecurityreasons,thisisreadableonl ybyroot.Itcanbemodifiedbyrootdirectly,butitispreferabletouseaco nfigurationutilitysuchaspasswdtomakethechanges.Acorrupt/etc/passwdfi lecaneasilyrenderaLinuxboxunusable. /etc/printcapshowsthesetupofprinters /etc/profilesetssystemwidedefaultsforbashshell.ItisthisfileinSlac kwarethatsetsuptheDIR_COLORSenvironmentvariableforthecolorlscommand. Alsosetsupothersystemwideenvironmentvariables. /etc/resolv.confcontainsalistofdomainnameserversusedbythelocalmach ine /etc/securettycontainsalistofterminalsonwhichrootcanlogin.Forsecur ityreasons,thisshouldnotincludedialupterminals. /etc/termcapASCIIdatabasedefiningthecapabilitiesandcharacteristicsofd ifferentconsoles,terminals,andprinters /etc/X11/XF86ConfigXconfigurationfile.ThelocationinSlackwareis/etc/XF 86Config. /proc/cpuinfocpuinformation /proc/filesystemsprintsfilesystemscurrentlyinuse /proc/interruptsprintsinterruptscurrentlyinuse /proc/ioportscontainsalistofthei/oaddressesusedbyvariousdevicescon nectedtothecomputer /proc/kcoreThecommandlsl/proc/kcorewillgivetheamountofRAMonthec omputer.It'salsopossibletousethefreecommandtogetthesameinformation (andmore). /proc/versionprintsLinuxversionandotherinfo /var/log/messagesusedbysyslogdaemontostorekernelboottimemessages /var/log/lastlogusedbysystemtostoreinformationaboutlastboot /var/log/wtmpcontainsbinarydataindicatinglogintimesanddurationforeac huseronsystem 5ImportantDirectories Differentdistributionshavedifferentdirectorystructures,despiteattemptsat standardizationsuchasthetheLinuxFilesystemHierarchyStandard(FHS)organ ization. /binessentialUNIXcommandssuchasls,etc.Shouldcontainallbinariesneed