87

Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

  • Upload
    others

  • View
    14

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux
Page 2: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

LinuxforBeginners

TheUltimateGuideToTheLinuxOperatingSystem&LinuxCommands1st

Edition

AdamVardy

Page 3: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux
Page 4: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Contents

Introduction

Chapter1:WhatisLinux?

Distributions

OpenSource

TheLinuxShell

Root

Capitalization

Servervs.Desktop

WhyUseLinux?

Chapter2:InstallingLinuxServerEdition

Chapter3:InstallingLinuxDesktopVersion

Chapter4:BasicLinuxTasks/Commands

Sudo

ManPages

Tasksel

Apt-get

Services

Top

Chapter5:BasicLinuxNavigation

Chapter6:EditingLinuxFileswithVim

StartingVim

ChangingFileOwnership

EditingandNavigating

ExitingandSaving

Chapter7:AdvancedLinuxNavigation

ChangingDirectoriesandFindingFiles

Listing/DisplayingFiles

Making,Deleting,Moving,Copying,Renaming

MountingDrives

Conclusion

Page 5: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux
Page 6: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Copyright2016-Allrightsreserved.

This document is geared towards providing exact and reliable information inregardstothetopicandissuecovered.Thepublicationissoldwiththeideathatthe publisher is not required to render accounting, officially permitted, orotherwise, qualified services. If advice is necessary, legal or professional, apracticedindividualintheprofessionshouldbeordered.

-FromaDeclarationofPrincipleswhichwasacceptedandapprovedequallybyaCommitteeof theAmericanBarAssociationandaCommitteeofPublishersandAssociations.

Innowayisitlegaltoreproduce,duplicate,ortransmitanypartofthisdocumentin either electronicmeansor inprinted format.Recordingof thispublication isstrictly prohibited and any storage of this document is not allowed unless withwrittenpermissionfromthepublisher.Allrightsreserved.

The information provided herein is stated to be truthful and consistent, in thatany liability, in termsof inattentionor otherwise, by anyusageor abuse of anypolicies, processes, or directions contained within is the solitary and utterresponsibility of the recipient reader. Under no circumstances will any legalresponsibilityorblamebeheldagainstthepublisherforanyreparation,damages,ormonetarylossduetotheinformationherein,eitherdirectlyorindirectly.

Respectiveauthorsownallcopyrightsnotheldbythepublisher.

The information herein is offered for informational purposes solely, and isuniversal as so. The presentation of the information is without contract or anytypeofguaranteeassurance.

Thetrademarksthatareusedarewithoutanyconsent,andthepublicationofthetrademark is without permission or backing by the trademark owner. Alltrademarksandbrandswithinthisbookareforclarifyingpurposesonlyandaretheownedbytheownersthemselves,notaffiliatedwiththisdocument.

Page 7: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Introduction

Thank you for buyingLinux forBeginners. Linux In this book,we are going togive you an overview of the concepts that you have to understand before youactuallystartusingLinux.WewillexplaintoyouthedifferentelementsofitthatyououghttoknowaboutbeforeyougoanddelveintotheLinuxworld.

Linux hasmany benefits.However, it also has numerous little aspects that canleave you perplexed. Not being able to understand these aspects can definitelycauseyouproblemsinthefuture.

Inthisbook,we’regoingtotalkaboutwhatthoseelementsare.Wearealsogoingto talk about what Linux is, where it came from, and all of the fundamentalconceptsthatyouhavetounderstandbeforeyouactuallystartbuildingyourownLinux servers andmaintaining your own Linux systems. In addition, we’ll alsoteachyoubasicterminalcommandsthatwillgetyouupandrunningaboutwithintheLinuxoperatingsystem.

Wehopeyouenjoythisbook!

Page 8: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux
Page 9: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Chapter1:WhatisLinux?

ThefirstthingthatweneedtotalkaboutinthisbookisabouttheoriginsoftheLinux. Inanutshell,Linux isanoperatingsystem.For thoseofyouwhodonotknowwhatanoperatingsystemis,and forallofyouwhothinkyoudobutmayhaveforgottenwhatanoperatingsystemis,itisactuallythesoftwarelayerthatisbetween your hardware and the software that allows you to get somethingproductivedoneonacomputer.

Theoperatingsystemiswhatallowsthesoftwaretotalktothehardware.Itistheonethatletsyoustoreinformationonharddrives,sendoutprintjobstoprinters,etc. If you are in a normal Windows environment—a Microsoft WindowsOperatingsystem—youhaveyourhardwareatthebottom,youhavetheWindowsoperatingsystemontopofthat,andthenyouhaveMicrosoftOffice,forexample,thatsitsontopoftheoperatingsystem.

Linuxisanoperatingsystemthatactsasanintermediary—i.e.abridge—betweenthephysicaldeviceandtheinstructionalcodeofaprogram.Themainthingthatyou justneed to realize is that in theLinuxworld, the software thatyouwillberunningisofacompletelydifferenttype,comparedtotheonesthatyouwouldrunintheWindowsoperatingsystem.DesktopapplicationslikeMicrosoftOfficeandAdobe Photoshop are not usually run on a Linux environment. Linux normallyruns servers—Apache web servers, database servers, web virtualization servers,etc.

However,therearevariousLinuxdistributionsouttherethatarespecificallymadeforpersonaldesktopcomputers.TheseLinuxdistributionsare,inaway,similartoWindowsandMacOS, inasense that theyrunthesametypesofprograms likeWord Processing programs, photo and video editing programs, web browsingapplications, program development applications, games, etc. These Linuxdistributions are more targeted to home users who just want a free operatingsystemalternative.

Linuxdidnotbeginasanoperatingsystem,however.LinuxwasakernelcreatedbyLinusTorvaldswhilehewasastudentattheUniversityofHelsinki.TheKernelis essential, but by itself, it is useless. It can only function in the context of acompleteoperatingsystem.TheLinuxKernelwasused incombinationwith theGNUoperatingsystem.ImagineGNUasabigcomplexpuzzlewithabigpieceinthemiddlemissing—the big piece being the LinuxKernel. The complete puzzleequatestoafunctionaloperatingsystem.

ItisimportanttounderstandwhataKernelisasthisisthedefiningcomponentofLinux.AKernel isthecentralpartofanoperatingsystemthat isresponsibleforinterfacingallyouapplicationsdowntothephysicalhardware.

TherearetwomajortypesofKernelscompetingintoday’smarket—WindowsandUnix-likeKernels.TheLinuxKernel fallsunderthe latterasdoesBSD,MacOS,

Page 10: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

andSolaris.Theterm“Unix-like”referstothefactthattheyoperatesimilarto,orarebasedontheoriginalBellLabsUNIXoperatingsystem.

Kernelstendtofallunderthreecategories:

MicroKernel–AMicroKernelonlymanageswhatithasto:CPU,Memory,andIPCorinter-processcommunications.IfitisnotanIPC,Memory,orCPU,itisautomaticallyregardedasanaccessoryandcanbehandledinusermode.

Monolithic–MonolithicKernelslikeLinuxaretheoppositeofMicroKernels.TheyencompassnotonlytheCPU,Memory,andinter-processcommunications,butotherthingssuchasdevicedrivers,filesystemmanagement,andsystemservercalls.

Hybrid–TheWindowsKernelfallsunderHybridbecauseithastheabilitytopickandchoosewhattoruninbothuserandsupervisormode.

And so, between 1991 and 1994, Linus Torvalds created the Linux operatingsystembycombiningtheGNUOSwiththeLinuxKernel.Basically,LinusTorvaldswantedanoperatingsystemthatisnotonlyfree,butalsosomethingthathecancustomizetofitaccordingtohisprogrammingneeds.Linuxwashiscreativelittlepetprojectthathedidontheside.ThebigthingwithLinuxis,becauseithasan“ux”suffix,andbecausemostofthecommandsthatyouuselookalotlikeUNIXcommands,people think thatLinux is a typeofUNIXoperating system.This istotallynot the case.UNIX is its own type of operating system.Linux is its owntypeofoperatingsystem.

LinusTorvaldscreatedtheentireLinuxoperatingsystemfromthegroundup.Thereasonhe createdLinuxwas thathewanted to createanopen sourceoperatingsystem for people to use. Back in the day, UNIX was not open source. If youwantedtouseUNIX,youhadtopaysomebodyinordertouseUNIX.MicrosoftWindows,ofcourse,isMicrosoftWindows.YoualwayshavetopayinordertouseMicrosoftWindows.

SoLinusTorvalds,being thecomputerengineer thathe is,wantedanoperatingsystemthatwascompletelyfree.HeandhisfriendsattheMassachusettsInstituteofTechnology,orM.I.T.,wantedanoperatingsystemthattheydonothavetopayfortouseandwillalsohelpthemcreatethecomputerprogramsthattheywantedto make in a more efficient and easy way. In other words, they wanted anoperatingsystemthattheycancustomizetofittheirneedsaswellascompletelyfreetouse.

The big thing to remember with Linux is that, even though it is an operatingsystem,itlookstotallydifferentthanMicrosoftWindowsorMacOS.

Page 11: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Distributions

AfterLinusTorvaldscreatedLinuxbackinthe1990s,hewantedtostopworkingforalittlebit.So,whathedidwashemadethesourcecodeforhisnewoperatingsystem completely available to the public. This allowed everybody in theworld,especiallycomputergeeks,scientists,etc.,tostartplayingwithandchangingtheLinuxoperatingsystemastheysawfit.

MajorcompaniesandeducationalinstitutionsdecidedtheylikedLinux.AndsinceLinux is open source, they are able to see the source code. This gave them theabilitytostartcreatingtheirownversions.

PeoplefromUniversityofCalifornia,Berkeley,decidedtostartcreatingtheirownversion of Linux. People from China also started creating their own version ofLinux.Peoplefromallovertheworld—fromallwalksoflife—startedmakingtheirownversionsofLinuxthatfittheirownpersonalneeds.Today,youhaveRedHatLinux,UbuntuLinux,GoogleAndroid,andmanymore.

Making Linux’s source code available to the public facilitated the creation ofsomethingcalleddistributionsor“distros.”DistributionsarethevariousversionsofLinuxthatpeoplehavecreatedovertime.TherearemanydifferentversionsofLinuxthatareoutthere.Differentdistributionshavedifferentcapabilities.Now,whenyouneedtodecidewhichLinuxdistributionyouwanttouse,youaregoingtohavetothinkaboutwhatyouwantyourcomputertodofirstwithLinux.

Itismuchmoreimportantthatyouunderstandwhatyouwantyourcomputertodo,beforeyou install theLinuxoperatingsystem.WithMicrosoftWindows,youjust install it first and thenworry about what youwant to do with your serverlater.WithLinux,everydistributionisbuilttodothingsinacertainway.

Forexample,thereisaversionofLinuxcalledTrustix.TrustixLinuxisconsideredtobethemostsecureLinuxoperatingsystemoutthere.Itisjustabrick.YousetTrustixLinuxupandaslongasyoudonotdoanythingcompletelystupid,nobodycanhackitandnovirusescangettoit.Itisjustonesolid,secureserver.But,youhavetodecidethatyouwantasolidandsecureserverfirst,beforeyougoandgetthatparticulardistributiontoinstallontheserver.

So, ifyouwantacomputer thatyoucanusesomeofficeapplicationsoryouaregoingtosurfthewebwith,thenyoumaywantUbuntuLinux’sdesktopversion.Ifyou want a super secure computer, then youmight want Trustix Linux. If youwant somethingwith enterprise level support, let’s say youwant touse aLinuxdistributionthathasatechsupportcenterouttheretohelpyouifnecessary,youmaydecide touseRedHatLinux.Butagain,youhave todecidewhatyouneedyourcomputertodoinordertodeterminetheexactLinuxdistributiontoinstallonyourcomputer.

If you install Ubuntu Linux distribution on all your computers, and then youdecideyouneedenterprisesupportandyoucallRedHatLinux,theywillnotbeable to help you. Red Hat Linux does not support Ubuntu Linux. Every

Page 12: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

distributiondoesthingstheirownwayandiscreatedbydifferententities.Soyoumust familiarize yourself first with what a particular distribution does, andwhetheritfitsyourcomputingrequirementsexactly.

Page 13: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

OpenSource

Nowthatwehave talkedbasicallyaboutwhereLinuxcamefrom, thenext thingthatwe need to talk about isOpen source licensing.Of course, at this point intime, you have probably heard of open source software. You are also probablyunder thewrong idea thatopensourcesoftware is free software.This isnot thecase.

Open source software is not free software. And if you treat all open sourcesoftwareas if it is free, youare jeopardizingnotonly your career,but also yourcompany. It is just bad legally. Therefore, it is important that we discuss opensourcesoftwareandthedifferentwaysthatopensourcesoftwarevendorsgetpaid.

Sowhatdoesopensourceexactlymean?Whatopensourcesoftwaremeansisthatwheneveraprogrammersitsdownandbeginwritingthecodeforasoftware,theyprovideyouwiththecodeonlysothatyoucanseehowtheprogramwaswritten.Itdoesn’tnecessarilymeanitisfree.Sohowdotheseprogrammersearnwithanopensourcelicense?Therearefourdifferentwaysthattheseopensourcevendorsorprogrammersgetpaid.

Thefirstoneisthroughtheopensourcemodelwheretheygivethesoftwarefreeofcharge,butwhenyourequire trainingorsupport for thesoftware, that iswhereyouhavetopaythemacertainamount.LetussayforexampleyoudownloadedthemySQL software for yourLinux server.Youdownload themySQLprogram,tinkeredaroundwith it fora littlebit,andthenyoufindout that it isextremelyusefulandpowerful.

