Example: confidence

Introduction to the Linux Command Shell For Beginners

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 ? 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.

An Introduction to the Linux Command Shell For Beginners Presented by: Victor Gedris In Co-Operation With: The Ottawa Canada Linux Users Group and ExitCertified

Tags:

  Linux, Introduction, Beginner, Command, Shell, Introduction to the linux command shell for beginners

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

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 ? 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.

2 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. \ 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.

3 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 . 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 .

4 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!HelponmostLinuxcommand sistypicallybuiltrightintothecommandsthe mselves,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.

5 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! 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).

6 UnlikeDOSorWindowsfilesystemsthathavemul tiple 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.)/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.).Alsooftenusedforsoftwarepackagesin stalledfromsource,orsoftwarenotofficiall yshippedwith the system binaries (lpd, useradd, etc.

7 /usr/shareArchitecture-independentdata(i cons,backgrounds,documentation,terminfo, 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 .Showsthecurrentlocation in the directory , chdir ChangeDirectory .Whentypedallbyitself,itreturns you to your home directorycd : cd /usr/src/linuxcd ~ ~ canbeusedasashortcuttoyour home ,orotherdirectories relative to your .. ,if youarein/home/vicandyoutype cd .. , youwillendup in to your previous location!lsdir /wListallfilesinthecurrentdirectory, directorydir directoryList the files in the specified : ls /var/logls -ldirListfilesin long format, ,suchas ownership, permissions, date, and -adir /aListallfiles,including hidden.

8 , file in your home -lddirectoryA long listof directory ,butinsteadofshowingthedirectorycontents ,showthedirectory' ,comparetheoutputofthe following two commands:ls -l /usr/binls -ld /usr/binls /usr/bin/d*dir d*.*Listallfileswhosenamesbeginwiththele tter d in the /usr/bin and Re-DirectionBeforewemoveontolearningeven morecommands,let' ,thereforebyextensiontheLinuxphilosophy, is tohavemanysmallprogramsandutilitiesthatd oa is theresponsibilityoftheprogrammer or user to combine these utilities to make more useful Command Commands TogetherThepipecharacter, | , is piped intothenextprogram,andif thereis a secondpipe,theoutputis senttothethird program, etc. For example:ls -la /usr/bin | lessInthisexample,werunthecommand ls -la/usr/bin , whichgivesusa longlistingofallofthefilesin/usr/bin. Becausetheoutputofthiscommandis typicallyverylong,wepipetheoutput to a program called less , which displays the output for us one screen at a Program Output to FilesTherearetimeswhenit is usefultosavetheoutputofa commandtoa file, ,if wewanttocreatea filethatlistsalloftheMP3filesina directory,we can do something like this, using the > redirection character:ls -l /home/vic/MP3/*.

9 Mp3 > similarcommandcanbewrittensothatinsteado fcreatinga ,we can append to the end of the original file:ls -l /home/vic/extraMP3s/*.mp3 >> Linux can't possibly cover the details of all of these commands in this document, so don't forget that youcancheckthe manpages on all Linux or UNIX With Files and DirectoriesThese commands can be used to: find out information about files, display files, and manipulatethem in other ways (copy, move, delete).LinuxCommandDOSC ommandDescriptionfileFind out what kind of file it , file/bin/ls tellsusthatit isa Linuxexecutable in the previous the first few lines of a text : head /etc/servicestailDisplay the last few lines of a text : tail /etc/servicestail -fDisplaythelastfewlinesofa textfile,andthenoutputappendeddataasthef ilegrows(veryusefulforfollowinglog files!).Example: tail -f /var/log/messagescpcopyCopies a file from one location to : cp /tmp(copies the file to the /tmp directory)mvrename,ren, moveMoves a file to a new location, or renames example: mv /tmp(copythefileto/tmp,anddeleteitfromth eoriginallocation)rmdelDelete a file.

10 Example: rm / Directory. Example: mkdir /tmp/myfiles/rmdirrd, rmdirRemove Directory. Example: rmdir /tmp/ ThingsThefollowingcommandsareusedtofindf iles. ls is goodforfindingfilesif youalreadyknowapproximately where they are, but sometimes you need more powerful tools such as ,ifyouwanttoknowexactlywherethe grep commandislocatedonthefilesystem,youcanty pe whichgrep .Theoutputshouldbesomethinglike: /bin/grepwhereisLocatestheprogram,source code,andmanualpagefora Command (ifallinformationisavailable).For example,tofindoutwhere ls anditsmanpage are, type: whereis ls The output will look something like:ls: /bin/ls /usr/share/man/man1 ,youcanfindallfilesanddirectoriesthatcon tainthename mozilla bytyping:locate mozillafindAverypowerfulcommand, canbeusedtosearchforfilesmatchingcertain patterns,aswellasmanyothertypesofsearche s. A simple example is:find . -name \*mp3 Thisexamplestartssearchinginthecurrentdi rectory . andallsub-directories, looking for files with mp3 at the end of their CommandsThe following commands are used to find out some information about the user or the CommandExplanationpsLists currently running process (programs).


Related search queries