Transcription of Introduction to the Linux Command Shell For Beginners
1 An Introduction to theLinux Command ShellFor BeginnersPresented by:Victor GedrisIn Co-Operation With:The Ottawa Canada Linux Users GroupandExitCertifiedCopyright and RedistributionThismanualwaswrittenwithth eintentionofbeinga ,I decidedtoreleaseit undera freedocumentationlicense,withthehopestha tpeoplebenefitfromit byupdatingit Thefileformatisnon-proprietary, 'website[ ].Formore information on Open Office, please visit 2003 Victor grantedtocopy,distributeand/ormodifythis documentunderthetermsoftheGNUFreeDocumen tationLicense, ;withnoInvariantSections,withnoFront-Cov erTexts, 'swebsite: Version: , toprovidethereaderwitha is designedtoaccompanyaninstructor-ledtutor ialonthissubject, ,practical examples, and references to DOS commands are made, where is a Command Shell ?
2 A program that interprets commands Allowsa usertoexecutecommandsbytypingthemmanuall yat a terminal,orautomaticallyin programs called Shell scripts. A is a is BASH? BASH = Bourne Again Shell Bashisa shellwrittenasa freereplacementtothestandardBourneShell( /bin/sh)originally written by Steve Bourne for UNIX systems. It hasallofthefeaturesoftheoriginalBourneSh ell,plusadditionsthatmakeit easiertoprogram with and use from the Command line. Since it is Free Software, it has been adopted as the default Shell on most Linux is BASH different from the DOS Command prompt? Case Sensitivity:InLinux/UNIX,commandsandfile namesarecasesensitive,meaningthat typing EXIT instead of the proper exit is a mistake.
3 \ vs. / :InDOS,theforward-slash / isthecommandargumentdelimiter,whiletheba ckslash \ isa ,the / is thedirectoryseparator,andthe \ is these special characters in a minute! Filenames:TheDOSworldusesthe eightdotthree filenameconvention,meaningthatallfilesfo lloweda formatthatallowedupto8 charactersinthefilename,followedbya period( dot ),followedbyanoptionextension,up to 3 characters long ( ). In UNIX/ Linux , there isnosuchthingasa anypartofthefilename, and extensions may be interpreted differently by allprograms, or not at CharactersBeforewecontinuetolearnaboutLi nuxshellcommands,it :a)cannotbeusedincertainsituations,b)may beusedtoperformspecialoperations, or, c) must be escaped if you want to use them in a normal \Escape character.
4 If you want to reference a special character, you must escape itwith a backslash :touch /tmp/filename\* /Directory separator, used to separate a string of directory :/usr/ directory. Can also hide files when it is the first character in a directory~User's home directory*Represents 0 or more characters in a filename, or by itself, all files in a :pic*2002 can represent the files pic2002, picJanuary2002, picFeb292002, a single character in a :hello?.txt can represent , , but not [ ]Can be used to represent a range of values, [0-9], [A-Z], :hello[0-2].txt represents the names , , and | Pipe.
5 Redirect the output of one Command into another :ls | more >Redirect output of a Command into a new file. If the file already exists, over-write :ls > >>Redirect the output of a Command onto the end of an existing :echo Mary 555-1234 >> <Redirect a file as input to a :more < ; Command separator. Allows you to execute multiple commands on a single :cd /var/log ; less messages&& Command separator as above, but only runs the second Command if the first onefinished without :cd /var/logs && less messages &Execute a Command in the background, and immediately get your Shell :find / -name core > / & CommandsThe Command PATH: Most common commands are located in your Shell 's PATH , meaning that you can justtype the name of the program to execute : Typing ls will execute the ls Command .
6 Your Shell 's PATH variable includes the most common program locations, such as/bin, /usr/bin, /usr/X11R6/bin, and others. To execute commands that are not in your current PATH, you have to give the completelocation of the :/home/ (Execute a program in the current directory)~/bin/program (Execute program from a personal bin directory) Command Syntax Commands can be run by themselves, or you can pass in additional arguments to make them dodifferent things. Typical Command syntax can look something like this: Command [-argument] [-argument] [--argument] [file] Examples:lsList files in current directoryls -lLists files in long formatls -l --colorAs above, with colourized outputcat filenameShow contents of a filecat -n filenameShow contents of a file, with line HelpWhenyou'restuckandneedhelpwitha Linuxcommand,helpisusuallyonlya fewkeystrokesaway!
7 HelponmostLinuxcommandsistypicallybuiltr ightintothecommandsthemselves,available through online help programs ( man pages and info pages ), and of course a Command 's Built-In HelpManycommandshavesimple help flags usually look like -h or --help .Example:grep Manuals: Man Pages Thebestsourceofinformationformostcommand scanbefoundintheonlinemanualpages,known as man pages for short. To read a Command 's man page, type man Command .Examples:man lsGet help on the ls manA manual about how to use the manual!Tosearchfora particularwordwithina manpage,type /word .Toquitfroma manpage,justtype the Q , ,if youwanttoknowhowtochangea file'spermissions,youcansearchthemanpage descriptions for the word permission like this:man -k permissionIf you look at the output of this Command , you will find a line that looks something like:chmod (1) - change file access permissionsNowyouknowthat chmod is manchmod willshow you the chmod Command 's manual page!
8 PagesSomeprograms,particularlythoserelea sedbytheFreeSoftwareFoundation, ,butinsteadofbeingdisplayedononelongscro llingscreen, info Command ,oronsomeLinux distributions, pinfo (a nicer info browser).For example:info dfLoads the df info the Linux FilesystemTheLinuxfilesystemis a the / directory,otherwiseknownasthe root (nottobeconfusedwiththerootuser).UnlikeD OSorWindowsfilesystemsthathavemultiple roots ,oneforeachdiskdrive, many of the most common Linux Linux Directory ,files,drives, (butincorrectly)referredtoasthe slash or / / isjusta directoryseparator,notadirectory (programs)arestoredhere(bash,ls,mount,ta r, etc.)
9 /bootStatic files of the boot ,hardwaredevicesareacceessdjustlikeother files,andthey are kept under this system configuration of users' personal home directories ( /home/susan)./libEssential shared libraries and kernel information pseudo-filesystem. An interface to kernel data root (superuser) home system binaries (fdisk, fsck, init, etc)./tmpTemporary files. All users have permission to place temporary files ,read-onlydata(programs,libraries,docume ntation, and much more)./usr/binMost user programs are kept here (cc, find, du, etc.)./usr/includeHeader files for compiling C for most binary Locally ,/usr/local/lib, etc.
10 Alsooftenusedforsoftwarepackagesinstalle dfromsource,orsoftwarenotofficiallyshipp edwith the system binaries (lpd, useradd, etc.)/usr/shareArchitecture-independentd ata(icons,backgrounds,documentation,term info,man pages, etc.)./usr/srcProgram source code. The Linux Kernel, source RPMs, X Window data: mail and printer spools, log files, lock files, for Navigating the Linux FilesystemsThefirstthingyouusuallywantto dowhenlearningabouttheLinuxfilesystemis takesometimetolookaroundandseewhat'sther e!Thesenextfewcommandswill:a)Tellyouwher eyouare,b)takeyousomewhereelse,andc)show youwhat' ,cd, andlscommands,andcomparesthemtocertainDO Scommandsthatyou might already be familiar CommandDOS CommandDescriptionpwdcd PrintWorkingDirectory.