Even though you already figured out most of the intricacies of the mySQLprogram,therearestillcertainaspectsofitthatyouneedtolearn,orneedsupportwith.So,yougoapproachthesoftwaredeveloperandaskforsupportandtraining.Thisisthepointwhereyouhavetopaythemacertainamount.Thisisoneofthewaysthesedevelopersorprogrammersgetpaidfortheirdevelopmentefforts.

Thesecondwaydevelopersandvendorsgetpaidthroughanopensourcelicenseisthroughanon-commercial,personal-use-onlyopensource license.This iswheremostpeople,includingveteransystemadministrators,getintoalotoftrouble.

It is true that some open source licensed software will allow you to obtain aprogram completely free. You can use them in a computer lab or any kind ofexperimentalenvironmentwithouthaving toworryabout the legal implications.Why?Becauseitisforpersonalornon-commercialuseonly.

Theproblem,orthepartthatusuallygetsanadministratorinhotwater,isassoonas they take that server from the test lab and screw it into a server rack in theproductionenvironment,thecommercialusestartstokickin.

Ifyouareageekathomeandyouwanttoplayaroundwiththesoftware,thereisnoproblematall.Onceyouuseittopowerupabusinessserver,ormaybehostahomebusinesswebsiteforexample,younowownalicensingfeeforthatsoftware.

Page 14: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Thegruesomethingaboutitisthattheselicensingfeescanbeanywherebetween$5,000and$10,000.Itisthatexpensive.Therefore,itisonlyprudentthatyoubeconscious on how you use the software, whether it is for personal, non-commercial,orcommercialuse.

Thethirdwayopensourcesoftwareprogrammersorvendorsgetpaidisthroughapaidopensourcelicense.Someofyoumightbeasking,howcanasoftwarebeonan open source license if it is a paid software right off the bat? Well, a paidsoftwarewillalwaysbeconsideredasopensourceiftheyletyouseethecode.

Theideabasicallyis,ifyouwanttheproduct,youpaythevendorordeveloperthelicensingfeeandyoubuyitjustlikeifyouaredealingwithMicrosoft,Adobe,etc.Thedifferencewithopensourcesoftwareinthismodelis,eventhoughyouboughtthesoftwareandcanseethecode,youmaynothavethelegalrighttomodifythatcode.

Ifyouarethetypeofuserwholikesmodifycodetotailor-fitaparticularsoftwareaccordingtoyourspecificneeds,youshouldlookoutandavoidsoftwarethathasthistypeofopensourcemodel.

The fourthway theseopen source vendors getpaid is througha recurringopensourcelicensefee.Again,thisislikemostopensourcelicensesoutthere.Theyletyoudownloadandtestthesoftwarefreeofcharge.Theywouldevenletyouseethecode,justsoyouknowhowthesoftwareactuallyworks.

However,inorderforyoutohavethelegalrighttoactuallyusethesoftware,theywould have to charge you a yearly fee. This is usually cheaper than a one-timelicensingfee,butisexpensivenonetheless.

Hereisanexample:LetussayyoudownloadedFoxitPDFreaderforfree.Youcanuse the software, test out itsmost promising features, and even see the code tofigure out how it doeswhat it does. But in order use the software legally, fullyunlockitsmostusefulfeatures,andalsohavetechnicalsupportforit,youhavetopaythedevelopersayearlyrecurringfee.

So, as you can see, knowing how open source licensing works is far moreimportanttoyourbusinessthansimplybeingabletosetupaserver.This isthekind of thing that can cause massive amounts of damage to you and yourcompany. If you installmultiple serverswithopen source licensed softwareandyoudonotknowthelicensingrequirements,thatmaybeacatastrophicproblem.Remember,opensourcedoesnotmeanitisfree.Ithasnothingtodowithfree.Ahugeamountofopensourceonlyhappenstobefree.However,thatdoesn’tmeanopensourcesoftwareiscompletelyfree.

What open source means is that you are allowed to see the source code thatcreatedtheprogram.Thisdoesn’tmeanyou’reallowedtomodifythesourcecode.Youmay not even be able to do a single thing to the source code. But at leastyou’reallowedtoseethesourcecodesothatyouunderstandwhatishappening.Ifthereareflaws,oriftherearesecurityholes,youcanactuallyseethatinthecode.

Page 15: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

As you can see, Linux can go from being really affordable to being stupidlyexpensive in an instant.And thesemaintenance contracts are one of the thingsthat canmake it extremely expensive.Open source licensing, aswementioned,canmakeorbreakyourcareer.Somakesureyoutakeitseriously.

Page 16: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

TheLinuxShell

Nowthatwehavethelegalitiesoutoftheway, letusnowtalkabouttheshelloftheLinuxoperatingsystem.Sowhatisashell?Theshellofanoperatingsystemisthe screen that youuse to interactwith theoperating system. If you’re thinkingabout Microsoft Windows, the Windows shell is that graphical user interfacewherewehavethelittlemousepointerwhichweusetogoaroundandclickonthevariouselementsofthedesktop,suchasfolders,icons,etc.

Theshellisoftwotypes.Thefirstoneisthegraphicaluserinterface,orGUI.Thesecondone is called the lineuser interface,orLUI.TheLUIbasically looks likeDOSprompts. So, if you everplayedwith theMicrosoftWindowsDOSprompt,thelineuserinterfaceisexactlythat.Itisthatblackandwhitescreenwhereyoutypeindifferentcommandstogetaparticularoutputfromthecomputer.

In Linux, since this is a much more technical operating system preferred byprogrammers,geeks,engineers,orwhathaveyou,theyprefertousethelineuserinterface. So when you go and install Linux, you can either have a graphicalcomponent where you can click things in the desktop much like a normaloperatingsystem,oryoujusthavethatlittlelineuserinterface.

Themain thing that youhave to remember about the shell is that the lineuserinterface (LUI) ismuchmore powerful than the graphical user interface (GUI).However,whenyou installLinuxwith just a lineuser interface for the shell, allyouaregoingtogetisaprompt.Ifyoudon’tknowwhatyouneedtodowiththecommandprompt,likethevariousshellcommandsforthatoperatingsystem,youwillbestuck.

Therearemanycaseswherepeople installLinuxwithanLUI,butdoesn’tknowany Linux shell commands for the LUI. So basically, that’s the thing with theLinuxlineuser interface.Youaregoingtohavetounderstandthecommandsinordertogetthecomputertodoanythingthatyouneedittodo.

Page 17: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Root

ThenextbigconceptthatyouhavetounderstandwhenyouaregoingtobeusingLinux is the concept of Root. In Linux, root pertains to the highest level ofanything.Whenyouhearabouttherootuser,itisreferringtotheadministratorofthe computer. The root user is the highest level user that you can be on thecomputer.

So,ifyoucanloginasroot,youcandoanythingintheworldyouwanttowiththecomputer.Root can alsomean the root of the operating system. It iswhere theoperatingsysteminstalledinthecomputerharddrive.Ifyouthinkaboutthis intermsoftheWindowsoperatingsystem,C:/istherootoftheWindowsoperatingsystembecausethatiswhereitisinstalled.

Root can also mean the highest level that a user can get into. What does thismean?InLinux,usershavehomefolders.Thehomefolderholdsalloftheuser’sdata,suchasdocuments,settings,programs,etc.Sotherootoftheuserwouldbetheirhomedirectory.Thehomedirectoryisthehighestlevelforaparticularuser.

ThemainthingtounderstandwheneveryouaretalkingaboutrootinLinuxisthatrootisthehighestlevelofanything.There’sactuallyauseraccountinLinuxcalledroot,andthatuseraccountistheabsolutehighestleveluserthatyoucanbegintheoperating system in.Root can absolutelydo anything.Theyhave total access toeverything in the operating system. Once we go into actually starting to typecommandsandmakingLinuxdocertaintasks,thisconceptofrootisgoingtobecrucial.

Page 18: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Capitalization

LetusnowtalkaboutsomethingthatjustmesseswitheveryWindowsuser’sheadwhenmakingtheswitchtoLinux:Capitalization.Sobasically,youhaveuppercaseand lowercase letters. In theWindowsoperatingsystem, itdoesn’tcarewhetheryouputinanuppercaseoralowercaseletter.Ifyouhaveafoldernamed“Home”in Windows, that is going to be the same as “HOME,” “home,” or “homE.”Windows,exceptwhenitcomestopasswords,doesnotcareaboutcapitalization.

In the Linux world, keep in mind that Linux was created by computerprofessionals. These computer professionals coded the characters of letters,numbers,punctuations,etc.usingASCIItext.InASCIItext,anuppercase“H,”forexample,isactuallyadifferentcharacterfromalowercase“h.”Whatthismeansisthat in the Linux world, “Home,” “HOME,” “home,” or “homE” would beconsidereddifferentfolders.

Letus sayyouhavea foldernamed“USER,”but for some reasonyour typed in“user”whenyoutriedtoaccessit.Linuxwillnotbeabletofindthatfolderbecausethe “user” folder does not exist. Only the “USER” folder, with the uppercaseletters,doesexist.Soremember,capitalizationmattersinLinux.

Oneoftheplacesthiscancauseyoubigproblems,andyouhaveprobablyalreadyseenthiswithsomewebsitesthatyouuse,iswhenyouaretypingyourusernamelogins.InLinux,allusernameandpasswordsarecasesensitive.SowhenyoutypeinyourusernameorpasswordinLinux,makesurethatyoudon’thaveyourcapslockkeyturnedonoryouarenotaccidentallyholdingdownshiftwhenyoutypeinyourusernameandpassword.

Thisisactuallynotcomplicated.ItisjustthatpeopleareusedtousingWindowsthat they totally bring themannerisms of usingWindows over to Linux, wherecapitalizationmattersgreatly.

Page 19: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Servervs.Desktop

There are generally two versions of Linux that everybody is going to provide.Whether you get Red Hat Linux, Ubuntu Linux, Fedora Linux, or whateverdistributionthatmaybe,theywillnormallyhavetwoversionsofthedistribution.One is going tobe the server versionwhile theother is going tobe thedesktopversion.

Themaindifferencebetweentheserverversionsandthedesktopversionsofanyof these Linux operating systems is that, the server version is a stripped downversionifLinux.Why?Becausetheyfiguredthatifyouaregoingtobeinstallingaserver, you know specifically what you want installed on the server.What thismeansisthattherewillbenographicaluserinterfaceintheoperatingsystem,anda lot of the tools that you use to administer Linux will not be installedautomatically.

They figured that if youwant the tool and you are installing a server, then youknowhow to install the tool to the server yourself. If you are just beginning tolearn Linux, you are probably better off at this point in time to download thedesktopversion.Thedesktopversionsofthesedistributionsgiveyouthegraphicaluserinterfacerightoffthebat.

Whenyou install thedesktopversion,you’ll immediatelybeable tonavigate theoperatingsystemusingthegraphicaluserinterface,muchlikeMicrosoftWindowsorMacOS.Youwillhavedesktopicons,foldersthatyoucanclickon,etc.

It’sgoingtofunctiondifferentlycomparedtoWindowsorMac,soyoustillhavetolearnhowtouseLinux.Butit’sgoingtobeanenvironmentthatyouareprobablygoing to be able to understand as soon as you boot into it. After installing thedesktopversion,youaregoingtobootstraightintoagraphicalenvironment.Itisalreadygoing tohavemanagement tools installed,andyoucanplayaroundandfigureouthow touse that graphical environment.That’s themainadvantageofthedesktopversionovertheserverversionofLinux.

Page 20: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

WhyUseLinux?

The reason that you should learn Linux and start deploying Linux is for serverfunctionality.Linuxisincrediblyrock-solid.OnceyouinstallLinux,andonceyougetthroughallthequirksandyousetupalltheconfigurations,aLinuxserverwillrununtiltheCPUoverheatsanddies.Itwouldjustrunnon-stop.ALinuxserver,onceinstalledcorrectly,canrunforahundredandfiftydayscontinuouslywithouthavinganyproblems.

Linux is totally unlike Windows where you have to reboot it weekly to avoidmemory leaksorcrashes.Linux,as longasyouconfigure itproperly,would justrun and do its job day in and day out. The reason that you should look atdeployingLinuxis forserverfunctionality,whether it is forApachewebservers,mySQLdatabaseservers,virtualizationservers,emailservers,etc.

WhenyousetupaLinuxserver, that thing isgoingtoberock-solid.YouarenotgoingtohavethesameproblemsthatyouhavewithWindows,whereyouinstallWindows inacomputer todayandworksreallygreat,but thenyoukeepgettingmany updates. And two years from now, the computers are working slowerbecause all the updates that Microsoft has delivered actually decreased theperformanceofthecomputeritself.

ThisisnotthecasewithLinux.OnceyouinstallLinux,itisgoingtodoitsjobwiththesameefficiencyaswhenyoufirstinstalleditonyourcomputer—aslongasyouconfigureitproperly,ofcourse.

Linux is a really robust and efficient operating system. At this point, it isimportant that youhave a good foundationandunderstandingofwhere exactlyLinuxcamefrom,andwhataresomeofitsbasicbutimportantconcepts.

Page 21: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux
Page 22: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Chapter2:InstallingLinuxServerEdition

Inthischapter,wewill talkabouthowto installLinuxsothatyoucantry itoutandgetafeelonhowtousetheLinuxoperatingsystemingeneral.WearegoingtodiscusshowtoinstallboththeserverandthedesktopversionsofLinux,soyoucanjustseehowtheinstallprocessforeachversionworks.Alsonotethatwearegoing to be using the server and desktop version of theUbuntu distribution ofLinux.

Justwithall thedifferentdistributions thatareout there, it iscurrently theonethat seems to be themost popular.With all distributions of Linux, you shouldunderstandthattheyallhavetheirownparticularquirks.Ubuntuisnodifferent.

