下载
加入VIP
  • 专属下载券
  • 上传内容扩展
  • 资料优先审核
  • 免费资料无限下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 Linux Shell脚本攻略

Linux Shell脚本攻略.pdf

Linux Shell脚本攻略

chekwind
2012-04-03 0人阅读 举报 0 0 0 暂无简介

简介:本文档为《Linux Shell脚本攻略pdf》,可适用于IT/计算机领域

LinuxShellScriptingCookbookSolverealworldshellscriptingproblemswithoversimplebutincrediblyeffectiverecipesSarathLakshmanBIRMINGHAMMUMBAIDownloadfromWow!eBook<wwwwowebookcom>LinuxShellScriptingCookbookCopyright©PacktPublishingAllrightsreservedNopartofthisbookmaybereproduced,storedinaretrievalsystem,ortransmittedinanyformorbyanymeans,withoutthepriorwrittenpermissionofthepublisher,exceptinthecaseofbriefquotationsembeddedincriticalarticlesorreviewsEveryefforthasbeenmadeinthepreparationofthisbooktoensuretheaccuracyoftheinformationpresentedHowever,theinformationcontainedinthisbookissoldwithoutwarranty,eitherexpressorimpliedNeithertheauthor,norPacktPublishing,anditsdealersanddistributorswillbeheldliableforanydamagescausedorallegedtobecauseddirectlyorindirectlybythisbookPacktPublishinghasendeavoredtoprovidetrademarkinformationaboutallofthecompaniesandproductsmentionedinthisbookbytheappropriateuseofcapitalsHowever,PacktPublishingcannotguaranteetheaccuracyofthisinformationFirstpublished:JanuaryProductionReference:PublishedbyPacktPublishingLtdLincolnRoadOltonBirmingham,BPA,UKISBNwwwpacktpubcomCoverImagebyCharwakA(charwakgmailcom)CreditsAuthorSarathLakshmanReviewersAricPedersenJohnLWeatherwaxAcquisitionEditorStevenWildingDevelopmentEditorHyacinthaD'SouzaTechnicalEditorHitheshUchilIndexerTejalDaruwaleEditorialTeamLeaderAanchalKumarProjectTeamLeaderPriyaMukherjiProjectCoordinatorJovitaPintoProofreaderLesleyHarrisonProductionCoordinatorKruthikaBangeraCoverWorkKruthikaBangeraAbouttheAuthorSarathLakshmanisayearoldwhowasbittenbytheLinuxbugduringhisteenageyearsHeisanundergraduatestudentofComputerScienceandEngineeringatModelEngineeringCollege,Cochin,KeralaSarathisalifehackerwholovestoexploreinnovationsHeisaGNULinuxenthusiastandhactivistoffreeandopensourcesoftwareHespendsmostofhistimehackingwithcomputersandhavingfunwithhisgreatfriendsSarathiswellknownasthedeveloperofSLYNUX()auserfriendlyGNULinuxdistributionforLinuxnewbiesThefreeandopensourcesoftwareprojectshehascontributedtoarePiTiViVideoeditor,SLYNUXGNULinuxdistro,SwathantraMalayalamComputing,SchoolAdmin,Istanbul,andthePardusProjectHehasauthoredmanyarticlesfortheLinuxForYoumagazineonvariousdomainsofFOSStechnologiesHehadmadeacontributiontoseveraldifferentopensourceprojectsduringhismultipleGoogleSummerofCodeprojectsHecurrentlyliveswithhisparentsinKeralaSarathcanbereachedviahiswebsitehttp:wwwsarathlakshmancomIwouldliketothankmyfriendsandfamilyforthegreatsupportandencouragementtheyhavegivenmeforallmyendeavorsIwouldliketothankmyfriendsAnuMahadevanandNeenuJacobforthetirelessenthusiasmandpatiencetoreadthroughthechapterdevelopmentsandprovidingcommentsduringdevelopmentIwouldalsoliketothankMrAtanuDattaforhelpingmecomeupwiththechaptertitlesIextendmygratitudetotheteamatPacktPublishingwhohelpedmeinmakingthisbookhappenAbouttheReviewersAricPedersenistheauthorofcPanelUserGuideandTutorial(ISBN)andWebHostManagerAdministrationGuide(ISBN),bothwrittenforPacktPublishingHealsoservedasareviewerforCUPSAdministrativeGuide(ISBN)andLinuxEmailSecondEdition(ISBN)publishedbyPacktPublishingArichasovernineyearsofexperienceworkingasaSystemAdministratorHecurrentlyworksforHostdimecom,theworldclasswebhostandalsoforNetenbergcom,makersofFantastico,theworld'smostpopularwebscriptinstallerforcPanelserversIwouldliketothankPMUG(http:wwwpmugnjorg)foryearsofinterestingcontentandcamaraderieJohnLWeatherwaxhasbeeninlovewithcomputerseversincehehadaccesstooneAnappliedmathematicianbytrade,hebeganhisstudyofcomputerprogrammingwiththePascalprogramminglanguageonthecomputerthathisfatherboughtwaybeforemostpeoplehadeventhoughtofusingacomputerforanythingtrulypracticalAsanundergraduate,heobtaineddualdegreesinphysicsandmathematicsfromtheUniversityofMissouriColumbiaandasagraduatestudentheobtainedaPhDfromMITinAppliedMathematicsAftergraduating,heworkedformanyyearsapplyingpatternrecognitiontechniquestovariousproblemsinelectricalengineeringbeforetransitioningtomathematicalfinanceInschool,hewasstronglyinfluencedbytheUNIXLinuxphilosophyofusingsimplercomponentprogramstogethertosolvelargerproblemsManyyearslater,whileexploringvarioustradingstrategiesasaquantitativeanalysisataWallStreetfirm,hestillusesUNIXcommandsandtheUNIXphilosophyonadailybasisMostoftheworkhedoesnowisrelatedtousingmathematicalmodelstopredictpricesandtradevariousfinancialinstrumentsHespendshisfreetimeworkingonappliedmathematicsandpatternrecognition(muchofwhichcanbefoundonhiswebsiteathttp:waxworksmathcom)andspendingtimewithhisfamilywwwPacktPubcomSupportfiles,eBooks,discountoffers,andmoreYoumightwanttovisitwwwPacktPubcomforsupportfilesanddownloadsrelatedtoyourbookDidyouknowthatPacktofferseBookversionsofeverybookpublished,withPDFandePubfilesavailableYoucanupgradetotheeBookversionatwwwPacktPubcomandasaprintbookcustomer,youareentitledtoadiscountontheeBookcopyGetintouchwithusatservicepacktpubcomformoredetailsAtwwwPacktPubcom,youcanalsoreadacollectionoffreetechnicalarticles,signupforarangeoffreenewslettersandreceiveexclusivediscountsandoffersonPacktbooksandeBookshttp:PacktLibPacktPubcomDoyouneedinstantsolutionstoyourITquestionsPacktLibisPackt'sonlinedigitalbooklibraryHere,youcanaccess,read,andsearchacrossPackt'sentirelibraryofbooksWhySubscribe•FullysearchableacrosseverybookpublishedbyPackt•Copyandpaste,print,andbookmarkcontent•OndemandandaccessibleviawebbrowserFreeAccessforPacktaccountholdersIfyouhaveanaccountwithPacktatwwwPacktPubcom,youcanusethistoaccessPacktLibtodayandviewnineentirelyfreebooksSimplyuseyourlogincredentialsforimmediateaccessThisbookisdedicatedtomyparentswhoshowedmethebrightchoicesinlifeTableofContentsPrefaceChapter:ShellSomethingOutIntroductionPrintingintheterminalPlayingwithvariablesandenvironmentvariablesDoingmathcalculationswiththeshellPlayingwithfiledescriptorsandredirectionArraysandassociativearraysVisitingaliasesGrabbinginformationaboutterminalGetting,settingdates,anddelaysDebuggingthescriptFunctionsandargumentsReadingtheoutputofasequenceofcommandsReading"n"characterswithoutpressingReturnFieldseparatorsanditeratorsComparisonsandtestsChapter:HaveaGoodCommandIntroductionConcatenatingwithcatRecordingandplaybackofterminalsessionsFindingfilesandfilelistingPlayingwithxargsTranslatingwithtrChecksumandverificationSorting,uniqueandduplicatesTemporaryfilenamingandrandomnumbersSplittingfilesanddataiiTableofContentsSlicingfilenamesbasedonextensionRenamingandmovingfilesinbulkSpellcheckinganddictionarymanipulationAutomatinginteractiveinputChapter:FileIn,FileOutIntroductionGeneratingfilesofanysizeIntersectionandsetdifference(AB)ontextfilesFindinganddeletingduplicatefilesMakingdirectoriesforalongpathFilepermissions,ownership,andstickybitMakingfilesimmutableGeneratingblankfilesinbulkFindingasymboliclinkanditstargetEnumeratingfiletypestatisticsLoopbackfilesandmountingCreatingISOfiles,HybridISOFindingdifferencebetweenfiles,patchingheadandtail–printingthelastorfirstlinesListingonlydirectories–alternativemethodsFastcommandlinenavigationusingpushdandpopdCountingnumberoflines,words,andcharactersinafilePrintingdirectorytreeChapter:TextingandDrivingIntroductionBasicregularexpressionprimerSearchingandmining"text"insideafilewithgrepColumnwisecuttingofafilewithcutFrequencyofwordsusedinagivenfileBasicsedprimerBasicawkprimerReplacingstringsfromatextorfileCompressingordecompressingJavaScriptIteratingthroughlines,words,andcharactersinafileMergingmultiplefilesascolumnsPrintingthenthwordorcolumninafileorlinePrintingtextbetweenlinenumbersorpatternsCheckingpalindromestringswithascriptPrintinglinesinthereverseorderParsingemailaddressesandURLsfromtextiiiTableofContentsPrintingnlinesbeforeorafterapatterninafileRemovingasentenceinafilecontainingawordImplementinghead,tail,andtacwithawkTextslicingandparameteroperationsChapter:TangledWebNotAtAll!IntroductionDownloadingfromawebpageDownloadingawebpageasformattedplaintextAprimeroncURLAccessingGmailfromthecommandlineParsingdatafromawebsiteImagecrawleranddownloaderWebphotoalbumgeneratorTwittercommandlineclientdefineutilitywithWebbackendFindingbrokenlinksinawebsiteTrackingchangestoawebsitePostingtoawebpageandreadingresponseChapter:TheBackupPlanIntroductionArchivingwithtarArchivingwithcpioCompressingwithgunzip(gzip)Compressingwithbunzip(bzip)CompressingwithlzmaArchivingandcompressingwithzipsquashfs–theheavycompressionfilesystemCryptographictoolsandhashesBackupsnapshotswithrsyncVersioncontrolbasedbackupwithGitCloningharddriveanddiskswithddChapter:TheOldboyNetworkIntroductionBasicnetworkingprimerLet'sping!ListingallthemachinesaliveonanetworkTransferringfilesSettingupanEthernetandwirelessLANwithscriptPasswordlessautologinwithSSHRunningcommandsonremotehostwithSSHDownloadfromWow!eBook<wwwwowebookcom>ivTableofContentsMountingaremotedriveatalocalmountpointMulticastingwindowmessagesonanetworkNetworktrafficandportanalysisChapter:PutontheMonitor'sCapIntroductionDiskusagehacksCalculatingexecutiontimeforacommandInformationaboutloggedusers,bootlogs,andfailurebootPrintingthemostfrequentlyusedcommandsListingthetopCPUconsumingprocessinahourMonitoringcommandoutputswithwatchLoggingaccesstofilesanddirectoriesLogfilemanagementwithlogrotateLoggingwithsyslogMonitoringuserloginstofindintrudersRemotediskusagehealthmonitorFindingoutactiveuserhoursonasystemChapter:AdministrationCallsIntroductionGatheringinformationaboutprocessesKillingprocessesandsendorrespondtosignalswhich,whereis,file,whatis,andloadavgexplainedSendingmessagestouserterminalsGatheringsysteminformationUsingproc–gatheringinformationSchedulingwithcronWritingandreadingMySQLdatabasefromBashUseradministrationscriptBulkimageresizingandformatconversionIndexPrefaceGNULinuxisaremarkableoperatingsystemthatcomeswithacompletedevelopmentenvironmentthatisstable,reliable,andextremelypowerfulTheshell,beingthenativeinterfacetocommunicatewiththeoperatingsystem,iscapableofcontrollingtheentireoperatingsystemAnunderstandingofshellscriptinghelpsyoutohavebetterawarenessoftheoperatingsystemandhelpsyoutoautomatemostofthemanualtaskswithafewlinesofscript,savingyouanenormousamountoftimeShellscriptscanworkwithmanyexternalcommandlineutilitiesfortaskssuchasqueryinginformation,easytextmanipulation,schedulingtaskrunningtimes,preparingreports,sendingmails,andsoonTherearenumerouscommandsontheGNULinuxshell,whicharedocumentedbuthardtounderstandThisbookisacollectionofessentialcommandlinescriptrecipesalongwithdetaileddescriptionstunedwithpracticalapplicationsItcoversmostoftheimportantcommandsinLinuxwithavarietyofusecases,accompaniedbyplentyofexamplesThisbookhelpsyoutoperformcomplexdatamanipulationsinvolvingtaskssuchastextprocessing,filemanagement,backups,andmorewiththecombinationoffewcommandsDoyouwanttobecomethecommandlinewizardwhoperformsanycomplextextmanipulationtaskinasinglelineofcodeHaveyouwantedtowriteshellscriptsandreportingtoolsforfunorserioussystemadministrationThiscookbookisforyouStartreading!WhatthisbookcoversChapter,ShellSomethingOut,hasacollectionofrecipesthatcoversthebasictaskssuchasprintingintheterminal,performingmathematicaloperations,arrays,operators,functions,aliases,fileredirection,andsoonbyusingBashscriptingThischapterisanintroductorychapterforunderstandingthebasicconceptsandfeaturesinBashChapter,HaveaGoodCommand,showsvariouscommandsthatareavailablewithGNULinuxthatcomeunderpracticalusagesindifferentcircumstancesItintroducesvariousessentialcommandssuchascat,mdsum,find,tr,sort,uniq,split,rename,look,andsoonThischaptertravelsthroughdifferentpracticalusageexamplesthatusersmaycomeacrossandthattheycouldmakeuseofPrefaceChapter,FileIn,FileOut,containsacollectionoftaskrecipesrelatedtofilesandfilesystemsThischapterexplainshowtogeneratelargesizefiles,installingafilesystemonfilesandmountingfiles,findingandremovingduplicatefiles,countinglinesinafile,creatingISOimages,collectingdetailsaboutfiles,symboliclinkmanipulation,filepermissionsandfileattributes,andsoonChapter,TextingandDriving,hasacollectionofrecipesthatexplainsmostofthecommandlinetextprocessingtoolswellunderGNULinuxwithanumberoftaskexamplesItalsohassupplementaryrecipesforgivingadetailedoverviewofregularexpressionsandcommandssuchassedandawkThischaptergoesthroughsolutionstomostofthefrequentlyusedtextprocessingtasksinavarietyofrecipesChapter,TangledWebNotAtAll!,hasacollectionofshellscriptingrecipesthatareadherenttotheInternetandWebThischapterisintendedtohelpreadersunderstandhowtointeractwiththewebusingshellscriptstoautomatetaskssuchascollectingandparsingdatafromwebpages,POSTandGETtowebpages,writingclientstowebservices,downloadingwebpages,andsoonChapter,TheBackupPlan,showsseveralcommandsusedforperformingdatabackup,archiving,compression,andsoon,andtheirusageswithpracticalscriptexamplesItintroducescommandssuchastar,gzip,bunzip,cpio,lzma,dd,rsync,git,squashfs,andmuchmoreThischapteralsowalksthroughessentialencryptiontechniquesChapter,TheOldboyNetwork,hasacollectionofrecipesthattalksaboutnetworkingonLinuxandseveralcommandsusefultowritenetworkbasedscriptsThechapterstartswithanintroductorybasicnetworkingprimerImportanttasksexplainedinthechapterincludepasswordlessloginwithSSH,transferringfilesthroughnetwork,listingalivemachinesonanetwork,multicastmessaging,andsoonChapter,PutontheMonitor'sCap,walksthroughseveralrecipesrelatedtomonitoringactivitiesontheLinuxsystemandtasksusedforloggingandreportingThechapterexplainstaskssuchascalculatingdiskusage,monitoringuseraccess,CPUusage,syslog,frequentlyusedcommands,andmuchmoreChapter,AdministrationCalls,hasacollectionofrecipesforsystemadministrationThischapterexplainsdifferentcommandstocollectdetailsaboutthesystem,usermanagementusingscripting,sendingmessagestousers,bulkimageresizing,accessingMySQLdatabasesfromshell,andsoonPrefaceWhatyouneedforthisbookBasicuserexperiencewithanyGNULinuxplatformwillhelpyoueasilyfollowthebookWehavetriedtokeepalltherecipesinthebookpreciseandassimpletofollowaspossibleYourcuriosityforlearningwiththeLinuxplatformistheonlyprerequisiteforthebookStepbystepexplanationsareprovidedforsolvingthescriptingproblemsexplainedinthebookInordertorunandtesttheexamplesinthebook,anUbuntuLinuxinstallationisrecommended,however,anyotherLinuxdistributionisenoughformostofthetasksYouwillfindthebooktobeastraightforwardreferencetoessentialshellscriptingtasksaswellasalearningaidtocoderealworldefficientscriptsWhothisbookisforIfyouareabeginneroranintermediateuserwhowantstomastertheskillofquicklywritingscriptstoperformvarioustaskswithoutreadingentiremanpages,thisbookisforyouYoucanstartwritingscriptsandonelinersbysimplylookingatasimilarrecipeanditsdescriptionswithoutanyworkingknowledgeofshellscriptingorLinuxIntermediateoradvancedusersaswellassystemadministratorsordevelopersandprogrammerscanusethisbookasareferencewhentheyfaceproblemswhilecodingConventionsInthisbook,youwillfindanumberofstylesoftextthatdistinguishbetweendifferentkindsofinformationHerearesomeexamplesofthesestyles,andanexplanationoftheirmeaningCodewordsintextareshownasfollows:"Wecanuseformattedstringswithprintf"Ablockofcodeissetasfollows:#!binbash#Filename:printfshprintf"sssn"NoNameMarkprintf"ssfn"Sarathprintf"ssfn"Jamesprintf"ssfn"JeffAnycommandlineinputoroutputiswrittenasfollows:$chmodsexecutablefile#chownrootrootexecutablefile#chmodsexecutablefile$executablefilePrefaceWarningsorimportantnotesappearinaboxlikethisTipsandtricksappearlikethisReaderfeedbackFeedbackfromourreadersisalwayswelcomeLetusknowwhatyouthinkaboutthisbookwhatyoulikedormayhavedislikedReaderfeedbackisimportantforustodeveloptitlesthatyoureallygetthemostoutofTosendusgeneralfeedback,simplysendanemailtofeedbackpacktpubcom,andmentionthebooktitleviathesubjectofyourmessageIfthereisabookthatyouneedandwouldliketoseeuspublish,pleasesendusanoteintheSUGGESTATITLEformonwwwpacktpubcomoremailsuggestpacktpubcomIfthereisatopicthatyouhaveexpertiseinandyouareinterestedineitherwritingorcontributingtoabook,seeourauthorguideonwwwpacktpubcomauthorsCustomersu

用户评价(4)

  • 172.16.194.132 你妹的 被骗了 哪里是什么中文版的啊 还是英文的吗

    2013-05-21 07:20:01

  • huige 很不错的书哦 而且是中文的哟

    2013-05-21 07:16:31

  • UC 灰常感谢

    2012-11-21 02:11:38

  • 116.237.62.182 呵呵,好东西,如果有中文版的,那就更好了,不过还是得感谢你

    2012-06-28 05:41:35

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

评分:

/49

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利