Ubuntu Linux has some particular quirks that other distributions do not have.Throughthiswholebookwe’regoingtobeusingUbuntu.JustkeepinmindthatifyoudecidetouseadifferentversionofLinux,andyougoandtrytorunsomeofthe commands that we will be teaching you in the later chapters, theymay beslightlydifferentinthoseversions.SoyoumayhavetodoalittleGooglesearchtoseewhatthosedifferencesare.

Forexample,inUbuntuyouusethe“apt-get”commandinordertogetandinstallapplicationsorprogramsontotheLinuxcomputer.InRedHatorFedora,youusethe “YUM”command.Basically, at the endof theday, the “apt-get” and “YUM”commands do the same thing. It’s just that for each version/distribution, thesyntaxofthecommandvaries.

NowwearegoingtolearnhowtoinstalltheUbuntuLinuxserveredition.Again,Ubuntuiscompletelyopensource;itiscompletelyfree.WhetheryouwillbeusingUbuntuforpersonaluseorcommercialuse,youcandosoatnocost.Allyouneedtodo is go to theUbuntuwebsite, download the ISO file for theUbuntu serveredition,andthenburnittoadiskorputitinaUSBthumbdrive.

For the sake of conciseness, we will not delve into the disc burning process orbootableUSBthumbdrivecreationprocess. IfyoudonotknowhowtoburnanimagefileontoadiskoraUSBthumbdrive,therearemanytutorialsonthewebon how to do that. Just look it up and follow the steps enumerated in thosetutorials.

Sinceweareinstallingtheserverversion,keepinmindthatattheend,allwearegoingtoget isthe lineuser interface,orLUI,oftheshell.Inotherwords, it isablinking cursor at the commandprompt. If youdon’t know the commands thatyouneedtotypein,youwillbestuck.

Atthispointwearenotgoingtodiscussthosecommandsyet.Whatwearegoingtodoisjustgothroughtheinstallationoftheoperatingsystemsothatyouseeandknow how it all works. You may also be asking yourself, if there is a desktopversionandthereisaserverversion,thenwhyistheserverversionsobarebones?

Page 23: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Howcomeitdoesnothaveanygraphicaluser interfaceatall, liketheMicrosoftWindowsServeroperatingsystem?

The reason the server version is so barebones is that in all things computer,whether you are dealing with Windows, Mac OS, or Linux, every feature orfunctionisalsoanattackvectorforahacker.Everyadditionalfeatureorfunctionthatyouputintoacomputerisapotentialweaknessthatahackercanexploitormanipulate.

LikewiththeMacoperatingsystem:althoughtheMacoperatingsystemisfairlysecure,hackershavelearnedhowtohackintotheAdobeFlashappletthattheMacoperatingsystemisusing,andthentakeoverthecomputerthatway.EventhoughtheMacoperatingsystemisabrick,theAdobeFlashfeatureofithasnowbecomea security vulnerability, andhackers can takeover a lovelyMac computerusingtheFlashsoftware.

Now,withLinuxservers, since theseare servers thataregoing tobemajorwebservers, database servers, or virtualization servers, youwant the server to be assecure as possible. One of the ways that youmake the server secure, is by notgivinghackerstheopportunitytohackanything.Thelessfunctionalityorfeaturesyour server has, the less opportunity there is for hackers to compromise yoursystem.

Withthatoutoftheway,letusproceedwiththeinstallation:

Download – The first thing thatwe need to do is get theUbuntu Linux serveroperating system. All you need to do in order to get the Ubuntu Linux serveredition is yougo tohttp://www.ubuntu.com/.Lookbelow to seehow thehomepageoftheUbuntuwebsitelookslike:

NowwithUbuntu, they are creating numerous versions of Ubuntu to domanydifferentthings.ThereisadesktopversionofUbuntu,thereisanetbookversion,thereisaversionforCloud,andthereisevenaversionforthePhoneorTablet.Now,sincewearelookingfortheserverversionofUbuntu,wearegoingtogoand

Page 24: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

findthelinkatthetopthatsays“Server.”Goaheadandclickon“Server.”

Afterclickingon“Server,”youwillbepresentedwith thescreenabove.Youwillalso see an orange rectangular button near the middle of the page that says,“DownloadUbuntuServer.”Goaheadandclickthat.

After you click on “DownloadUbuntu Server,” you will see two versions of theserverversionofUbuntu:theUbuntuServer14.04.4LTSandtheUbuntuServer15.10.Thedifferencebetweenthetwoisthatthe14.04.4LTSversionisthemoststablereleaseofUbuntuserver.IthasLongTermSupport,whichisimportantifyouareputtingthisversiononanenterpriseserverandwanttohavehelpifeveraproblemariseswiththeoperatingsystem.

Ontheotherhand,the15.10versionisthemostuptodateversion,anditiswheremost of the newest features are implemented. However, having the newestfeaturesdoesnotmean that it is stable.Thereare stillminorquirkswithin thisversionthatthedevelopersareworkingtosortout,andsupportforthisversionisonlyuptoninemonths.

Page 25: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

If you are installingUbuntu server for your business and you need to have themost stable version out there, you should get the Ubuntu Server 14.04.4 LTSversion.Ifyouwanttoplayaroundwiththenewfeaturesoftheoperatingsystemandyoudon’tmindthestabilityissuesthatyoumayencounter,youmaygofortheUbunteServer15.10version.

Now,afteryouhavechosenwhichversionofUbuntuserveryouwanttoinstall,itwill then ask you whether you want the 64-bit version, or the 32-bit version.Hopefully, if you are trying to figure out how touseLinux, youunderstand thedifference between 64-bit and 32-bit. If you do not understand the differencebetween the two, basically all you have to know is for the server version, youshouldtrytodownloadandinstallthe64-bitversion.

Ifthe64-bitversiondoesnotinstallontothecomputeryouaretryingtoinstalliton,thendownloadthe32-bitversionoftheoperatingsystem.Onceyoupicktheonethatyouwanttogowith,clickthedownloadbuttonandthenitwillstartthedownloadprocess.Keep inmind that the file size is around600MB, so itmaytakeawhiledependingonhowfastyourInternetspeedis.

With this, what is going to happen is the Ubuntu ISO file is going to bedownloadedtoyourcomputer.Inordertoinstalltheoperatingsystem,youneedtotakethatISOfileandburnittoaCDortoaDVD,andthenyouputthatintoyour computer.Make sure that you boot off of the CD orDVD. By default, thecomputer is set to boot directly to the hard drive of the computer where theoriginaloperatingsystemisinstalled.

IfyouwanttoinstallUbuntuinyourcomputer,makesureitbootsoffoftheCDorDVDfirstandnottheHDDorharddrive.Therearemanywaysonhowtodothis.However, themost common is by pressing the “DELETE” or “F1” key on yourkeyboardtoget intotheBIOSsettingsofyourmotherboard,andfromthereyoucan set where you want to boot the computer from. Different motherboardmanufacturers have differentways to get to theBIOS settings, somake sure toconsulttheuser’smanualofyourmotherboardonhowtodothis.

Installation – Once you boot off of the CD or DVD, it will now ask you whatlanguageyouwanttoinstallUbuntuLinuxin.

Page 26: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Atthispoint,justchoosewhateverlanguagethatappliestoyouandpressENTER.AfterpressingENTER,itwillnowshowyouthevariousoptionsforinstallation.

Thevariousoptionsforinstallationinclude,InstallUbuntuServer,InstallUbuntuEnterpriseCloud,Checkdiscfordefects,Textmemory,Bootfromharddisk,andRescue a broken system.Whatwe are going to do is simply install theUbuntuServer.GoaheadandhighlightthatoptionusingthearrowkeysonyourkeyboardandpressENTER.

AfteryoupresstheENTERkeyonyourkeyboard,theinstallationprocesswillaskyou to choose the language for the installation process itself. Note that thelanguagethatwewereaskedtochoosepriorwasforthelanguageoftheoperatingsystemitselfonceitisfinishedinstalling.

Page 27: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Goaheadandchoosethelanguagethatappliestoyouusingthearrowkeys,andthen press ENTER. After that, the installation will now ask you to choose thecountry,territory,orareayouareinrightnow.

Again,usingyourarrowkeyschoosethecountry,territoryorareathatappliestoyouandpressENTER.Next, itwillaskyouifyouwanttheinstallationtodetectyour keyboard layout. This is a necessary step since, as you know, Linux is aninternationaloperatingsystem.Therearecountriesthatutilizeatotallydifferentkeyboardlayouttotypetext.

Page 28: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Choose the“Yes”option ifyouareusingsomething likeaJapanese,Chinese,orsomeotherAsiankeyboardlayout.Otherwise,choose“No.”Afteryouhavemadeyour choiceandpressedENTER, the installationwill thenaskyou theoriginofyourkeyboard.

Go ahead and choose the option that applies to you and press ENTER. Now,dependingonyour chosenkeyboardorigin, the installationwill thenask you tochoose which specific keyboard layout that applies to your keyboard. If yourkeyboardoriginatedfromUSAforexample,theUSAkeyboardhasmanydifferentlayoutsliketheonebelow:

Page 29: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

GoaheadandchoosetheonethatappliestoyourkeyboardusingthearrowkeysandthenpressENTER.AfteryoupressENTER,youwillseethattheinstallationwillruntheconfigurationthatyouhavejustchosen.Oncethatisdone,itwillnowstartwiththenetworkconfigurationprocess.

As you can see in the illustration above, it is now asking you to enter the hostnameforyourparticularsystem.Basically,thisisjustthecomputername.IntheWindows operating system, we normally distinguish each computer by theircomputernames.InLinux,theequivalentofthecomputernameisthehostname.So,goaheadandjustenterthecomputernamethatyouliketoputandthenpressENTER.

After you press ENTER, it will now start configuring the system clock by firstaskingyoutochooseyourtimezone.

Page 30: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

After you have selected your time zone, press ENTER. Once you do that, theinstallationwillonceagainimplementtheoptionsthatyouhavechosen.Oncethatisfinished,theinstallationwillnowaskyouhowyouwantyourharddrivetobesetuppriortotheLinuxinstallation.

Rightnow,donotusetheoptionthatsays,“Guided–useentirediskandsetupLVM.”WewillgooverLVMin thesucceedingchapters.Fornow, justgoaheadand choose the option that says, “Guided – use entire disk” and press ENTER.Afterdoingthat,itwillnowaskyoutoselectthediskpartition.

Page 31: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Dependingonhowmanyharddrivesyouhaveonyourcomputer,thenumberofoptionsthatwillshowupherewillvary.JustgoaheadandchoosethecorrectharddiskwhereyouwanttoinstallLinuxandpressENTER.

AfterpressingENTER,theinstallationprocesswillnowasyouwhetheryouwanttowritethechangesthatyou’vemade—theoptionsyouchose—tothedisk.ThisisLinuxbasicallyaskingyouwhetheryouaresureabouttheoptionsyouchoseprior,and that if everything is as you prefer. If so, choose the “Yes” option andpressENTER.

Page 32: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Asyoucanseeintheillustrationabove,theinstallationwillnowimplementalltheoptionsthatyouhavechosen.ItwillinstallallthecoreessentialfilesnecessaryforLinuxservertofunctionproperlyonyoursystem.Now,dependingonwhatkindofcomputerandwhatkindofhardwareyouareputtingthison,thiscaneitherbeareallyquickprocessorrelativelyslowprocess.AndthatisthefunnythingwithLinux. You could be throwing this thing on anything from the most moderncomputer—a three thousand server computer fromDell—to the server that wasthreethousanddollarstwelveyearsago.

Linux, especially with the server version, will work regardless of how old yoursystemspecification is.ThesystemrequirementsofLinuxare so low that it canrun on what most people today consider outdated systems. Unlike MicrosoftWindows where the system requirements are somewhat heavy, Linux’s systemrequirementsareextremelylightthatyoucaneveninstallitonaUSBthumbdriveandrunthewholeoperatingsystemoffofthatonanycomputersystem.

AfterLinux isdonewith installing thecoreessential files, itwillnowaskyoutoenteryourfullnamefortheLinuxuseraccount.

Asitsaysonthescreen,yourrealnamewillbeusedasthedefaultoriginalnamewhenever you send emails, for example, aswell as any programs that show the

Page 33: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

user’srealname.Youarenotactuallyrequiredtoputyourfullnamehere.Soforthosewhoarenotcomfortableputtingtheirrealnamesdown,donotworry.

GoaheadandenterwhateverfictitiousnameyouwanttoputdownfortheLinuxaccount.Afterthat,theinstallationwillnowaskyoutoenterausernamefortheLinuxaccount.

JustenteranyusernamethatyouwanttouseandpressENTERagain.Now,itwillaskyoutoenteraspasswordfortheLinuxuseraccount.

Enter the password that youwant to your user account to have. After pressingENTER,itwillthenaskyoutore-verifyyourpassword,sogoaheadandtypeyourpasswordagainandthenpressENTER.

Now,takealookatthescreenbelow:

Page 34: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Ifyoureceiveascreensimilartotheoneabove,thisisLinuxbasicallytellingyouthatthepasswordyouhavechosenisweak.ThisishowsecureLinuxis.Itwilltellyou if you have aweak password, and that you have to change it and choose amuchhardertoguesspasswordthathackerswillhavedifficultyincracking.Ifyoureceivethisscreen,justgobackandreplaceyourpasswordwithamuchtougherone.

In the next step, the installation process will ask you whether you want toconfigure yourhomedirectory for encryption.What encryptionmeans is that itwill actually encrypt—encode—the filesand folders thatyouput intoyourhomedirectory.YourhomedirectoryisbasicallytheDocumentsandSettingsfolder inMicrosoftWindows.Itiswheremostofyouressentialfilesandsettingsarestored.

Most of you might think that enabling encryption right off the bat is good.However,theissueisthatsinceyouarebrandnewtousingLinux,itissuggestedthatyoudonotencryptyourhomedirectory.Otherwise,ifyouencryptyourhomedirectoryandthenyourLinuxcomputercrashes,youwillmostlikelyloseallyourdata.Ifyoudonotencryptyourdirectoryandyouaccidentallydosomethingyouarenotsupposed todoandcrashyoursystem, thenyoucanpull theharddriveoutandyoucanrecoveryourdataprettyeasily.

Ifyouencryptthatdirectory,itisgoingtobeencoded.WhenyourLinuxoperating

Page 35: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

systemdies,yourdatagoeswithit.Why?Becausethesystemisgoingtoassumethat your system has been compromised by a hacker and it will prevent thehackersfromgainingaccesstoyourfilesbydestroyingit.Sorightnow,sinceyouarestillbeginningtolearnhowtouseLinux,itisrecommendedthatyoudonotencryptyourhomedirectory.

Onceyouknowwhatyouaredoing,youcanencryptit.Rightnow,don’t.

Inthenextstep,theinstallationwillaskyoutoconfigureyourproxyserverifyouareusingone.Sinceyouarestillabeginneryouaremostprobablynotusinganyproxy server so just leave this option blank, choose continue and then pressENTER.

Okay.NowtheinstallationisnowgoingtoaskhowfrequentlyyouwantupdatestohappenonyourLinuxsystem.JustlikeMicrosoftWindows,Linuxneedsupdatestoo.

Basically, the installation is asking you if you want automatic updates to beinstalled. Again, since you are new at this, it is recommended that you do notinstall automatic updates. Aswhat we havementioned before, Linux is alreadystable and extremely secure. If you go in every couple of months and do the

Page 36: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

updates manually, you will be fine. Doing the updates manually allows you toknow what particular features or patches are added to your system for bettercontrol.

Because remember theautomaticupdates, if they install and there is aproblemwithone, then yourweb server thatwas justworking fine the otherday is nowcrashing.Soatthispoint,donotinstallautomaticupdates.

Next,youwillbepresentedwithaSoftwareselectionscreen.

Within thisprocess, it is actually asking youwhat kindof server youwant yoursystemtobe.Doyouwant it tobeaDNSserver?Doyouwant it tobeaLAMPserver?Doyouwantittobeamailserver?

Rightnowwearenotgoingtodoanything,partlysincewewillbediscussinghowtodothisinanotherchapter.Ifforexampleyouknowwhatyouaredoingandyouwanttomakeyourserverawebserver,goaheadandhighlighttheLAMPserver,hitthespacebaronyourkeyboardtoselectit,andthenpressENTER.

LAMPbasicallymeanswebserver.LAMPisanacronymforLinuxApacheMySQLPHPserver.Whenyouselectthisoption,thismeansitwillautomaticallyinstallallthecomponentsyouneedforthatApachewebserver.Becauselikewhatwehavementioned before, in the Linuxworld, they do notwant you to install anythingthatyouarenotgoingtouse.

In theWindows world, when you install their operating system, they throw ineverything including the kitchen sink, your neighbor’s kitchen sink, and yourgrandma’s kitchen sink. They just throw everything in when you install theoperatingsystem.Thegoodpartis,isthatitistheresoyoudonothavetoinstallalot of stuff later on. The bad part is again, aswe havementioned before, everysingle component that gets installed onto a computer is a potential securityvulnerability. IntheLinuxworld, theyaremuchmoreworriedaboutsecuritysotheydonotinstallanythingunlessyouwantittobeinstalled.

GoingbacktoourSoftwareselectionscreen,unselectanythingifyouhaveselectedaparticularoption.MakesurenothingisselectedandthenpressENTER.Thisis

Page 37: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

justgoingtobeabarebonesserver.

Next,youwillbepresentedwithaGrub-PCconfigurationscreen.

This is also called aGrub boot loader.Many people like using Linux, theymayadore Linux, and theymay even think that the entire world should run Linux.However, these people are also realists. They also know that they need to useMicrosoftWindowsonceinawhile.So,whattheydidwastheycreateddualbootcomputers.

Dualbootmeansyoucanbooteither intoWindows,oryoucanboot intoLinux.Youcansubdivideyourcomputer—yourcomputerharddisk—toaccommodate10differentoperatingsystems ifyouwant.Andwhenyoubootyourcomputer,youcanselectbetweenthoseoperatingsystems.

What theGrub configuration screen is askingnow iswhether youwant to do adualbootonthisparticularmachine.Dualbootingisbasicallyoutofthescopeofthisbooksinceitinvolvesaplethoraofoperatingsystems,notjustLinux.SoifyouwanttoknowmoreaboutthespecificsofDualbooting,therearemanyresourcesonline that canhelpyouwith that.But fornow, justgowith thedefaultoption,whichis“Yes,”andpressENTER.

Oncethatisdone,youwillnowgetascreenthatsaysthattheinstallationisnowfinished.

Page 38: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Onceyougetthescreenabove,readtheinstructionscarefullyandpressENTERtoboot into your newly installed Linux server operating system. After you pressENTER, your computer will restart basically and then you will get the screenbelow:

As you can see, you only have a blinking cursor that is asking you to enter thelogin credentials for the server. Just go ahead and enter the username andpasswordthatyoumadeduringtheinstallationandpressENTER.

Page 39: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

As soon as you enter your login credentials successfully, itwill give you a briefwelcomingtextonyourscreen.YouarenowloggedintoLinuxserveritself.SothatistheUbuntuserver.So,aswehavetalkedaboutbefore,peoplewhoinstallLinuxserverwillgetstuckiftheydonotknowthespecificcommandstonavigatearoundthecommandpromptofLinux.Thereisnographicaluserinterface—nothing.AllyougetissomethingthatlookslikeaDOS/Terminalscreen.

Page 40: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux
Page 41: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Chapter3:InstallingLinuxDesktopVersion

Now we will talk about how to install the desktop version of the UbuntudistributionofLinux.Whenyouinstallthisversion,attheendofit,youwillgetanicegraphicaluserinterface—youwillbeabletoseefilesandfoldericonsthatyoucanclickandusetonavigatearoundtheLinuxoperatingsystem.Itwillalsohavebasic applications like web browsers to navigate websites online, and wordprocessingapplicationssuchasOpenOfficeforwhenyouneedtotypedocuments,etc.Again, installation isaprettysimpleprocedure;you justclicka fewbuttonsandyouaregoodtogo.

Download–Justlikewiththeserverversion,gotohttp://www.ubuntu.com/anddownloadthedesktopversionofUbuntuLinux.

Clicktheoptionontopthatsays“Desktop”toproceedtothepagewhereyoucandownloadthedesktopversionofUbuntu.

Onceyouarethere,goaheadandclickontheorangebuttonthatsays“DownloadUbuntu.” After you click that, you will be presented with two versions of thedesktopversionofUbuntuLinux:Ubuntu14.04.4LTSandUbuntu15.10.

We have already explained the difference between the two versions in the last

Page 42: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

chapter,sogoaheadandchoosetheversionthatyouwanttoworkwith.Also, ifyou notice on the right hand side, it will ask you to choose your flavor of thatparticularversion.Thisisthemaskingyouwhetheryouwantto32-bitorthe64-bitversionof theUbuntuLinuxdesktop.Justchoose theversionthatapplies toyoursystemandthenclick“Download.”

GoaheadandwaituntilISOfiledownloadisfinished.Oncethat’sdone,burnthatISOfiletoaCDorDVD,putthatintothesystemwhereyouwanttoinstallLinux,andthenbootoffofit.Nowwe’llproceedwiththeinstallationprocess.

The interesting part that you will probably notice during the desktop version’sinstallationisthatitwillgiveyoutwooptions:tryUbuntuorinstallUbuntu.ThecuriousthingaboutLinuxisthattheyhavethingscalledLiveCDs.WhataLiveCDmeansisthattheentireoperatingsystemisinstalledandcanberunoffoftheCD.

WhenyouaredealingwithWindows,MacOS,orevenLinuxserver,youalwayshave to install theoperatingsystemfor it toworkonthecomputer.WithaLiveCD,youcanactuallybootstraightoffoftheCDanduseallofthefunctionalityoftheoperatingsystemwithoutinstallingit.Youcansurftheweb,managefiles,edittext,etc.byjustrunningtheentireoperatingsystemfromtheCDitself.

In addition, if youhave aWindows computer, you canput in a LinuxLiveCD,boot from it, and do whatever you want to do with it without affecting thecomputeratall.ThisisagreatwayforausertotestaparticularLinuxdistributionfirstwithoutgoingthroughthelengthyinstallationprocess.

So,goingbacktoourinstallationprocess,justgoaheadandclickinstallUbuntufornow.

Page 43: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Next,youwillbeaskedtochooseyourregionandtimezone.Goaheadandchoosetheregionandtimezonethatappliestoyouandclick“Forward.”

Again, just like in theserveredition, the installationwillnowaskyou tochooseyourkeyboardlayout.Goaheadandchoosetheonethatappliestoyouandclick“Forward.”

Next, the installationwill ask you to prepare the disk space in your hard driveprior to installation. If you want to use your entire disk for Ubuntu alone, go

Page 44: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

aheadandchoosetheoptionthatsays,“Eraseandusetheentiredisk.”However,ifyou have another operating system on your hard drive and you want to installLinuxinsideadifferentdiskpartition,thenchoosetheoptionthatsays,“Specifypartitionsmanually.”

SpecifyingpartitionsmanuallyinvolvestellingtheinstallationprocesshowmuchdiskspaceyouwanttoallocatefortheLinuxinstallation.Fornow,sinceyouarestillabeginner,letusassumethatyouarejustinstallingLinuxaloneinyourharddrive,andthatyouarenotgoingtodoanypartitioning.Sogoaheadandchoose,“Eraseandusetheentiredisk”andpressforward.

Afteryoupress“Forward,”theinstallationwillaskyouwhatyournameis,whatnameyouwant touse to log in, thepassword that youwant toput for theuseraccount,andthenameyouwanttogivetheLinuxcomputer.

Also,ifyouscrolldownalittlebit,youwillseethattheinstallationisaskingyouwhetheryouwanttologintothecomputerautomaticallyonceitbootsup,requireapasswordduring login, and require apasswordduring loginanddecrypt yourhome folder. The latter option only applies if you installed Linux with theencryptionfeatureenabled.

Goaheadandentertheinformationneededandthenpress“Forward.”Next,the

Page 45: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

installationprocesswillshowyoutheallthesettingsandoptionsyouhavechosenso far andwhat it is about to do. If everything looks okay, go ahead and press“Install.”

Onceyouclickinstall,theinstallationwillnowproceedandyouwillseeawindowthathasaprogressbaratthebottom.Atthispoint,justexercisepatienceandwaituntiltheprogressbarreaches100%.

Once the progress bar reaches 100%, it will tell you that the installation iscompleteandthatyouneedtorestartyourcomputertofinalizeandusethenewinstallation.Goaheadandclick“RestartNow.”

Page 46: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Again,theactualtimethatitwilltakefortheprocesstofinishwilldependonyourhardware. Do realize you should look at the hardware requirements for thedesktop version of the Ubuntu Linux operating system. Remember, the serverversionisextremelystrippeddown.Thereisalmostnothingtoitreally.

Thedesktopversionhasall these fancygraphicsanduser interfaces,asyoucanevidentlyseeevenfromtheinstallationitself.Wheretheinstallationoftheserverversionbasicallyistextbased,theinstallationforthedesktopversionactuallyhasgraphical user interfacewindows and optionbuttons that you can actually clickon.

Allofthesefancygraphicalnicetiesactuallydoesrequireprettydecenthardware.It is therefore recommended that if you are going touse thedesktop versionofUbuntuLinux,yourcomputershouldbeatleastfiveyearsoryoungerwithatleast1GigabyteofRAM.Ifyouhaveanylessthanthat,itmaynothavetheresourcesitrequirestorun.

Butinthegranderscopeofthings,thedesktopversionofLinuxstillhasamuchlightersystemrequirementcomparedtoMicrosoftWindowsorMacOS.

After the restart sequenceof your computer is done and you finish logging intoLinux using the credentials that you entered during installation, you will nowreachthedesktopofUbuntuLinux.

Page 47: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Just likewhat we havementioned prior, you now have something that vaguelylooks likeMicrosoftWindows or theMacOS operating system. As you can seerightoffthebat,youhaveyourapplicationsonthelefthandsidesuchasFirefoxforwebbrowsing,OpenOfficeSuiteforwordprocessingtasks,yourhomefolder,Linuxsettings,Amazon,andmuch,muchmore.

So,thatistheUbuntuLinuxdesktopversion.

Page 48: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux
Page 49: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Chapter4:BasicLinuxTasks/Commands

In this chapter,wearegoing togoover thebasic tasks that youcanperform inLinux. We are going to show you how to install applications, how to updateapplications,howtolookattheLinuxtaskmanagerandeventerminateprocessesifnecessary,howtostartservices,andawholelotmore.ThesearethebasictasksthatyouwillneedtounderstandinordertodoanythingelseinLinux.

Everything thatwill be shownherewill beon theUbuntuLinux server version.Thisisnotthedesktopversion.YouaregoingtobelookingattheLUI,orthelineuserinterface.Youwillbetypingincommandsonthekeyboardinsteadofclickingabunchofoptionsinagraphicaluserinterface.

Whilethismayseemalittledauntingandtedious,keepinmindthatinLinux,alltypesofseriousadministrationhave tobedoneat thecommand line.This isanoperatingsystemdevelopedbyprogrammersforprogrammersprimarilyafterall.

EvenifyouareusingthedesktopversionofUbuntuLinux,itdoesnotgiveyouthefullpoweroftheoperatingsystemunlessyouusetheterminalorcommandlinetoexecutecertaintasks.Alotoftimes,evenifyouareusingadesktopversion,youstillhave toopenupa terminal screenand typeout all the commands that youneedtotypeouttoadministerthesystem.

Page 50: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Sudo

The first command thatweneed to talkaboutbeforeyoustartdoinganyof theothercommandsis“sudo.”Sudobasicallymeans“superuserdo.”Inthepreviouschapters,we discussedhowdifferent distributions do things slightly differently,andthateverysingledistributionofLinuxhasitsownquirks;itsownlittlewaysofdoingthingsdependingonwhatthecreatorsareworriedabout.

One of the things that the creators of Ubuntu Linux were worried about wassecurity.Aswhatwetalkedaboutbefore,ineveryLinuxcomputer,thereisausercalledRoot.Root is thehighest leveluseronthecomputer. It iskindof like theadministratorinaMicrosoftWindowscomputer.

JustlikeonaWindowscomputer,ifsomebodyloggedinastheadministrator,orsomebodyloggedinasrootonLinux,theycandoabsolutelyanythingtheywanttothat computer. They can install viruses, malware, or spyware, or basically justcausealotofhavoc.Hackers,usingspecialprogramsandscripts,canalsotrytologinasRootandcausealltheseproblems.

Toalleviatethepossibilityofahackerobtainingrootaccess,theUbuntucreatorsdecidedtheyneverwantanybodyto loginstraightasRoot.So inUbuntuLinux,youcannotloginastheuserRoot.

Now,herecomestheproblem.SinceyoucannotloginasRoot,howdoyoudoallthese administrative tasks then?How do you execute administrative processes?Whattheyhaveisthisprogramcalledsudo.Itisbasicallyacommandprefixthattells theoperatingsystemthatyouwanttorunaparticularprocessasthesuperuserorroot.

Sudo temporarily gives a user administrative access—root access—to execute anessential command in Linux. In the Windows operating system, sudo is theequivalent of the “Run as Administrator” option each time you want to run aprogramwithadministrativerightsinWindows.

Page 51: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

ManPages

The next thing we need to talk about are “man” pages. Man pages stand formanualpages.Whatyouhavetorememberwithmanpagesisthatifyoudonotunderstand how a command is supposed to work or what command you aresupposed to run, the man pages is where you look up information about anycommand.

Let us say for example that you want to look up information about the pingcommand.What youdo is you type inman followedby the command that youwanttofigureout.Lookatthesyntaxofthisbelow:

$manping

What thiswilldo inLinux is itwillopenupapage thatwilldescribe toyouthepingcommandandeverythingthatyouneedtoknowaboutthepingcommand.Soifyouaretryingtofigureouthowaparticularcommandworks,allyouneeddoistypeinman,aspace,andthenthenameofthecommand,thatwillthenopenupamanualpageforyouwhereyouwillbeabletoreadaboutwhateveritisyouwanttoknowaboutthatparticularcommand.

Nowadays,intheageoftheInternet,doingasimpleGooglesearchisawholeloteasierthantryingtodoitwiththemanpage.However,ifInternetaccessisdown,itisgoodtohavethemanpageshandy.

InWindows,themanpagesisbasicallytheold“questionmark”commandwhereitshowsyouthe“Help”pages.TheonlydownsideabouttheManpagesinLinuxisthatitdoesnotexplainalotofthingstoyou.Itdoesnotmakethingsnecessarilystraightforward.

Sowhenyougotothemanpagesandlookupthepingcommand,youaregoingtoget this whole page of text that is going to tell you about the ping command.However, once you are there, you arenot going to knowhow to get out of thatpage.Itisnotuser-friendlyandstraightforward.YoucanhittheEscapekey,butthatisnotgoingtodoanything.YoucantrytohitEnterorBackspace,buttheyarenotgoingtodoanything,either.

Inordertoexitoutofthemanpages,youneedtotypeintheletter“Q”forquit.Whenyoutypetheletter“Q,”youwilldropoutofthemanpages.Sounlessyoupresseverykey inyourkeyboardandexperiment,youwillnot findout that thecommandtoexitoutofthemanpageisbytypingtheletter“Q.”Asyoucansee,thisiscounter-intuitivesincemostpeopleareusedtopressingtheEscapekeyinWindowstoexitoutofanything.

So now, let us say youwant to knowwhat theping command is all about. Goaheadandtypethecommandbelow:

$manping

Afteryoutypethat inandpressENTER,youwillseethemanpageforthepingcommandjustliketheonebelow:

Page 52: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Looking at the man page for the ping command, you will see the commanddescription,andalsothevariousoptionsassociatedwiththepingcommand.Theoptions are basically ping command suffixes which further augment what thebasicpingcommandcando.Oneexampleofthisistypingthesuffix“-t”afterthepingcommandtocontinuouslypingaparticularhost.

Now, let us say you want to knowwhat the apt-get command is all about. Goaheadandtypethecommandbelow:

$manapt-get

OnceyoutypethatinandpressENTER,youwillgetthemanpagefortheapt-getcommandliketheonebelow:

And now, thismanpage for theapt-get command will tell you everything youneedtoknowabouttheapt-getcommand.Likewhatwehavementionedearlier,someof themanpages for these commandsareaboutas longas awholebook.Remember,ifyouwanttogetoutofthemanpageforanyreasonatall,justpressQonyourkeyboardtoexit.

Page 53: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Tasksel

Thenextcommandthatwearegoingtotalkaboutistasksel.Thisstandsfor“taskselect.” Now, Ubuntu is trying to become the premier provider of Linuxdistributions.Theyhavereallydonea lotofworkto improveUbuntuLinuxandtheyknowhowtomakethingsasuser-friendlyaspossible.Withthatinmind,oneofthethingstheycameupwithwasthisprogramcalledtaskselortaskselect.

When you are trying to set up an Apache web server, an email server, or avirtualization server, for example, note that each of these servers requires anumberofdifferentprogramsinorderforittowork.Soifyouaretryingtosetupawebserver,youneedtoinstallApache,youneedtoinstallmySQL,youneedtoinstallPHP,andyouneedtoinstalltheconnecterssothattheycanactuallyworktogether.

TheUbuntucreatorsthenfiguredthatifyouneedtoinstallthosethings,theycancreateascriptthatwouldjustinstallallthosethingsforyou.Sowhatwillhappenis, if you know exactlywhat youwant your server to do and you are really notworriedaboutmakingitreallycustomized,youcanrunthetaskselcommandandchoosewhichpre-packagedservertypeyouwantyourservertobe.

The creators of Ubuntu came up with around ten to twenty different serverinstallationpackagesthatyoucouldchoosefrom.Andwhathappensisifyourunthe tasksel command, you will get a DOS screen where all of these serverinstallationpackagesare listed.Ifyouwanttomakeyourserveranemailserverforexample,allyouneedtodoisselectEmailserverandthenitwillinstallallthenecessarysoftwareyouneedforthatparticularservertype.

This facilitates for a hassle-free installation. It is quick and extremely user-friendly.YoucanhaveafullApachewebserverrunningin30minutesorlesswiththiscommand.

Themainthingthatyouhavetorememberwiththiscommandisthatyouhavetoputsudoinfrontofthecommand.Youmightbewondering,howcomewedidnotputsudowhenweexecutedthemancommand?Well,themancommanddoesnotnecessarily pose any security risk when executed. It is therefore one of thosecommandswheresudoisnotnecessary.

Withthetaskselcommand,however,rememberthatweareinstallingapplicationswiththiscommand.Installationrequiresmodifyingcertainfiles intheoperatingsystemtoaccommodateacertainprogram. Ifahacker someonemanages togetaccessandexecutethetaskselcommand to install viruses,youwillbe inhavingrealbigproblems.

The creators of Ubuntu realize this as well. They are worried about peopleinstalling software that should not be installed onto the server. So, if you aretrying to install software, or do any administrative task, you have to put sudobeforethecommandthatyouaretryingtoinitiate.Withthatinmind,toproperlyexecutethetaskselcommand,youhavetotypeinthesyntaxbelow:

Page 54: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

$sudotasksel

Onceyoutype inthecommandaboveandpressENTER,youwillget thescreenbelow:

So now, you are in the tasksel screen. If you look closely, you will see variousoptionsthatyoucanselect.Theseareallthedifferentpackagesthatyoucaninstalleasilyontotheserver.Ifyouwantyourservertobeusedincloudcomputing,youcanselectoneofthecloudcomputingoptionsavailable.IfyouwantyourservertobeaDNSserver,youcangoaheadandselectDNSserver,andsoforth.

Onceyouhavehighlightedthepackageofyourchoice,yousimplyhitthespacebaronyourkeyboard.Thatwillputanasterisk,andinsomecasesacheckmark,ontheboxon the leftandthenyoucanpressENTER.WhenyouhitENTER,whatwill happen is the server will now install all of the software packages that arerequiredinorderforittowork.

This process will take a fewminutes depending on how fast your computer is.Oncetheprocessisdone,youwillthenhaveafullyfunctionalserver.

Page 55: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Apt-get

Nowwearegoingtotalkabouthowyoucaninstallindividualprograms.ThethingthatyouhavetorememberwithLinuxisthatthisisanopensourceworld.Mostofthe software is free,or youpay for it inweirdways like serviceagreementsandsuch.IntheWindowsworld,everythinghastogothroughactivationprocedures.

So, whether you are using Quickbooks, Adobe, or Microsoft software itself,everybody is worried that somebody is going to pirate or steal a product. Toprevent their software from being pirated, they put in these insane activationproceduresthatrequireyoutohavetheCDwiththecorrectCDkey,etc.Andthenbeyondthat,onceitisinstalledwiththerightcode,youthenhavetogooffandhitsome activation server so that the creators of the software can verify yourinstallation.

InLinux,theyareabletocreatethingscalledrepositories.RepositoriesareplacesontheInternetthatjusthousethousandsuponthousandsofLinuxprograms.Soinsteadofhavingtohaveadiskofsomesort,youcanjustgotothatrepositoryandinstalltheapplicationfromthere.

InWindowsorMacOS,youhavetohaveaCDorDVDofthesoftware.Ifyoulosethat disk, you are screwed. In Linux, all the software, or a huge portion of thesoftware is out sitting in these repositories. You can just go and grab softwarefromtheserepositoriesaslongasyouhaveInternetconnection.ThisistheeasiestwaytoinstallsoftwareontheLinuxplatform.

ThereareotherwaystoinstallapplicationsinLinux,andwewilltalkabouttheminthelaterchapters.Butfornow,sincewearestilldiscussingthebasics,wewilljustfocusoninstallingfromrepositories.

So basically, within a Linux computer, there is already a configuration file thattellsthatLinuxcomputerwheretherepositoriesare.Whenyourruntheapt-getcommand, this apt-get command will go out to the repository and it will getwhateverprogramitisthatyouwanttogetandinstallitforyou.

Tocorrectlyexecuteanapt-getcommand,justtypeinthesyntaxbelow:

$sudoapt-getinstall<nameofprogram>

Let’ssayyouwanttoinstalltheApache2programinyourserver.Simplytypeinthecommandbelow:

$sudoapt-getinstallApache2

Afteryou type theabovecommandandpressENTER,Linuxwill thengoout totherepositorysittingontheInternet,findtheApache2program,andtheninstallitonyourLinuxcomputer.It’sthateasy.

Now, let’s say youdecide that youdonotwantApache2and youwant to use adifferentwebserverinstead.Well,thecommandtheuninstallApache2is:

$sudoapt-getremoveApache2

Page 56: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

ThiswillgoinanduninstallApache2fromyourLinuxcomputer.It’sthatsimple.This ishowyou install anduninstallmostof the software that youare going toneedforyourLinuxserver.OnceyougetbetterandyougainmoreexperienceinusingLinux,youwillstartbuyingproprietarysoftwareintheLinuxworld.

Youmaybuyspecialbackupsoftware,ormaybeaspecialsecuritysoftware.Someofthesetypesofprogramsmaynotbeintherepositories,andyoumayhavetogothrough different steps in order to install those programs. But for 99% of theprogramsthatanybodyeverinstallsforLinux,thisapt-getcommandwillwork.

There are thousands and thousands of Linux programs in these repositories.Figuringoutwhatprogramsyouwanttoinstallcanbealittlebittricky.Ifyoudonotknowwhat are thebestprograms tohave in yourLinux computer, thebestthing to do would be to make a Google search about it. You’ll find manyrecommendedLinuxprogramsouttherethataregreatforbeginners.

As you probably know by now, everybody pokes fun at the people behindMicrosoftWindows because they always have these updates. Every third day oftheweekoreverymonthyougetatleast10updatesforyoursystem.Manypeoplesay that these updates are proof thatMicrosoft is crap. However, the reality isevery singleoperating systemor softwareneeds to getupdatedonce in awhile.ThesameistruewithLinux.

So,onceyouinstallall thesoftwarethatyouwantonyourLinuxserverandyouwant to update them, all you need to do is use theupgrade command. See thesyntaxbelow:

$sudoapt-getupgrade

What the above command will do is it will see whether the program in therepository is newer than the one you have on the server. If the version of theprogramthatyouhaveisolderthantheonesintherepository,itwillbringdownthatinformationanditwillaskyouwhetheryouwanttoupdateyoursoftwareornot.IfyousayYes, itwillautomaticallyupdateallthesoftwarethatyouhaveonyourcomputer.

Thisisbasicallyallyouhavetounderstandatthispointwithregardtoinstallingandmaintainingyoursoftware.

Page 57: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Services

Likewhatwehavepreviouslymentioned,Linuxisbestforservers.OnceyouturnaLinuxserveron, theycan justgountil thehardwareburnsout, literally.OnceyouturnaLinuxsystemon,thereareveryfewtimesyouactuallyneedtorebootit.When we say very few times, we are talking once a year; and that is alreadyoverkill.

However,whenyougoinandchangeyourconfigurationfilesinthesoftwarethatyouhaverunningonyourserver,youmayneedtorestartthatindividualsoftwareorthatindividualservice.LetussayyouhaveApache2installedontoyourLinuxserverandyouchangesomeoftheconfigurationfiles.ThoseconfigurationfilesdonotgetloadeduntilyourrestarttheApache2service.

Although thecomputer staysonall the time,youdohave to restart theserviceseveryonceinawhilejusttomakesuretheyareup-to-date.Whatwearegoingtoseenowishowtostart,stop,andrestartservices.

Withthis,youneedtotypeinthesyntaxbelow:

$sudo/etc/init.d/<nameoftheprogramorservice>start

$sudo/etc/init.d/<nameoftheprogramorservice>stop

$sudo/etc/init.d/<nameoftheprogramorservice>restart

So, let’ssayyouchangedtheconfigurationfiles intheApache2programinyourserverandyouneedtorestartit.Simplytype:

$sudo/etc/init.d/Apache2restart

This would restart the Apache2 service, which would bring online whateverconfigurationchangesthatyouhavemade.Now,let’ssayyouareplayingwiththewebserver,youaremakingsomechanges,andyoudonotwantanybodyfromtheoutside world coming in while you do the changes. So you want to stop theservicesentirely,whichbasicallymakesthewebservergooffline.Allyoudois:

$sudo/etc/init.d/Apache2stop

The above command stops theweb service.However, it does not stop anythingelse. Thismeans thatwhile nobody from the outsideworld is able to reach thewebsite that you are hosting, you are still able to make changes to theconfiguration files, editoptions,modify settings,etc.Only theactualwebservercomponentisnotfunctioningatthispoint.

Let’snowgoaheadandlookathowthislookslikewhenyouactuallyexecuteitatthecommandpromptofLinux.

Page 58: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

So right now we’re at the command prompt or terminal of our Linux serveroperatingsystem.Inthisexample,letusassumethatyouhaveApache2installedonyour system, and that youwant to stop that service.The first thing that youshould do is type in the word sudo, put a space after the sudo, then type in/etc/init.d/Apache2,putaspaceagainafterthat,andthenthewordstop.

AssoonasyouhitENTERaftertypingintheaforementionedcommand,youwillgetthebelowscreen:

Asyoucanseeinthescreenabove,Linuxhassuccessfullystoppedtheservice.Atthis point, the domain that thisweb server is hosting is not accessible over theInternet.Thewebsiteiscurrentlyoffline.Tostarttheservice,allyouneedtodoistype the same command that we typed when stopping the service, with theexceptionoftypingstartinsteadofstopattheend.

Page 59: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Whenrestartingaservice—startingandstoppingaserviceautomatically—simplyenterthesamecommand.Theonlyexceptionisinsteadoftypingstartorstopattheend,youtyperestart.Again,whatisincrediblynicewiththisinLinuxisthatyoudonothavetorestarttheentireserver.

If you restart an entire server, nomatter how fast the operating system is, it isgoingtotakeacoupleofminutesbeforeeverythingisonline.Ifyouonlyhavetorestarttheservice,everythingwillbebackonlineinseconds.

Page 60: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Top

Thenext thing thatweneedto talkabout is thecommandcalled top.If youarecomingfromtheWindowsworld,thinkofthetopcommandasbasicallyyourtaskmanager.So,ifyougotheLinuxcommandpromptandtypeintop,whathappensisyouwillseehowmuchyourmemory isbeingused,howmuchofyourCPUisbeing used, and then all of the processes that are currently running on yoursystem.

You will see something called the processor ID or the PID, the CPU usage perprocess, thememoryusageperprocess,howlongtheprocesshasbeenrunning,etc. So basically, the top command is the taskmanager of the Linux operatingsystem.

IntheWindowstaskmanager,ifaprocessisrunningandyouneedtoterminateit, youcan justdoa right-clickusingyourmouseanddoEndprocess. InLinuxwithtop,ifyouneedtoterminateorkillaparticularprocess,youjustneedtotypeinthesyntaxbelow:

$K<PID>

Soasyoucanseefromthecommandsyntaxabove,allyouneedtodoistypeintheletterKandtheprocessIDnumber.So ifyouseeprocess1578doingsomethingstupidforexample,youtypein:

$K1578

Typingthatcommandinwillkillthatparticularprocess.AlltheprocessesinLinuxget their own unique process ID number. So if one particular process is doingsomethingthatitisnotsupposedtobedoing,itisextremelyeasyfortheusertoidentifythatprocessthroughthePIDandterminateit.

Remember, thekillor terminatecommandwillonlyworkwithin top.If youarenotwithinthetoptaskmanager,thekill/terminatecommandwillnotworkonitsown. If the particular process that you are trying to terminate is somethingimportantfortheLinuxservertofunctionproperly,itwilltellyouthattheprocesscannotbekilled/terminated.Ifthatisthecase,youmayhavetodoyour“onceayear”rebootinordertokilltheprocess.

So,inordertoseethetoptaskmanager,allyouneedtodoistypeinthecommandbelow:

$sudotop

Onceyoutypethatin,youwillhavethescreenbelow:

Page 61: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

The illustration above shows how the top task manager looks like. If you lookclosely, you can see what the up time for the computer is, the total number oftasks,what thecurrentCPUusage is, thememoryusage,buffers swap files,etc.This basically gives you the same information a task manager would in theMicrosoftWindowsoperatingsystem.

Youcanseerightnow,upatthetop,thereisprocessID1489andtheuserisroot.Andifyoulooktothefarrightofthat,youwillseethatprocessID1489isactuallyfor the top taskmanagerprocess.You canalso see theCPUusage, thememoryusage,andthetimethatthetopprocessisupandrunning.

Now,ifyouneedtounderstandhowtousethetopcommandbetter,youcantypeintheletter“H.”TypingintheletterHwillshowyouthedifferentcommandsthatyoucanusewiththetopcommand.

What you see after typingH is basically the help page for the top command. Itdisplaysallthesub-commandsthatyoucanusewithinthetopenvironment.Togobacktothemaintopenvironment,justpressanykey.

Now,let’ssayyouwanttokill/terminateaprocess.Letussayyouwanttokillthetoptaskmanagerinordertoexitoutofit.Soagain,asyoucanseetheprocessIDfortopis1489.First,typeinK,andthenitwillaskyouwhichPIDtokill.

Page 62: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Once itasksyouwhichPIDtokill, type1489and thenpress theENTERkey. Itwillthenaskyoutore-verifythatyouwanttokillprocess1489.

GoaheadandpressENTERagain to terminate the toptaskmanager and bringyoubacktotheLinuxcommandprompt.It’sthatsimple.

Page 63: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux
Page 64: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Chapter5:BasicLinuxNavigation

NowweneedtotalkaboutbasicfoldernavigationintheLinuxoperatingsystem.ThisisslightlydifferentfromMicrosoftWindows.However,thefunnythingisitlookscloseenoughtoWindowsthatwhenthingsdonotworkright,peoplehavetheurgetowanttopickuptheircomputerandthrowitoutthewindow.

Take the abovediagram for example. InLinux, youalsohave thecd command.JustlikeinWindows,thecdcommandstandsforchangedirectory.Ifyouwanttogotoadifferentdirectoryorfolder,youtypeincd.Ifyouareinafolder,letussayyouareinthevarfolderinourillustration,andyouwanttogotoafolderwithinthevarfolder,whichinthiscaseistheabcfolder,allyouneedtodoistypeinthecommandbelow:

$cdabc

So,thatiscd,aspace,andthenthenameofthefolderthatyouwanttogoto.Thatwill drop you in the folder that you are trying to go into.Now, the problem is,people in the Windows world are used to following the cd command with aforwardslashsymbol. Ifwewere toapply this inourpreviouscommand, itwilllookliketheonebelow:

$cd/abc

WhatLinuxdoesinthiscaseisitinterpretstheforwardslashsymbolastherootfolder.Linuxwillthinkthatyouwanttochangetotherootfolder,andthenlookfor the abc folder within the root folder. Of course, once Linux executes thiscommand,itwillnotbeabletofindanexistingabcfoldersince inactuality, theabc folder is located in thevar folder. That is where you have to be extremelycareful.

ThisisonereasonwhyalotofLinuxadministratorsalwaystypeinthefullpathto

Page 65: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

wherever they are trying to go, no matter where they are at. If a Linuxadministratoristryingtogoinandchangesomethingintheabcfolder,theywilljusttypeinthecommandbelow:

$cd/etc/var/abc

Linuxisfinickyaboutthiswholechangedirectorysyntax.Aswehavementionedbeforeaswell,capitalizationmattersinLinux.Ifyouaretryingtoreachafolderwhose name is written in all lowercase, and you type the folder in all capitalletters, Linuxwill not be able to find it; itwill say that the directory cannot befound.

Allofthisisimportantforyoutounderstand.Itcanbeextremelyfrustratingifyoudonotgraspit.

So, the first thing youwant to dowhen navigating files and folders in Linux ismake sure that you are in the root directory. To do this, you must type thecommandbelow:

$cd/

Thatiscd,aspace,andthenaforwardslash.Thisisautomaticallybringyoutodotherootdirectory if you arenot already there.Now thenext logical thing todowouldbetoseewhatfoldersarewithintherootfolderitself.Todothis,youmusttypethecommandbelow:

$ls

The ls, or list command will list all the files and folders within a particulardirectory—root,inthiscase.

Page 66: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Asyoucanseeafter typing in the lscommand,Linuxwillnowshowyouall thefoldersthatarewithinintherootdirectory.Youcansee lotsof foldershere likethebin,dev,opt,sbin,sys,var,boot,etclib,andsoforth.

Now,let’ssaywewanttogotoinsidetheetcfolder.Allyouneedtodoistypeinthecommandbelow:

$cdetc

Thecommandabovewillautomaticallydropyouinsidetheetcfolder.Ifyoulookbesidetheblinkingcursorof thecommandprompt, itwillsay/etc$.That is themain indication thatyouare indeed inside theactual folder thatyouwant togointo.Ifyoudothe lscommandagain, itwillshowyouall thefileswithintheetcfolder.

Inordertogobacktotherootfolder,allyouneedtodoistype:

$cd/

Thiswillautomaticallyreturnyouto therootdirectorynomatterhowdeepyouarewithinthefolders.

Nowlet’ssayyouwanttogobacktotheetcfolder.Butthistime,insteadoftypingetcinalllowercase,youtypeditinalluppercase.

Page 67: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Asyoucansee,LinuxwillnotbeabletofindthedirectorywithanuppercaseETC.Why? Because Linux cares about capitalization. Uppercase letters are differentfrom lower case letters in the Linuxworld. Basically, that is all there is to it inLinuxbasicnavigation.

Page 68: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux
Page 69: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Chapter6:EditingLinuxFileswithVim

ThischapterisaboutVimforfileeditingwithinLinux.WhenyouaredealingwithLinuxsystems,editingconfigurationfilesisanextremelyimportantthing.Ifyouwant a piece of software to do something specific, or if you want to customizesomething, you almost always have to open up a little configuration file andactuallyeditit.WhetheritisaPHP.inifile,whetheritisapasswordfile,whetheritisthe.htaccessfile,basicallyalltheconfigurationsinaLinuxsystemareheldwithin a simple text file that you have to edit in order to make the system dodifferentthings.

Now, there are a lot of different editors out there thatmany people use to editconfiguration fileswithinLinux.Wearegoing tobe talkingaboutVim,which isoneofthemostpowerfulfileeditorsavailableforLinux.

Oneofthebigthingsthatyouhavetounderstand(sincemostofyouarecomingfrom the Windows operating system) is that in Linux, there are no fileassociations.Whatwemeanbythis isthat inWindows,youalwayshavethefileextension—association—after the filename.Forexample, if youhaveaMicrosoftWorddocumentnamedNotes, youwillnotice that the file extension that itwillhave is either .doc or .docx. Therefore, its complete filename would be eitherNotes.docorNotes.docx.

The file extension iswhat tells theWindowsoperating systemwhat program touse to open that file. InLinux, there are no file associations. This is one of themainreasonswhymostpeopleareafraidofusingLinux;nofileassociationsatall.Basically,allyouhaveisjustafilename.That’sit.

Now youmay be asking, “How do you know if it is a text file or any other filetype?”ThatisactuallytheweirdthingaboutLinux.Theyexpectyou,asthesystemadministrator, toknowwhat that file is.So if youaregoing tomodify text files,understandthattheyarenotgoingtohave .txt fileextensions.Itwill justbethefilename.Youmustunderstandwhatfileitisyouneedtomodifyfirstbeforeyouuseafileeditorsoftwaretoeditthatfile.

AlltheconfigurationfilesinLinuxhavetobeeditedusingafileeditor.Ifyoudonotunderstandhowtoeditdocumentsortext inLinux,youarenotgoingtogetanywhere.

Page 70: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

StartingVim

Now,we need to talk about how to startVim, particularly howdo you open orcreateafilewiththem.Itisprettystraightforward.Thefirstthingthatyouwanttodo is type the command sudo, followed by a space, followed by the word vim,followedbyanotherspace,andthenthenameofthefilethatyouwanttoopen.

$sudovim<filename>

Noticethatthewordvimisinalllowercase.Remember:capitalizationisessentialinLinux,somakesuretotypeviminalllowercase.Thesamethingapplieswhentypinginthenameofthefilethatyouwanttoopen.

That isall thatyouhave todo toopena fileusingVim.If, forexample,youaretryingtoopenaPHP.inifile,simplytypethecommandbelow:

$sudovimphp.ini

Now, if youare trying to createanew file, the “$sudovim<filename>”syntaxalsocreatesfiles.Soifyoutypethatcommandinthecommandprompt,thatwillcreatethefileandopenitatthesametime.Withthatinmind,openingfilesandcreatingfilesusestheexactsamecommand.

Forsomeofyouuserswithexperience inusingotherversionsofLinuxwhoarealsoreadingthisbook,youmaynoticethatyoucanrunthevimcommandwithoutsudo. The problem with running vim without sudo, at least in the Ubuntudistribution,issometimesitwillworkrightandsometimesitwillnot.Itisacase-to-casebasiswhereinsomeoftheconfigurationfileswillopenandcanbeeditedwithoutusingsudowhileotherswillnoteditproperly.

Andyoucanrunintoproblemswhere,ifyouopenaconfigurationfilewithsimplyvimand the filename,youwillnotbeable tosave the fileonceyouare finishedediting it.Why?Because youdidnot open that file as an administrator.This iswhy it is always considered good practice to use sudowhenever you are doingcriticaltasksinLinux.

Page 71: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

ChangingFileOwnership

Fileownership isanother important thingthatweneedto takenoteofsinceweare usingVim to edit configuration files. So what do we basicallymean by fileownership?KeepinmindthatmostofthesoftwarethatyouinstallonyourLinuxsystemcamefromtheirrespectivedevelopers.Inotherwords,theycamefromanexternalsource.WhenyouinstallthemontoyourLinuxsystem,theownershipofallofthefilesofthatsoftwaretechnicallystillfallsonthedeveloper.

Now,here is theproblem: InLinux, you cannot edit any fileunless youare theowner of that file. For example,when you installApache2,mySQL,orPHP onyourLinuxwebserver,allthefilesassociatedwiththatsoftwareisownedbyrootofthesourceofthefile.Ifyoutrytogoinandeditsomeofthosefiles,manytimesyouwillnotbeabletoeditthembecauseyouarenottheowner.

So,ifyouaregoingtoeditconfigurationfiles,thefirstthingthatyououghttodoischangetheownershipfromwhoeveritistoyou,justtomakeyourlifeeasy.Todothat,yousimplytypeinthiscommand:

$sudochown<username><filename>

Theusername in theabovecommandpertains to thenameof theuser thatyouwanttochangetothepermissionto.Filename,ontheotherhand,pertainstothenameofthefilewhoseownershipyouwanttochange.

Letussayyourusernameisreaderandyouwanttochangetheownershipofthefilenamednotes.Allyouneedtodoistypethecommandsyntaxbelow:

$sudochownreadernotes

Onceyoudothis,youwillnowbecometheownerofthefileandthuswillhavetheabilityorpermissiontoeditit.

Page 72: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

EditingandNavigating

NowthatyouknowhowtoopenafileusingVim,thenextthingthatyouneedtounderstandishowtomodifyafileusingVim.Thefirstthingthatyouwillnoticewheneditingavimfileis that, ifyouusethearrowkeystomovethecursorandstarttypingtoeditthefile,nothinghappens.ThereasonisthatyouhavetoentertheInsertmodeinVim.

InordertoentertheInsertmodeinVim,yousimplytypetheletter“a.”Onceyoudo that, youwill be able to edit and start typing yourmodifications on the file.Whenyouaredonemakingyourmodificationstothefile,whatyoudotogetoutoftheInsertmodeishittheESCkeyonyourkeyboard.

Sothenextthing is, ifyoueditaconfigurationfile,especially likethephp.iniorany other main configuration file, keep in mind that these are really longdocuments.Ifyouaretryingtoeditasinglewordorvalue insidethatextremelylongfile,findingthatsinglewordorvaluealonecanbeatedioustask.

InordertofindsomethinginVim,therearetwosimplecommandsthatyoucanusetomakeyourlifeeasy.First,makesurethatyouareoutoftheInsertmode.OnceyouareoutofInsertmode,goaheadandtypethecommandbelow:

:/<name>

That is colon, followed by a forward slash, and then a space, and thenword ofvaluethatyouarelookingforwithinthefilethatyouaretryingtomodify.Again,remember that capitalization is crucial. Make sure you capitalize the namecorrectly,orelseLinuxwillnotabletofindwhatyouarelookingfor.Andifitdidfindsomething,itwillbetheincorrectone.

Whatthiscommanddoesisitlooksfromtheplacethatyouareat—yourcursor—all thewaydown through the rest of thedocument. Itwill look for thewordofvalue that you typed in your find command. Now, the important thing withsearchingisthatyoucanputinwildcardcharacters.

Letussayyouarelookingforthewordmaxwithintheconfigurationfile.Tolookformax,youneedtotypeinthefindcommandbelow:

:/max

Now,oneofthethingsmostLinuxexpertsdoiswhenevertheyarelookingforaspecific string in a file, they put a wildcard character, specifically an asterisksymbol,beforeandafter thenameof thestring.Thecommandwould then looklikethis:

:/*max*

Whattheabovecommandsaysisyouarelookingforanythingthathasmaxinthemiddle;whetheritisapartofastringorastandalonestring.Becausesometimesifthereisaspaceorthereisalittlecharacterbeforeorafterthestring,itmaynotshowupwhenyoudo the findcommand.This is thepurposeof thewildcard in

Page 73: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

caseslikethese.

Now take note that with the forward slash, Vimwill search from where yourcursorisatgoingdown.So,whatifyouhavereachedtheendofthefileandyoudidnotfindwhatyouarelookingfor?Atthispoint,yourcursorisattheendofthefile.Inordertomakeasearchupwardsfromwhereyourcursorisat,simplytypethecommandbelow:

:/?<name>

Thatiscolon,followedbyaforwardslash,followedbyaquestionmark,aspace,andthenthestringorvaluethatyouarelookingfor. Thisiswhatwillmakethesearchgoupwardsfromwhereyourcursorisat.

Now, what if there are multiple instances of the string or value that you arelookingforinavimfile?Well,whenyoudoasearch,Vimwillautomaticallyhaltonthefirstinstanceofthestringorvaluethatyouarelookingfor.Tomovetothenext instance, you just need to hit the letter “n” on the keyboard. This is theequivalent of “Find Next” in the Windows operating system. As you can see,navigating inVim is really easy. The above commands are all it takes to open,navigate,search,andeditfilesinVim.

Page 74: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

ExitingandSaving

Thenextthingweneedtotalkaboutishowopen,exit,andsavefileswithinVim.Sofar,whatwediscussedopeningVimfilesfromthecommandprompt.Sonow,letusdiscusshowtoopenupotherVimfileswhileinsideVimitself.

Ifyouneed toopena fileandyouarealready inVim—soyouneed to switch toanotherfile—justtypethecommandbelow:

:e<filename>

Thatisacolon,followedbyalowercaselettere,aspace,andthenthefilename.Again,makesureyouareoutofInsertmodewhenyoudothis.IfyouareinInsertmodeandyoutypeinthiscommand,whatwillhappenisVimwilljusttypeinthecommandwithinthefileitself.Itwillnotbeinterpretedasacommandtoopenupadifferentfile.

ThatisallyouhavetodotoopenupanotherVimfilefromwithinVim.Now,letussayyouopenupafileandyoulookaroundinthem.Butthen,youdecidethatyoudonotwanttochangeanythingandyouneedtogetoutofthatfile.Whatyoudointhisinstanceistypeinthecommandbelow:

:q

That isa colon,and then followedby the lowercase letterq.Thiscommandwillexit you out ofVim. Of course, you have to press ENTER after typing in eachcommandinordertoexecutethem.

Therewill be timeswhen you alsohave to force quit out ofVim.Theremay betimes when Vim has become unresponsive or it does not want to accept thenormalquit command. Incases like these,youwant to forceVimto exit.Todothatyouhavetoputanexclamationmarkafterthelowercaseletterq.

:q!

WhetherVimgotstuckorhasbecomeunresponsivetoothercommands,puttinganexclamationmarkafterthelowercaseletterqwilldefinitelygetyououtoftheVimapplication.Onlyusethiscommandifnothingelseworks.KeepinmindthatifyouarequittingVimnormallyusingthe:qor:q!command,nochangeswillbesaved in the file that you are trying to edit—unless you saved the changes firstbeforetryingtoexecutethequitcommand.

Now, let us sayVim locked up for some reason and you have already enterednumerouschangesinthefile.Ofcourse,inorderforyounottogothroughallthechangesagain,youwanttosavethefilebeforequitting.Inthisinstance,whatyoudoistypeinthecommandbelow:

:wq

That is a colon, followed by the lowercase letterw, and then followed by thelowercaseletterq.The lowercase letterwstandsfor“write”,whilethe lowercaseletterqstandsforquit.Sothiswillsavewhateverchangesyoumadetothefilefirst

Page 75: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

beforequittingVim.

Thenextthingis,letussayyoumadesomechangestothefilebutyoudonotwantit to be saved to the original file. So you are basically trying to do a “save as”commandhere.Todothat,justtypeinthecommandbelow:

:w<newfilename>

Thatiscolon,followedbyalowercaseletterw,aspace,andthenthenameofthenewfilethatyouwanttocreateandsaveinto.Thiscommandwillsavethefilethatyou edited to a new file. This is particularly useful when you do not want tooverwritetheoriginalfileandyouwanttopreserveitforsomereason.

Page 76: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux
Page 77: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Chapter7:AdvancedLinuxNavigation

In this chapter,wewill talk about advancedLinux navigation. In chapter 5,wehavealreadytalkedabouthowtochangedirectoriesinLinux.Now,wewilldiscusshowtofindfoldersinLinux,howyoumakeandremovedirectories,howyoucopyfiles,andthenfinallyhowyoumountdrivesinLinux.

Page 78: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

ChangingDirectoriesandFindingFiles

In the last chapter,we talkedabouthowyouedit configuration filesusingVim,whichisprettyessentialinLinux.Now,asyousitthereandlookatthefilesystem,youprobablyhavenoideawherethoseconfigurationfilesareinthefirstplace.Ifyou wanted to edit the php.ini file for example, the question that you may beaskingsinceyouareabeginnerinLinuxis,whereisthephp.inifilelocated?

So,tofindanyparticularfilethatyouwanttoedit,youmustfirstlearnhowtogetto the folder or directorywhere that particular file is located. Again, to changedirectories, all you need to do is make use of the cd command just like inWindows.Thesyntaxtochangedirectoryis:

$cd<nameoffolder>

Now, there is more to this command thanmeets the eye. Remember, Linux isexceptionally literalwhen it comes to the interpretation of commands syntaxes.Again,letusmakeuseofthediagrambelow:

Ifforexampleyouareinthevardirectory/folderandyouwanttogototheabcfolder,allyouneedtodoistype:

$cdabc

Now,ifforexampleyouareinthevarfolderandyouwanttogototheetcfolder,justtypingin$cdetcfromwithinvarwillnotwork.BecausethenLinuxwillthinkthatyouwanttogototheetcfolderthatiswithinthevarfolder,whichdoesnotexist.

Whatyoumustdoistypethecommandbelow:

$cd/etc

Takenoteoftheforwardslashbeforethenameofthedirectorythatyouwanttogoto.ThisforwardslashwilltellLinuxtofirstgototherootdirectoryandthenfindtheetcfolderordirectory.Now,Linuxwillnowbeabletosuccessfullybringyoutotheetcfoldersinceitisabletolocateitintherootdirectory.

Page 79: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Now, consider the example diagram above. Let us say that you are in the rootdirectoryandyouwanttogotothewwwdirectory.Ifyoutype:

$cdwww

Linux will not be able to bring you to thewww directory; it will say that thedirectorydoesnotexist.Why?Becauseremember,youare intherootdirectory.AsfarasLinuxisconcerned,thereareonlytwofileswithintherootdirectoryatthispoint:etcandvar.Tobeabletogotothewwwdirectoryfromroot,youmusttype:

$cd/var/www

Nowyoumightbeasking,won’tthesecondforwardslashintheabovecommandbringyoubacktoroot?No,itwillnot.Linuxonlyinterpretsthefirstinstanceofthe forward slash as the root directory. The second forward slash will beinterpretedas an instruction to look for thedirectory that succeeds it, from thedirectorythatprecedesit.

Hereisanotherexample:Letussayyouareinthewwwdirectoryandyouwanttogototheetcdirectory.Ifyoutypein:

$cdetc

This commandwill notwork.Keep inmind that you are currently in thewwwdirectory.AsfarasLinuxisconcerned,thereisnoetcdirectory insidethewwwdirectory.Tomakethiswork,youhavetotypethecommandbelow:

$cd/etc

Soagain,thefirstinstanceoftheforwardslashwillbeinterpretedbyLinuxasaninstructiontogototherootdirectoryfirst.Onceitisintherootdirectory,itwillthen find theetcdirectory.Of course, this commandwill successfully bring youinsidetheetcdirectorysinceitexistswithintherootfolder.

Page 80: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Listing/DisplayingFiles

Now,onceyouareinadirectory,itisalwaysimportanttofindoutwhatelseisinthatdirectory.TolistfilesinLinux,yousimplyusethecommandls.

$ls

And then, depending on what you want to do, you can apply one of twoarguments.Ifyoudo:

$ls-l

Whatwillhappenisthatallthefilesandfolderswillgetlisted.Inadditiontothat,itwillalsoshowyouthepermissionsforthosefilesandfolders,thedatetheyweremodified,thegroupownershipofthefilesandfolders,andtheindividualowner.

Alotoftimesthatcanturnintoareallybigfile.So,whatyoucanalsodoistype:

$ls-m

Thistime,insteadofLinuxgivingyouareallylonglist,itjusttypeseverythingintoanice block so you can see everybit of information about the files and folders.ThatisallyouneedtodotolistfilesandfoldersinLinux.

Now,let’ssayyouwanttoeditacriticalconfigurationfile,butyouhaveabsolutelynoideawherethatfileis.Thankfully,Linuxdoeshaveasearchoption.Inordertosearchforfilesandfolders,allyoudoistype:

$sudofind-iname<file/foldername>

That issudo,a space, followedby theword find,another space, the argument -iname,anotherspace,andthenfinallythenameofthefileorfolderthatyouarelookingfor.Nowyoumightbeaskin,whatdoesthat -inameargumentdo?Well,whatitdoesisitmakesthesearchcaseinsensitive.

Remember,justlikewhatwehavebeenmentioningsincechapter1,capitalizationmattersinLinux.SinceyouarenewtoLinux,youmaynotknowwhichfileshaveuppercaselettersandwhichfileshavelowercaseletters.Ifyouputinthe-inameargument in your search parameter, itwill locate the file or folder that you arelookingforregardlessoftheircapitalization.

Page 81: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Ifyouare lookingfora foldernamedhome forexample,andyouuse thesearchcommandwiththe -inameargument,itwillcomebackwithallthefolderthathashomeas the folder name.Whether that folder is name asHome, homE, hOme,HOme,hoMe,orHOME,itwillcomeupinthesearchresult.

Whereasifyoumessupthecapitalizationofthenameofthefileorfolderthatyouare lookingfor,andyoudidnotusethe-inameargument, thesearchmaycomebackwithnoresultsbecausenofileorfoldermatchthecapitalization.

Also,donot forgetabout thesudocommandwhenexecuting find commands inLinux.Ifyoudonotputinsudoatthebeginning,thefindcommandwillfailinthemostobnoxiouswayinthatitwillnottellyouthatitfailed.Itwillsimplynotgiveyou any results. So youwill think that the file does not exist on the computer,wheninactualityitdoesexistbutyoujustdidnotusesudo.

Withwhatever file or folder that you are looking for, you can alsousewildcardcharacterstogetherwiththeirnamewhendoingasearch.Inchapter6,webrieflytalked aboutmaking use of the asterisk wildcard when searching for strings inVim.When finding files and folders within the Linux file system, you can alsomakeuseoftheasteriskwildcard.

Ifyouputanasteriskbeforeafileorfoldername,thatmeansthatyouarelookingfor“anythingbefore”thatparticularfileorfoldername.Letussayyouaretryingtolocateaconfigurationfile inLinux.InLinux,allconfigurationfileshave .confsuffix. If you are looking for a configuration file but you forgot what the exactnameis,youmaywanttopullupallthefilesthathave.confastheirsuffix.Inthiscase,whatyoudoistypethecommandbelow:

$sudofind-iname*.conf

What this command will do is look for a file or folder name that begins withanythingandendswith.conf.Now,whatifyouknowthefilenameofthefilethatyouarelookingfor,butyoudonotknowthesuffix.Inthiscase,youneedtotypethecommandbelow:

$sudofind-inamephp*

Whatthiscommandwilldoislookforafileorfoldernamethatbeginswithphpandendswithanything.

Page 82: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Making,Deleting,Moving,Copying,Renaming

Nowweneedtotalkaboutmaking,deleting,moving,copying,andrenamingfilesandfoldersinLinux.Thefirstthingthatwearegoingtodoistalkaboutcreatingafolder.Itisprettystraightforward.Allyoudoistype:

$sudomkdir<nameofdirectory/folder>

Thatissudo,followedbyaspace,andthenthemkdirparameter,anotherspace,andthenthenameof the folderordirectory thatyouwant tomake.Asyoucanprobablyalreadyguess,mkdirstandsfor“makedirectory.”

Keepinmindthatifyoudonotputthefullpathofthedirectory,thiscommandwill simply create that directory or folder inside the directory that you arecurrentlyin.

Forexample,letussayyouareinthevardirectoryandyouwanttocreateaNotesfolderinsidetheetcdirectory.Ifyoutype:

$sudomkdirNotes

ThiscommandwilljustcreatetheNotesfolderinthevardirectory.TocreatetheNotes folder intheetcdirectory fromwithinvar, youmust type in the fullpathjustliketheonebelow:

$sudomkdir/etc/Notes

Thisway,Linuxwillgototherootdirectoryfirst,andthenintotheetcdirectory,andwithintheetcdirectorycreateaNotesfolder.Typinginthefullfilepathwillensurethatnomatterwhereyouareinthefilesystem,youwouldbeabletocreatethe folder in the right location. That is all you need to do to create a folder ordirectoryinLinux.

Deletingfilesorfoldersisjustassimple.Whatyoudoistypethecommandbelow:

$sudorm<fileorfoldername>

Thatissudo,aspace, followedbythe lettersrm,anotherspace,andthenfinallythenameof the file or folder that youwant todelete.As youmayhave alreadyguessed,rmstands for remove.Letus say for exampleyouwant todeletea filenamedNotes.Allyouneedtodoistype:

Page 83: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

$sudormNotes

Deletingfoldersisalittlebitdifferent,however.Youactuallystillfollowthesamesyntaxaswhenyouaredeletingafile.Theonlydifferenceisthatyouhavetoaddthe-Rargumentattheendofthecommandwhendeletingfolders.Theargument-Rstandsforrecursive.Byusingtherecursiveargument,youarebasicallytellingLinuxtodothesametasktothecontentsofthefolder.

Letussayyouwanttodeletethewwwfolderthathasthreefilesinit.Todothis,youjusttype:

$sudormwww-R

Thiscommandwillnotonlydeletethefolderitself,butalsothethreefilesthatareinside it. If you do not put a recursive argument at the end of a delete foldercommand,Linuxwillnotbeabletoexecuteitsuccessfully,sinceyoucannotdeleteafolderwithoutdeletingthecontentsaswell.Theonlytimeyouwouldbeabletodeletea folder successfullywithout the recursiveargument iswhen the folder isemptytobeginwith.

In Linux, there is no command to rename files and folders per se. Instead ofrename,wehavethemovecommandinLinux.Letussayforexampleyouhaveafilenamedfile1,andyouwanttochangethenametofile2.Todothatyouhavetotypethecommandsyntaxbelow:

$sudomv<nameofoldfile><nameofnewfile>

Thatissudo,aspace,followedbythelettersmv,anotherspace, thenameoftheoriginalfile,anotherspaceagain,andthenfollowedbythenameofthenewfile.Soagain,goingbacktoourexample,ifyouwanttochangethenamefile1tofile2,youhavetotype:

$sudomvfile1file2

Thiscommandwillchangethenameoffile1tofile2.Itisstilltechnicallyrenaminga file.But inLinux,weuse the termmove.Now,howaboutmovinga file fromfolder to folder? Well, the same syntax still applies. However, instead of justtypinginthenameofthefilesandfolders,youmustindicatethefullpath.

Let’ssayyouwanttomoveafilenamedfile1insidethevarfoldertotheetcfolderintherootdirectory.Todothis,youmusttypethecommandbelow:

$sudomv/etc/var/file1/etc/file1

Thatissudo,aspace,followedbythelettersmvformove,anotherspace,theexactfilepathofthesourcefile,anotherspace,andthenlastlyfollowedbytheexactfilepathtothedestination.Itisassimpleasthat.

Copying is another important task inLinux.A lot of times, especially if youaredealingwithaconfigurationfile,itisessentialthatyoumakeabackupfilebeforeyou start messing around with the original file. Otherwise, if you mess up theoriginal file, youmay end up damaging the program that that file is associated

Page 84: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

with.

TocopyfilesinLinux,allyouhavetodoistype:

$sudocp<nameofthefile><nameofthecopiedfile>

Thatissudo,aspace,followedbytheletterscpforcopy,anotherspace,thenameofthefileyouwanttomakeacopyof,anotherspace,andthenfinallythenameoftheduplicatefile.So,letussayyouwanttomakeacopyofafilenamedfile10.Allyouneedtodoistype:

$sudocpfile10file10.bak

Here,file10.bakisthenameoftheduplicatefileoffile10.Asyoucansee,itiseasytomakecopiesoffilesinLinux.

Page 85: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

MountingDrives

The last big thing that you have to understand in order to navigate Linux ismountingdrives.This iswhereyouhaveanexternalharddrive,youplug it intothe computer, and you need tomount the drive in order for you to browse itscontents.Thatexternalharddrivecouldbeanormalharddrive,aflashdrive,oraCD-ROMdrive.FlashdrivesandCD-ROMdrivesareconsideredasharddrivesinLinux.

Basically, any drive that youwill connect to the computer is a drive thatwouldhave to be mounted. The first thing that you have to understand is how themountingprocessworksinLinux.Themountingprocessisasfollows:

Step1–Connecttheharddrive.

Step2–Createafolderforyourmountpoint.

Step3–Grabsomespecificinformationabouttheharddriveandthenpointthemountpointfoldertothatharddrive.

Thatisessentiallyhowyoumountthedrive.Themountpointfoldernowgetstiedtotheharddrive.Sincetheyaretiedtogether,youcannowbrowsethecontentsoftheharddrivethroughthemountpointfolder.

Sohowdo you actuallymake themount point folder in the commandprompt?Simple:justtypethecommandbelow:

$sudomkdir/mnt/<nameofmountpointfolder>

Takenoteofthe/mntdirectorythatwearecreatinghere.Knowthat/mntisthestandardmountingdirectoryinLinux.Thismountingdirectoryisuniversal.Youcan use a different mounting directory if you want. However, using /mnt isconsideredasabestpracticesincemostLinuxadministratorsandprogrammerswilluseitbydefault.

Now,let’ssayyouwanttomountaconnectedharddrivetoamountpointnameddrive1.Todothis,youjusttype:

$sudomkdir/mnt/drive1

Bytypingthecommandabove,youarecreatingthefolderthatyourharddrivewillbemountedto.Onceyoudothis,thenextthingthatyouhavetodoisfindouttheinformationabouttheharddrivethatyouaretryingtomount.Todothisyoujustrunthecommandbelow:

$sudofdisk-l

Theabovecommandwilllistallofthephysicalharddrivesthatareconnectedtoyour system. This list is going to show you the different hard drives that areconnected to your system, how much space they have, etc. In there, you arelooking forsomething that isgoing to look like/dev/sda1.ThesearecalleddisknamesinLinux.

Page 86: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Linuxdisknamesarealwaysarranged inanalphabeticalorder. If youhave twohard drives connected to your Linux system, for example, they will be named/dev/sdaand/dev/sdb, respectively. Thenumbers that succeed the disk namesrefertothepartitionswithinthatparticulardisk.

Ifyouhavetwopartitionsinyourfirstharddriveforexample,theywillshowupas/dev/sda1and/dev/sda2respectively.Ifyouhavethreepartitionsinyoursecondhard drive, they will show up as /dev/sdb1, /dev/sdb2, and /dev/sdb3respectively.

So,inordertomounttheharddrive,allwearegoingtodooncewefindthedisknameistypethefollowing:

$sudomount<diskname><mountpoint>

Ifwewere to apply this command syntax toour example, the command shouldlooklikethis:

$sudomount/dev/sda/mnt/drive1

Thisisallyoutodomountyourharddrive.Now,youcangoandchangedirectoryto/mnt/drive1bytyping:

$sudocd/mnt/drive1

Andonceyouareinyourmountpointdirectory,youcantype:

$ls-l

Theabovecommandwilllistallthecontentsofthatharddrive.YoucannowapplyalltheLinuxnavigationcommandsthatyouhavelearnedsofarinyourmounteddrive.ThatisbasicallyhowyoumountaharddriveinLinux.

Now, if youaredonewith thatharddriveandyouwant toun-mount it, all youneedtodoistype:

$sudoumount<diskname><mountpoint>

Asyoumayhavealreadyguessed,umountstands forun-mount.Once youhavesuccessfully un-mounted a hard drive, you can repeat the same process ofmountingadriveifyouwanttouseanewharddrive.

Page 87: Linux For Beginners: The Ultimate Guide To The Linux Operating System & Linux

Conclusion

There you have it. That is all there is to the basic installation, basic taskcommands,basicandadvancednavigation,andeditingfilesinLinux.Again,likewhatwehavementionedintheotherchapters,theonlyreasonthisisintimidatingandtheonlyreasonanybodyisnervousaboutthisisthattheydonotknowwhatcommandstorun.Onceyouunderstandthecommandsthatyouneedtorun,itallbecomeseasy.

Onceagain,thesecommands,thoughtheymightseemcomplicatedtoyouatthispoint,arejustprettybasic.Ifwhatwehaveshowedyouinthisbookdoesnothelpyoudoeverything thatyouneed todo, thenbyallmeansuse themanpages inordertolearnthemorecomplicatedcommandsthatyouneed.

WithLinux, thesky’s the limiton the things thatyoucandowith theoperatingsystem.Wearebasicallyjustbringingthisdowntoalevelthatbeginnerslikeyoucanlearnandunderstandquickly.

Wewouldliketothankyouforbuyingthisbook.WehopethatyoulearnedalotabouttheLinuxoperatingsystemanditsbasiccommands.Feelfreetomakethisbook your beginner’s quick guide as you explore the intricacies of this fantasticoperatingsystem.

Atthispoint,wewouldliketoencourageyoutotinkerandplayaroundwiththeLinux operating system and its numerous distributions. Keep in mind thatdifferent distributions have different features. Some of the commands that areindicated in this book may already be an automatic process in anotherdistribution. For example, desktop distributions of Linux such as Linux Mint,ArchLinux,PeppermintLinux,KaliLinux,PuppyLinux,etc.allperformtheharddrive mounting task automatically. Not only that, they also allow you to applyvariousthemestotheGUI,makeuseofwidgets,etc.togivetheoperatingsystemamorecustomizedfeelandlook.

Linuxisatrulywonderfuloperatingsystem,andithasnowreachedalevelwhereitcancompetewiththemorepopularoperatingsystemsoutthere.Wehopethatthisbookbecomesyourfirststeppingstonetowhatmaybethefutureofcomputeroperatingsystems—Linux.