linux module 1

Upload: parimalin

Post on 08-Apr-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 Linux Module 1

    1/305

    11

    LinuxLinuxFundamental AdministrationFundamental Administration

    in a Linux environmentin a Linux environment

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    2/305

    22

    Module 1Module 1Role of a sys adminRole of a sys admin

    System DocumentationSystem DocumentationHelpHelp

    File system layoutFile system layout4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    3/305

    33

    File SystemFile System

    DirectorysDirectorys Locations for files andLocations for files anddirectories.directories.

    SubdirectorysSubdirectorys-- A directory that isA directory that isbelow a directory.below a directory.

    DocumentsDocuments ASCII, ASCII,

    ApplicationsApplications databases, worddatabases, wordprocessors, spreadsheetsprocessors, spreadsheets

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    4/305

    44

    File System: UnixFile System: Unix

    Unix File Str ct re

    bin sbin lib

    bin sbin etc

    local

    sr dev etc

    ser ser2 ser3

    home lib var boot bin

    floppy cdrom

    mnt sbin root proc

    Root (/)

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    5/305

    55

    Filesystem Hie y St ndardFilesystem Hierarchy Standard

    1993 Linux community formed a1993 Linux community formed aproject too standardize theproject too standardize thefilesystem layout for all generalfilesystem layout for all general

    purpose Linux distributionspurpose Linux distributions Known as the Linux FilesystemKnown as the Linux Filesystem

    Standard but later renamed to theStandard but later renamed to the

    Filesystem Hierarchy StandardFilesystem Hierarchy Standard FHS defines two categories of dataFHS defines two categories of data

    use: Data Sharing and Datause: Data Sharing and DataModificationModification

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    6/305

    66

    Data SharingData Sharing

    ShareableShareable -- Can be used by multiple hostCan be used by multiple hostsystems on a network. These files containsystems on a network. These files containgeneralgeneral--purpose information such as userpurpose information such as user

    datafiles, executables and commondatafiles, executables and commonconfiguration filesconfiguration files

    NonNon--shareableshareable -- Data is not shareableData is not shareablewhen it is linked to a specific host. For, awhen it is linked to a specific host. For, aunique configuration file such as theunique configuration file such as thepasswd file and system logspasswd file and system logs

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    7/305

    77

    DataModi icationDataModi ication

    VariableVariable -- Data is considered variableData is considered variablewhen it changes by natural andwhen it changes by natural and

    frequentfrequentprocesses(/var/log/messages)processes(/var/log/messages)

    StaticStatic -- This data is left alone for theThis data is left alone for themost part remaining the same frommost part remaining the same from

    day to day or even year to year.day to day or even year to year.

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    8/305

    88

    FHS Data Ty esFHS Data Ty es

    Sharable Non-SharableStatic /usr

    /usr/local

    /etc

    /bootVariable /var/mail

    /home/var/log/proc

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    9/305

    99

    The root FilesystemThe root Filesystem

    Must contain utilities and filesMust contain utilities and filessufficient to boot the operatingsufficient to boot the operatingsystemsystem

    Should contain utilities needed byShould contain utilities needed bythe system administrator to repair orthe system administrator to repair orrestore a damaged systemrestore a damaged system

    Should be relatively smallShould be relatively small Software should not create files orSoftware should not create files or

    directories in the root filesystemdirectories in the root filesystem

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    10/305

    1010

    The usrFilesystemThe usrFilesystem

    Contain system utilities andContain system utilities andprograms that do not appear in theprograms that do not appear in the

    root partitionroot partition User programs will often appear inUser programs will often appear in

    /usr/bin/usr/bin

    Some system administrationSome system administrationprograms may appear in /usrprograms may appear in /usrfilesystem as wellfilesystem as well

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    11/305

    1111

    The arFilesystemThe arFilesystem

    Contains data such as printer spoolsContains data such as printer spoolsand log files that vary over timeand log files that vary over time

    Is always changing and growing andIs always changing and growing andoften has its own partitionoften has its own partition

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    12/305

    1212

    root Filesystem O erviewroot Filesystem Overview

    File file system available upon booting isFile file system available upon booting isthe root filesystem (/)the root filesystem (/)

    In some cases, the root filesystemIn some cases, the root filesystem

    contains everything on the systemcontains everything on the system

    Best practice is to define multipleBest practice is to define multiplepartitions containing one or more of thepartitions containing one or more of the

    directories found below root (/)directories found below root (/) When Linux boots, the partitions are mountedWhen Linux boots, the partitions are mountedand together create a single filesystemand together create a single filesystem

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    13/305

    1313

    //

    Top of the filesystem hierarchyTop of the filesystem hierarchy

    Some directories must always be aSome directories must always be a

    part of the root filesystem to allowpart of the root filesystem to allowLinux to bootLinux to boot

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    14/305

    1414

    /bin and/sbin/bin and/sbin

    Contains required system binaryContains required system binaryprogramsprograms

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    15/305

    1515

    /dev/dev

    Contains device filesContains device files

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    16/305

    1616

    /etc/etc

    Contains boot configurationContains boot configurationinformationinformation

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    17/305

    1717

    /lib/lib

    Contains program librariesContains program libraries

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    18/305

    1818

    /boot/boot

    Holds static files used by the bootHolds static files used by the bootloaderloader

    Can be placed on a separate partitionCan be placed on a separate partition For use with older versions of lilo,For use with older versions of lilo,

    usually on a partition below theusually on a partition below the10241024thth cylinder of a hard drive.cylinder of a hard drive.

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    19/305

    1919

    /home/home

    Holds user filesHolds user files

    Often placed on a separate partitionOften placed on a separate partition

    Normally becomes the largestNormally becomes the largestpartition on the system and can evenpartition on the system and can evenbe placed on a separate physical diskbe placed on a separate physical disk

    Can be shared over the network toCan be shared over the network tocentralize users files.centralize users files.

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    20/305

    2020

    /tm/tm

    Programs use this for temporary filesPrograms use this for temporary files

    Best practice to place it on aBest practice to place it on a

    separate partition to preventseparate partition to preventtemporary files from filling uptemporary files from filling upvaluable disk space on the rootvaluable disk space on the rootpartitionpartition

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    21/305

    2121

    /var/var

    Log files are stored hereLog files are stored here

    Email is stored hereEmail is stored here

    Print queues are stored herePrint queues are stored here RedHat stores the Apache web docsRedHat stores the Apache web docs

    herehere

    NIS files stored hereNIS files stored here

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    22/305

    2222

    /usr/usr

    Holds a hierarchy of directoriesHolds a hierarchy of directoriescontaining user commands, sourcecontaining user commands, sourcecode, and documentationcode, and documentation

    Often quite large in sizeOften quite large in size

    Should have its own partitionShould have its own partition

    /usr/sbin holds sys admin/usr/sbin holds sys adminexecutablesexecutables

    /usr/bin holds user executables/usr/bin holds user executables

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    23/305

    2323

    Binary File LocationsBinary File Locations

    User Commands System AdministrationCommands

    Vendor-supplied , essential /bin /sbinVendor-suppliednonessential

    /usr/bin /usr/sbin

    Locally supplied,nonessential

    /usr/local/bin /usr/local/sbin

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    24/305

    2424

    File Location CommandsFile Location Commands

    whichwhich

    findfind

    locatelocate updatedbupdatedb

    whatiswhatis

    aproposapropos

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    25/305

    2525

    which Overviewwhich Overview

    Shows the location of a commandShows the location of a commandand displays the full pathname. Usesand displays the full pathname. Usesthe PATH variable to search for thethe PATH variable to search for thecommand.command.

    Command Format: whichCommand Format: which commandcommand

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    26/305

    2626

    find Overviewfind Overview

    Locates files that match anLocates files that match anexpressionexpression

    Works recursivelyWorks recursively

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    27/305

    2727

    find Syntax and O tionsfind Syntax and O tions

    Syntax:Syntax:

    find paths expressionfind paths expression

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    28/305

    2828

    locate Overviewlocate Overview

    Locates files who names match oneLocates files who names match oneor more patternsor more patterns

    Searches an index of files previouslySearches an index of files previouslycreatedcreated

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    29/305

    2929

    locate Syntax and O tionslocate Syntax and O tions

    Syntax:Syntax:

    locatelocate patternspatterns

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    30/305

    3030

    u datedb Overviewu datedb Overview

    Refreshes or creates the slocateRefreshes or creates the slocatedatabase indatabase in/var/lib/slocate/slocate.db/var/lib/slocate/slocate.db

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    31/305

    3131

    u datedb Syntax and O tionsu datedb Syntax and O tions

    Syntax:Syntax:

    updatedb [options]updatedb [options]

    Options:Options: --ee directoriesdirectories (exclude a comma(exclude a comma--

    separated list of directories from theseparated list of directories from thedatabase)database)

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    32/305

    3232

    whatis Overviewwhatis Overview

    Search the whatis database for exactSearch the whatis database for exactmatches to keywords and display thematches to keywords and display theresultsresults

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    33/305

    3333

    whatis Syntax and O tionswhatis Syntax and O tions

    Syntax:Syntax:

    whatiswhatis keywordskeywords

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    34/305

    3434

    apropos Overviewapropos Overview

    Search the whatis database forSearch the whatis database forpartial word matches to keywordspartial word matches to keywordsand display the resultsand display the results

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    35/305

  • 8/7/2019 Linux Module 1

    36/305

    3636

    Objective 1: Use andManageObjective 1: Use andManage

    Local System DocumentationLocal System Documentation Text and PagingText and Paging

    The man FacilityThe man Facility

    Information in /usr/docInformation in /usr/doc Info PagesInfo Pages

    OdditiesOddities

    Using the locate CommandUsing the locate Command

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    37/305

    3737

    Documentation OverviewDocumentation Overview

    System Administrators should beSystem Administrators should becomfortable with navigating throughcomfortable with navigating throughdocumentation in the event that hedocumentation in the event that heor she needs helpor she needs help

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    38/305

    3838

    Documentation ObjectivesDocumentation Objectives

    Use and Manage Local SystemUse and Manage Local SystemDocumentationDocumentation

    Find Linux Documentation on theFind Linux Documentation on theInternetInternet

    Write System DocumentationWrite System Documentation

    Provide User SupportProvide User Support

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    39/305

    3939

    Use andManage Local SystemUse andManage Local System

    DocumentationDocumentation Text and PagingText and Paging

    The man FacilityThe man Facility

    Information in /usr/docInformation in /usr/doc Info pagesInfo pages

    OdditiesOddities

    Using the locate CommandUsing the locate Command

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    40/305

    4040

    Text and PagingText and Paging

    Text and Paging OverviewText and Paging Overview

    Paging ProgramsPaging Programs

    lessless

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    41/305

    4141

    Text and Paging OverviewText and Paging Overview

    Each Linux system is configured withEach Linux system is configured withextensive documentation from:extensive documentation from: ProgrammersProgrammers

    AuthorsAuthors Other ContributorsOther Contributors

    Some documentation is quite formal whileSome documentation is quite formal whileother documentation is fairly informalother documentation is fairly informal

    Combined, this documentation offers aCombined, this documentation offers arobust body of information for users androbust body of information for users andsystem administratorssystem administrators

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    42/305

    4242

    Paging ProgramsPaging Programs

    more was a popular paging program on Unixmore was a popular paging program on Unixsystemssystems

    more would give users one more screen ofmore would give users one more screen ofinformationinformation

    more is known to be limited in its capabilities somore is known to be limited in its capabilities sothe less command was developedthe less command was developed

    less is similar to more but offers more capabilitiesless is similar to more but offers more capabilities

    less does not read all of its input before starting,less does not read all of its input before starting,

    which makes it faster for large inputwhich makes it faster for large input Can also use less commands to control theCan also use less commands to control the

    behavior of lessbehavior of less

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    43/305

    4343

    less Commandsless Commands

    Command DescriptionSpace Scroll forward one screenD Scroll forward one-half screen

    Return Scroll forward one lineB Scroll backward one screenU Scroll backward one-half screenY Scroll backward one lineg Go tot he beginning of the text G Go to the end of the text /pattern Search forward for a pattern which can be a regular expression

    ?pattern Search backward for pattern which can be a regular expressionH Display a help screen:n Display next file from command line:p Display previous file from command line

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    44/305

    4444

    The man FacilityThe man Facility

    The man Facility OverviewThe man Facility Overview

    man Commandman Command

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    45/305

    4545

    The man Facility OverviewThe man Facility Overview

    The man facility was created to putThe man facility was created to putdocumentation books on the systemdocumentation books on the system

    manpages are available for mostmanpages are available for mostcommands on the systemcommands on the system

    manpages are also available formanpages are also available forimportant files, shells, devices andimportant files, shells, devices andother items on your Linux systemother items on your Linux system

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    46/305

    4646

    The man CommandThe man Command

    Formats and displays man pages onFormats and displays man pages ona topic using a pagera topic using a pager

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    47/305

    4747

    man Syntax and Optionsman Syntax and Options

    Syntax:Syntax:

    man [options] [section] commandman [options] [section] command

    Options:Options: --a Instructs man to display alla Instructs man to display all

    manpages that match a name in amanpages that match a name in asequential fashionsequential fashion

    --d Display debugging informationd Display debugging information --w Print the locations of manpagesw Print the locations of manpages

    instead of displaying theminstead of displaying them

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    48/305

    4848

    Man SectionsMan Sections

    Sect. Description

    1 Executable programs or shell commands

    8 System Administration commands

    2 System calls

    3 Library calls

    4 Special files (usually found in /dev)

    5 File formats and conventions

    6 Games

    7 Macro packages and conventions

    9 Kernel routines

    N Tcl/Tk commands4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    49/305

    4949

    Information in /usr/docInformation in /usr/doc

    Some Linux users contribute theirSome Linux users contribute theirknowledge in the form of HOWTOknowledge in the form of HOWTOguides, FAQs, README files and evenguides, FAQs, README files and even

    exhaustive manualsexhaustive manuals Most of this documentation ends up inMost of this documentation ends up in

    /usr/doc/usr/doc

    Most is ASCII and can be displayedMost is ASCII and can be displayed

    using a pager programusing a pager program Contents of /usr/doc can be categorizedContents of /usr/doc can be categorized

    as follows:as follows: Package RelatedPackage Related

    FAQFAQ

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    50/305

    5050

    Package elatedPackage elated

    usually useful bits of informationusually useful bits of informationincludes with the program sourceincludes with the program source

    Contains documentation files that areContains documentation files that areoften specific to a version of aoften specific to a version of apackagepackage

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    51/305

    5151

    FAQFAQ

    Contains detailed information in aContains detailed information in aQ&A formatQ&A format

    Man important FAQs resides inMan important FAQs resides in

    usr/doc/FAQusr/doc/FAQ FAQs are often formatted in:FAQs are often formatted in:

    HTML (web browser friendly)HTML (web browser friendly)

    ps (printer friendly)ps (printer friendly) txt (plain text)txt (plain text)

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    52/305

    5252

    HOWTO documentsHOWTO documents

    Details information on how toDetails information on how toperform a certain taskperform a certain task

    Often serve as reference material forOften serve as reference material fornew administratorsnew administrators

    Often stored in /usr/doc/HOWTOOften stored in /usr/doc/HOWTO

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    53/305

    5353

    InfopagesInfopages

    Are part of a system called textinfoAre part of a system called textinfowhich uses a single source file towhich uses a single source file todisplay information on screen and ondisplay information on screen and onpaperpaper

    Is hypertext and creates a browserIs hypertext and creates a browserlike interface on a terminal orlike interface on a terminal or

    terminal windowterminal window

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    54/305

    5454

    info Commandsinfo Commands

    Command DescriptionTab Mov among y rt xt links

    Ent r ollow y rt xt linkst rn to t topof t menu? List all info commandsP andn Move toprevious andnextpages respectivelyu Moveupone level in t eTextinfo ierarc yq Terminate t e systemh Showaprimer for first timeusers

    /string Enter a string/patter Search forward for pattern,which canbea regular expression

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    55/305

    5555

    Using the locate CommandUsing the locate Command

    The locate command is handy as itThe locate command is handy as itcan return all instances of thecan return all instances of thecommand or command fragment youcommand or command fragment youenterenter

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    56/305

    5656

    Documentation on the netDocumentation on the net

    The Linux Documentation ProjectThe Linux Documentation Project

    Usenet NewsgroupsUsenet Newsgroups

    Mailing ListsMailing Lists Vendor Web Sites and OtherVendor Web Sites and Other

    ResourcesResources

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    57/305

    5757

    The Linux DocumentationThe Linux Documentation

    ProjectProject Most documentation, includingMost documentation, including

    HOWTOs, is part of an organizedHOWTOs, is part of an organizedapproach to system documentationapproach to system documentation

    Linux Documentation Project (LDP) isLinux Documentation Project (LDP) isa group of writers, proofreaders anda group of writers, proofreaders andeditors to create systemeditors to create systemdocumentation for Linuxdocumentation for Linux

    The url is http://www.linux.orgThe url is http://www.linux.org

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    58/305

    5858

    The Linux DocumentationThe Linux Documentation

    ProjectProject Documentation handled by LDP includesDocumentation handled by LDP includes

    online documents, manpages, HOWTOsonline documents, manpages, HOWTOsand a complete set of reference guidesand a complete set of reference guidesincluding:including: Installation and Getting Started GuideInstallation and Getting Started Guide

    The Linux Users GuideThe Linux Users Guide

    The Linux System Administrators GuideThe Linux System Administrators Guide

    The Linux Programmers GuideThe Linux Programmers Guide

    The Linux KernelThe Linux Kernel

    The Linux Kernel Hackers GuideThe Linux Kernel Hackers Guide

    The Linux Kernel Module Programming GuideThe Linux Kernel Module Programming Guide

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    59/305

    5959

    Usenet NewsgroupsUsenet Newsgroups

    Worldwide bulletin board serviceWorldwide bulletin board service

    Messages are posted to a users localMessages are posted to a users localnews server in a newsgroupnews server in a newsgroup

    Can usually access Usenet contentCan usually access Usenet contentthrough your ISPthrough your ISP

    Can read messages with a newsCan read messages with a newsreader applicationreader application

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    60/305

    6060

    Important Usenet NewsgroupsImportant Usenet Newsgroups

    comp.os.linuxcomp.os.linux

    comp.os.linux.advocacycomp.os.linux.advocacy

    comp.os.linux.developmentcomp.os.linux.development

    comp.os.linux.announcecomp.os.linux.announce

    comp.os.linux.hardwarecomp.os.linux.hardware

    comp.os.linux.answerscomp.os.linux.answers

    comp.os.linux.networkingcomp.os.linux.networking comp.os.linux.xcomp.os.linux.x

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    61/305

    6161

    Mailing ListsMailing Lists

    Mailing list is an email autoresponderMailing list is an email autoresponderwith a known list of mail recipientswith a known list of mail recipients

    Inbound mail to the list server will beInbound mail to the list server will bemirrored to each of the othermirrored to each of the otherrecipients on the listrecipients on the list

    Mailing list mail is more likely to beMailing list mail is more likely to be

    read by subscribers than usenetread by subscribers than usenetinformationinformation

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    62/305

    6262

    CertificationCertification

    http://www.brainbench.comhttp://www.brainbench.com

    http://www.linuxcertification.comhttp://www.linuxcertification.com

    http://www.lpi.orghttp://www.lpi.org http://www.redhat.com/rhcehttp://www.redhat.com/rhce

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    63/305

    6363

    CommerceCommerce

    http://www.elinux.comhttp://www.elinux.com

    http://www.linuxcentral.comhttp://www.linuxcentral.com

    http://www.linuxmall.comhttp://www.linuxmall.com

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    64/305

    6464

    DistributionsDistributions

    http://www.calderasystems.comhttp://www.calderasystems.com

    http://www.debian.orghttp://www.debian.org

    http://www.linuxhttp://www.linux--mandrake.commandrake.com http://www.redhat.comhttp://www.redhat.com

    http://www.slackware.comhttp://www.slackware.com

    http://www.suse.comhttp://www.suse.com http://www.turbolinux.comhttp://www.turbolinux.com

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    65/305

  • 8/7/2019 Linux Module 1

    66/305

    6666

    GeneralGeneral

    http://www.linux.comhttp://www.linux.com

    http://www.linux.orghttp://www.linux.org

    http://www.linuxberg.comhttp://www.linuxberg.com

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    67/305

    6767

    GUIsGUIs

    http://www.afterstep.orghttp://www.afterstep.org

    http://www.eazel.comhttp://www.eazel.com

    http://www.gnome.orghttp://www.gnome.org http://www.kde.orghttp://www.kde.org

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    68/305

    6868

    NewsNews

    http://slashdot.orghttp://slashdot.org

    http://www.linuxplanet.comhttp://www.linuxplanet.com

    http://www.lwn.comhttp://www.lwn.com http://www.linuxjournal.comhttp://www.linuxjournal.com

    http://www.linuxtoday.comhttp://www.linuxtoday.com

    http://www.linuxpr.comhttp://www.linuxpr.com http://www.oreillynet.comhttp://www.oreillynet.com

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    69/305

    6969

    Open SourceOpen Source

    http://www.fsf.orghttp://www.fsf.org

    http://www.gnu.orghttp://www.gnu.org

    http://www.kernelnotes.orghttp://www.kernelnotes.org http://freshmeat.orghttp://freshmeat.org

    http://www.sourceforge.nethttp://www.sourceforge.net

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    70/305

    7070

    ProjectsProjects

    http://www.apache.orghttp://www.apache.org

    http://www.squidcache.orghttp://www.squidcache.org

    http://www.linuxrouter.orghttp://www.linuxrouter.org http://www.linuxppc.orghttp://www.linuxppc.org

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    71/305

    7171

    Search EnginesSearch Engines

    http://www.google.comhttp://www.google.com

    http://www.altavista.comhttp://www.altavista.com

    http://www.northernlight.comhttp://www.northernlight.com http://www.yahoo.comhttp://www.yahoo.com

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    72/305

    7272

    SupportSupport

    http://www.linuxcare.orghttp://www.linuxcare.org

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    73/305

  • 8/7/2019 Linux Module 1

    74/305

    7474

    X Window SystemX Window System

    http://www.x.orghttp://www.x.org

    http://www.sgree86.comhttp://www.sgree86.com

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    75/305

    7575

    Role ofa SystemRole ofa SystemAdministratorAdministrator

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    76/305

    7676

    SuperuserSuperuser

    Known as the root userKnown as the root user

    Has a uid of 0Has a uid of 0

    Most powerful account on the systemMost powerful account on the system By default cannot remotely login asBy default cannot remotely login as

    rootroot

    By default cannot use root as an ftpBy default cannot use root as an ftpuseruser

    Home directory of /rootHome directory of /root4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    77/305

    7777

    SuperuserSuperuser

    Should not use superuser forShould not use superuser foreveryday use because:everyday use because:

    Normally do not need rootNormally do not need root--level accesslevel access

    If a mistake is made when logged on asIf a mistake is made when logged on asroot, it can have systemroot, it can have system--widewideimplicationsimplications

    Can read other users email and filesCan read other users email and fileswhich can cause ethical issueswhich can cause ethical issues

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    78/305

    7878

    Process UsersProcess Users

    Restricted access to processRestricted access to process--requiredrequiredresourcesresources

    Found on all UNIX and Linux systemsFound on all UNIX and Linux systems

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    79/305

    7979

    Unprivileged UsersUnprivileged Users

    Regular users that have restricted toRegular users that have restricted toareas/activities for which they have beenareas/activities for which they have beengiven permissionsgiven permissions

    Typically need only run programs andTypically need only run programs andsave documents and datasave documents and data

    Created as necessary by a systemCreated as necessary by a systemadministrator using the useradd commandadministrator using the useradd command

    or the LinuxConf graphical utilityor the LinuxConf graphical utility

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    80/305

    8080

    Module : UserModule : User

    ManagementManagement/etc/passwd, /etc/shadow,/etc/passwd, /etc/shadow,/etc/group, /etc/gshadow/etc/group, /etc/gshadow

    Useradd, usermod, userdelUseradd, usermod, userdelGroupadd, groupmod,Groupadd, groupmod,

    groupdelgroupdel

    Chage, passwdChage, passwd

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    81/305

    8181

    /etc/passwdfile/etc/passwdfile

    steve:x:500:100:steve gamblin:/home/steve:/bin/bash

    This is the file that contains account information ofusers in a Linux system. It can be read by everyone

    who is logged into the server. Only the root account haswrite privileges.

    Username:password:uid:gid:comment:home:shell

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    82/305

    8282

    /etc/passwd: username/etc/passwd: username

    Most unixes up to 8 charactersMost unixes up to 8 characters

    Has to start with a letterHas to start with a letter

    May have numbersMay have numbers Should be lowercaseShould be lowercase

    Must be uniqueMust be unique

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    83/305

    8383

    /etc/passwd: password/etc/passwd: password

    If it contains an "x" then theIf it contains an "x" then thepassword is in a special file calledpassword is in a special file called/etc/shadow/etc/shadow

    Most unixes min 6 charactersMost unixes min 6 characters

    Most unixes up to 8 charactersMost unixes up to 8 characters

    May contain spacesMay contain spaces

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    84/305

    8484

    /etc/passwd: uid/etc/passwd: uid

    Uid is the unique numerical id number forUid is the unique numerical id number forthe user.the user.

    Technically should be unique, but accountsTechnically should be unique, but accounts

    can be setup to have the same uidcan be setup to have the same uid Odd things can happen with same uidsOdd things can happen with same uids

    Generally uid from 0 to 99 reserved forGenerally uid from 0 to 99 reserved forsystem accountssystem accounts

    100 to 60000 for normal users100 to 60000 for normal users

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    85/305

    8585

    /etc/passwd: gid/etc/passwd: gid

    Number of the primary group thatNumber of the primary group thatthe user belongs to.the user belongs to.

    The users secondary groupThe users secondary group

    memberships defined in thememberships defined in the/etc/group file/etc/group file

    Gids from 0 to 99 reserved forGids from 0 to 99 reserved forsystem groups.system groups.

    100 to 60000 for general use.100 to 60000 for general use.

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    86/305

    8686

    /etc/passwd: Comment/etc/passwd: Comment

    This may or may not containThis may or may not containinformation.information.

    Should be kept to a minimumShould be kept to a minimum

    Usually contains users real nameUsually contains users real name

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    87/305

    8787

    /etc/passwd: home/etc/passwd: home

    Contains the location of the homeContains the location of the homedirectorydirectory

    Most system accounts do not have aMost system accounts do not have ahome directoryhome directory

    The root accounts home directory isThe root accounts home directory isusually /rootusually /root

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    88/305

    8888

    /etc/passwd: Default Shell/etc/passwd: Default Shell

    This contains the default shell thatThis contains the default shell thatthe Sys Admin has assigned to thethe Sys Admin has assigned to theuser.user.

    In Linux most common shell is bashIn Linux most common shell is bash

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    89/305

    8989

    /etc/shadow/etc/shadow

    steve:$1$wW4mgdYE$yQ2eQrU:11768:0:99999:7:::

    This file contains the password for the user. It is onlyreadable by the root user.

    Username:password:Days since Jan 11970 that password has been changed:Days before password can be changed:

    Days after which password must be changed:Days before password is to expire that user is warned:Days after password expires that account is disabled:Days since Jan 1,1970 that account is disabled:A reserved field:4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    90/305

    9090

    UserManagement: useraddUserManagement: useradd

    To add user accounts by commandline you use theuseradd command.Command Format: useradd [options] username

    Options-c "comment" Comment field-d /home/user home directory-u uid specify uid-g group specify primary gid-G group1, secondary groups-m create home directory-s /bin/shell specify default shell-k /etc/skel specify default profiles-n turns off group same as user creation

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    91/305

    9191

    Useradd ExampleUseradd Example

    Example:To create a user called bob.

    useradd bob

    To create a user called billy, but you want to turn offthe group creation and to have billy assigned to theusers group. and you want to add in Billy's name in the

    comment field

    useradd n c "Billy Smith" billy

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    92/305

    9292

    UseradddefaultsUseradddefaults

    You can define preset options, so that you don't have tospecify them when you use the useradd command.

    useradd D will list all of the defaults defined.

    Command Format: useradd D [options]

    Options-b home dir sets default home directory-e default expiry date sets default expiry date-g group sets default group *-s shell sets default shell4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    93/305

    9393

    UseraddUseradd D ExampleD Example

    Example:To set the default shell to the tcsh shell.

    useradd D s /bin/tcsh

    The file that contains the useradd default values is/etc/default/useradd

    Remember that you need to use the n option to havethe default group option to work in Redhat.

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    94/305

    9494

    UserManagement: usermodUserManagement: usermod

    The usermod command allows you to modify a usersaccount.

    Command Format: usermod [options] usernameOptions-c "comment" Comment field-d /home/user change home directory-m create home directory-u uid specify new uid-g group chnage primary gid-l username change username-G group1, secondary groups-s /bin/shell specify new default shell4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    95/305

    9595

    UserManagement: usermodUserManagement: usermod

    The usermod also allows you to lock and unlockaccounts.

    Command Format: usermod [options] username

    Options-L Lock the account

    -U Unlock the account

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    96/305

    9696

    Usermod ExampleUsermod Example

    Example:To change the uid of the user bob

    usermod u 550 bob

    This will also change all of the uids of the files of theuser bob, to the new ones, if they are in the home

    directory. To change any that are out side thehomedirectory, you would use the find command (with theexec option).

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    97/305

    9797

    UserManagement: userdelUserManagement: userdel

    Userdel will delete a user from the /etc/passwd file andthe /etc/shadow file.

    Command Format: userdel [option] usernameOption-r Delete home directory.

    Example:You want to delete the user named bobuserdel r bob

    This will delete his home directory as well.4/6/20114/6/2011

    B i UNIX C dB i UNIX C d

  • 8/7/2019 Linux Module 1

    98/305

    9898

    Basic UNIX CommandsBasic UNIX Commands

    unameuname Displays the name of the current operatingDisplays the name of the current operatingsystemsystem

    date Displays the date and time

    cal Displays a calendar for the current month and year.

    ls Displays the directory listing

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    99/305

    9999

    Command Line SyntaxCommand Line Syntax

    command option(s) argument(s)command option(s) argument(s)

    CommandCommand Executable commandExecutable command

    OptionOption How the command will be ranHow the command will be ran

    ArgumentArgument The file, directory or text youThe file, directory or text you

    are utilizing for the commandare utilizing for the command

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    100/305

    100100

    Control CharactersControl Characters

    Control Characters perform specific tasksControl Characters perform specific tasksat the command lineat the command line

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    101/305

    101101

    Viewing Online DocumentationViewing Online Documentation

    The online UNIX reference manuals provide aThe online UNIX reference manuals provide adetailed description of command and examples ofdetailed description of command and examples ofhow they are usedhow they are usedCommand:

    Result:

    4/6/20114/6/2011

    S lli h M PS lli h M P

  • 8/7/2019 Linux Module 1

    102/305

    102102

    Scrolling the Man PagesScrolling the Man Pages

    Keys used to control the scrolling capabilities in theKeys used to control the scrolling capabilities in the

    manualmanual..

    4/6/20114/6/2011

    S hi fS hi f

  • 8/7/2019 Linux Module 1

    103/305

    103103

    Searching forman pagesSearching forman pages

    To list the online manuals that are availableTo list the online manuals that are availableyou can use theyou can use the kk option. This will allow youoption. This will allow youlist all of the manuals in reference to thelist all of the manuals in reference to theparameter of your command.parameter of your command.

    4/6/20114/6/2011

    D t i i C t UD t i i C t U

  • 8/7/2019 Linux Module 1

    104/305

    104104

    Determining Current UsersDetermining Current Users

    TheThe whowhologged in users and whatlogged in users and whatsessions they are currently utilizing onsessions they are currently utilizing onthe server.the server.

    4/6/20114/6/2011

    Id tif i UId tif i U

  • 8/7/2019 Linux Module 1

    105/305

    105105

    Identifying a UserIdentifying a User

    TheThe who am iwho am i command allows you to identifycommand allows you to identifywho you are logged in as.who you are logged in as.

    4/6/20114/6/2011

    Id tif i U G D t ilId tif i U G D t il

  • 8/7/2019 Linux Module 1

    106/305

    106106

    Identifying UserGroupDetailsIdentifying UserGroupDetails

    Use theUse the idid command to identify the usercommand to identify the userID and group IDID and group ID

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    107/305

    P d C dP d C d

  • 8/7/2019 Linux Module 1

    108/305

    108108

    Passwd CommandPasswd Command

    The password command will assign a password to anaccount.

    Command Format: passwd [option] username

    Option-l Lock the account-u Unlock the account

    4/6/20114/6/2011

    P d E lP d E l

  • 8/7/2019 Linux Module 1

    109/305

    109109

    Passwd ExamplesPasswd Examples

    You want to lock the bob account.passwd l bob

    You want to change or set bob's passwordasswd bob

    4/6/20114/6/2011

    / t // t /

  • 8/7/2019 Linux Module 1

    110/305

    110110

    /etc/group/etc/group

    This is the file that contains the names of the groups,the gid associated with the group, and the groupsmembers.

    bin:x:1:root,bin,daemon

    Group:password:group members

    /etc/gshadow holds passwords for the /etc/group file.This is not a popular function. But can be set with thegpasswd command.

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    111/305

  • 8/7/2019 Linux Module 1

    112/305

    112112

    GroupManagement: groupmodGroupManagement: groupmod

    You can modify an existing group with the groupmodcommand.

    Command Format: groupmod [option] group

    Option-g gid change the gid-n name change the group name to name

    ExampleTo change the group name from web to accountgroupmod n account web4/6/20114/6/2011

    G M n gement g delG M n gement g del

  • 8/7/2019 Linux Module 1

    113/305

    113113

    GroupManagement: groupdelGroupManagement: groupdel

    To delete a group from the /etc/group file and fromthe system, use the groupdel command.

    Command Format: groupdel group

    ExampleTo delete the account group.groupdel account

    4/6/20114/6/2011

    Password Aging:Password Aging: chagechage

  • 8/7/2019 Linux Module 1

    114/305

    114114

    PasswordAging:PasswordAging: chagechage

    The chage command will set password aging parameters

    Command Format: chage [options] user-l displays current settings.-m # minimum days between password changes-E Set expiry date mm/dd/yyyy-M # max days a password is valid

    -W # number of days for warning of password change

    ExampleTo set the expiry date of the user bobchage E 05/10/2002 bob4/6/20114/6/2011

    Initialization FilesInitialization Files

  • 8/7/2019 Linux Module 1

    115/305

    115115

    Initialization FilesInitialization Files

    Two sets of initialization files:Global Set for all usersLocal Allows for the user to customize their

    environment.

    Global Local/etc/profile ~/.bash_profile

    /etc/bashrc ~/.bashrc

    4/6/20114/6/2011

    Initialization FilesInitialization Files

  • 8/7/2019 Linux Module 1

    116/305

    116116

    Initialization FilesInitialization Files

    Processing order

    /etc/profile

    ~/.bash_profile

    ~/.bashrc/etc/bashrc

    This is fuzzy, as~.bashrc calls/etc/bashrc

    If you start a sub shell~/.bashrc/etc/bashrc

    Processed only once, per login

    4/6/20114/6/2011

    /etc/skel/etc/skel

  • 8/7/2019 Linux Module 1

    117/305

    117117

    /etc/skel/etc/skel

    If you want to modify the initial .bash_profile and.bashrc files that will be copied into the users

    directory, they are located in the /etc/skel directory.

    You can create multiple skel directories, if you findthat you find that users need customized initializationfiles, based on group needs with the k option in the

    useradd command.

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    118/305

    118118

    Module : SystemModule : System

    SecuritySecurityReview ofPermissionsReview ofPermissions

    S and t bitsS and t bits

    Review of Chown, chmod,Review of Chown, chmod,umaskumask

    The syslog daemonThe syslog daemon4/6/20114/6/2011

    Users and GroupsUsers and Groups

  • 8/7/2019 Linux Module 1

    119/305

    119119

    Users andGroupsUsers andGroups

    Talk about users and groups

    4/6/20114/6/2011

    Command: lsCommand: ls ll

  • 8/7/2019 Linux Module 1

    120/305

    120120

    Command: lsCommand: ls--ll

    total 6drwxr-xr-x 3 steve staff ch1

    drwxr-xr-x 3 steve staff ch2

    drwxr-xr-x 3 steve staff ch3

    -rw-r--r-- 1 steve staff fullnotes

    -rw-r--r-- 1 steve staff outline

    d rwx r-x r-xFile TypeD Directory- Regular File

    UsersPermissions

    GroupPermissions

    OthersPermissions

    User (owner) Group File/dir name

    4/6/20114/6/2011

    File Security: PermissionsFile Security: Permissions

  • 8/7/2019 Linux Module 1

    121/305

    121121

    File Security: PermissionsFile Security: Permissions

    File permissions determine how users can use files andtraverse directories on the server.

    Three sets of permissions:User- Owner of the file/ directoryGroup- A grouping of usersOther- (Public) Anyone expect for the owner andmembers of the group the file/dir belongs to

    Three types of permissions:r- Read

    w- Write

    x- Execute

    - Norights

    4/6/20114/6/2011

    File Security: PermissionsFile Security: Permissions

  • 8/7/2019 Linux Module 1

    122/305

    122122

    File Security: PermissionsFile Security: Permissions

    File Rights:rFile can be read or copied

    w File can be modifiedx File can be executed (run), binary or shell scripts- No rights to file

    4/6/20114/6/2011

    File PermissionsFile Permissions

  • 8/7/2019 Linux Module 1

    123/305

    123123

    File PermissionsFile Permissions

    File Permissions:--x You can execute only *-w- You can modify only *

    r-- You can read only-wx You can modify and execute *r-x You can read and executerw- You can read and modifyrwx You can read,modify and execute

    If you do not have read rights to a file you cannot copy it,But you can move it!

    4/6/20114/6/2011

    File Security: PermissionsFile Security: Permissions

  • 8/7/2019 Linux Module 1

    124/305

    124124

    File Security: PermissionsFile Security: Permissions

    Directory Rights:rDirectory contents can be listed with lsw Files can be add or deletedx Access to directory is granted- No rights to directory

    4/6/20114/6/2011

    Directory PermissionsDirectory Permissions

  • 8/7/2019 Linux Module 1

    125/305

    125125

    Directory PermissionsDirectory Permissions

    Directory Permissions:--x You have access but can't list, delete or create *-w- Cannot do anythingr-- You can list the directory contents only *r-x You can list and travel through the directoryrw- You can list the directory contents only *-wx You can add or delete files, but can't list them,

    you can travel through the directoryrwx You can list, add, delete and travel through thedirectory

    4/6/20114/6/2011

    PermissionsPermissions

  • 8/7/2019 Linux Module 1

    126/305

    126126

    PermissionsPermissions

    Permissions are processed in the following way:

    Every user has a uid numberEvery group has a gid numberTo find out your uid/gid useThe id command.

    $ iduid=1001(steve) gid=10(staff)

    4/6/20114/6/2011

    Command: lsCommand: ls--ll

  • 8/7/2019 Linux Module 1

    127/305

    127127

    Command: lsCommand: ls--ll

    total 6drwxr-xr-x 3 steve staff ch1

    drwxr-xr-x 3 steve staff ch2

    drwxr-xr-x 3 steve staff ch3

    -rw-r--r-- 1 steve staff fullnotes

    -rw-r--r-- 1 steve staff outline

    d rwx r-x r-xFile TypeD Directory- Regular File

    UsersPermissions

    GroupPermissions

    OthersPermissions

    User (owner) Group File/dir name

    4/6/20114/6/2011

    Changing Permissions: chmodChanging Permissions: chmod

  • 8/7/2019 Linux Module 1

    128/305

    128128

    Changing Permissions: chmodChanging Permissions: chmod

    Changing file and directory permissions is done throughchmod. You have to own the file or directory in order to beable to change its permissions.

    Two ways to use chmod: symbolic modeCommand Format:

    chmod [option] [who][op-code][permission] fileOptions-R Recursively make changes

    who op-code permissionu user = set rreadggroup + add w writeo other - remove x executea

    all

    4/6/20114/6/2011

    Chmod: Symbolic ModeChmod: Symbolic Mode

  • 8/7/2019 Linux Module 1

    129/305

    129129

    Chmod: SymbolicModeChmod: SymbolicMode

    Examples:

    $ cd;touch changeme

    To add execute permissions to the file use the command:$ chmod u+x changeme

    You can also combine options in the command$ chmod u-x,o-r changeme

    In symbolic mode you can specify what permissions youwant to have changed without knowing what permissionsare already set.

    4/6/20114/6/2011

    Changing Permissions: chmodChanging Permissions: chmod

  • 8/7/2019 Linux Module 1

    130/305

    130130

    Changing Permissions: chmodChanging Permissions: chmod

    Octal Mode:Command Format: chmod [option] [octal numbers] file

    Option-R Recursively make changesOctal numbers:

    User Group Otherr=4 r=4 r=4

    w=2 w=2 w=2x=1 x=1 x=1

    (User total x 100)+(Group total x10) +(Other total)= Octal4/6/20114/6/2011

    Chmod ExamplesChmod Examples

  • 8/7/2019 Linux Module 1

    131/305

    131131

    Chmod ExamplesChmod Examples

    Examples:

    $ cd;touch changeme

    $ chmod 744 changeme

    $ chmod 640 changeme

    When you change permissions in octal mode, you mustspecify all of the permissions.

    4/6/20114/6/2011

    New Permissions Files: s bitNew Permissions Files: s bit

  • 8/7/2019 Linux Module 1

    132/305

    132132

    New Permissions Files: s bitNew Permissions Files: s bit

    The s bit can be applied to the user and the groupportions. The s bit is used when the file is executed.

    When the s bit is applied to the user part of thepermissions, it means "run this program as if youare the user"Look at /usr/bin/passwd

    When the s bit is applied to the group part of thepermissions, it means "run this program as if youare a member of the group"Look at /usr/bin/wall4/6/20114/6/2011

    New Permissions Dir: s bitNew Permissions Dir: s bit

  • 8/7/2019 Linux Module 1

    133/305

    133133

    New Permissions Dir: s bitNew Permissions Dir: s bit

    The s bit can be applied to the group portion of adirectories permissions. It has now effect if it isSet on the user or other portions.

    When a file is saved in a directory with the s bit seton the group,its group ownership will be set to thedirectories group owner.

    4/6/20114/6/2011

    Setting the s bitSetting the s bit

  • 8/7/2019 Linux Module 1

    134/305

    134134

    Setting the s bitSetting the s bit

    To set the s bit for the user, you can use either thesymbolic method or the octal method.

    Symbolic method:

    Setting it for the userchmod u+s runme.sh

    Setting it for the groupchmod s+g runme.sh

    4/6/20114/6/2011

    Setting the s bitSetting the s bit

  • 8/7/2019 Linux Module 1

    135/305

    135135

    Setting the s bitSetting the s bit

    To set the s bit in the octal mode, we add a new set:Special User Group Other

    Special:4 = user s bit in binary: 1002 = group s bit in binary: 010

    4/6/20114/6/2011

    Setting the s bit: OctalSetting the s bit: Octal

  • 8/7/2019 Linux Module 1

    136/305

    136136

    Setting the s bit: OctalSetting the s bit: Octal

    Octal setting user s bit on a filechmod 4755 runme.sh

    Octal setting the group s bit on a filechmod 2755 runme.sh

    Setting both user and group s bits on a file

    chmod 6755 runme.sh

    4/6/20114/6/2011

    The "sticky" bitThe "sticky" bit

  • 8/7/2019 Linux Module 1

    137/305

    137137

    The sticky bitThe sticky bit

    The sticky bit is applied only to a directory and hasthe effect of only allowing the owner, directory owner

    or root the ability to delete or remove files in thatdirectory.Look at /tmp

    4/6/20114/6/2011

    Setting the t bitSetting the t bit

  • 8/7/2019 Linux Module 1

    138/305

    138138

    Setting the t bitSetting the t bit

    To set the t bit for the user, you can use either thesymbolic method or the octal method.

    Symbolic method:

    chmod o+t /data

    4/6/20114/6/2011

    Setting the t bitSetting the t bit

  • 8/7/2019 Linux Module 1

    139/305

    139139

    Setting the t bitSetting the t bit

    To set the t bit in the octal mode, we use it on the newset:Special User Group Other

    Special:1 = t bit Binary 001

    4/6/20114/6/2011

    Setting the t bit: OctalSetting the t bit: Octal

  • 8/7/2019 Linux Module 1

    140/305

    140140

    Setting the t bit: OctalSetting the t bit: Octal

    Octal setting user t bit on a directory

    mkdir /public

    chmod 1777 /public

    4/6/20114/6/2011

    The special setThe special set

  • 8/7/2019 Linux Module 1

    141/305

    141141

    The special setThe special set

    You can combine the special bits, if you need to.

    For Example:You want every file created in the /public to belong tothe group html and to have the sticky bit, so that onlythe owner, directory owner or root can delete files in

    that directory.

    chown steve:html /publicchmod 3777 /public

    4/6/20114/6/2011

    Permissions: DefaultsPermissions: Defaults

  • 8/7/2019 Linux Module 1

    142/305

    142142

    Permissions: DefaultsPermissions: Defaults

    When you create a file or directory it is given defaultpermissions.Defaults:

    Files rw- rw- rw- (666)Dir. rwx rwx rwx (777)

    These defaults can be changed with the umask command.Command Format: umask [octal number]

    User Group Otherr=4 r=4 r=4

    w=2 w=2 w=2

    x=1 x=1 x=1

    (User total x 100)+(Group total x10) +(Other total)= Octal4/6/20114/6/2011

    Permissions: umaskPermissions: umask

  • 8/7/2019 Linux Module 1

    143/305

    143143

    Permissions: umaskPermissions: umask

    To view your current umask filter:$ umask022 The OS creates this for you

    $ touch changeme

    Default permissions: rw- rw- rw- (666)Umask filter: --- -w- -w- (022)

    Result rw- r- r- (644)

    If a file exists and you copy it, the umask is applied tothe file. It does not affect file/directory moves.4/6/20114/6/2011

    Permissions: umaskPermissions: umask

  • 8/7/2019 Linux Module 1

    144/305

    144144

    Permissions: umaskPermissions: umask

    Umask only takes away rights, does not add them. Youcan set your own umask to suit your security needs.

    Example:$ umask 027 Files: Allows all default rights to the

    owner/creator, gives group usersread only rights, and no rights toeveryone else to newly created files.

    Dir: Allows all rights to users, givesread and execute permissions togroup users and no permissions toeveryone else to newly createddirectories.

    4/6/20114/6/2011

    Chown: Changing OwnershipChown: Changing Ownership

  • 8/7/2019 Linux Module 1

    145/305

    145145

    C o C a g g O e s pC o C a g g O e s p

    chown changes the ownership of a file or directory.

    Command Format: chown [-options] file-R recursively change files

    Example:$ touch changeme$ chown root changeme

    $ ls l changeme-rw-r--r-- 1 root staff 0 Jan 6 15:19 changeme

    4/6/20114/6/2011

    Chown AgainChown Again

  • 8/7/2019 Linux Module 1

    146/305

    146146

    gg

    To change a files ownership and group assignment at thesame time use the chown command.

    Command Format: chown user:group [option] file

    Or chown user.group [option] fileOr chown .group [option] file

    -R Recursively change assignments

    Example:$ touch allchange$ chown root:web allchange$ ls l allchange-rw-r--r-- 1 root web 0 Jan 6 15:51 allchange4/6/20114/6/2011

    chgrpchgrp

  • 8/7/2019 Linux Module 1

    147/305

    147147

    g pg p

    To change the group assignment of a file or directory,use the chgrp command.

    Command Format: chgrp [options] file-R recursively change files

    Example:$ touch mygroupfile

    $ chgrp web mygroupfile$ ls l mygroupfile-rw-r--r-- 1 steve web 0 Jan 6 15:46 mygroupfile

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    148/305

    148148

    Module 4: CommandModule 4: Command

    ReviewReview

    Cp, mv, touch,Cp, mv, touch,*,?,[],{},>,,

  • 8/7/2019 Linux Module 1

    149/305

    149149

    yy

    Lists the files and directories in theLists the files and directories in thedirectory specifieddirectory specified

    Command Format: ls [Command Format: ls [--options] [pathname]options] [pathname]

    Options:Options:

    --aa Display hidden filesDisplay hidden files

    --FF Display with file types * / @Display with file types * / @

    --ll Display long formDisplay long form

    --RR List files in subdirectoriesList files in subdirectories

    --bb List hidden charactersList hidden characters

    --dd List directory names but not the contentsList directory names but not the contents4/6/20114/6/2011

    Commands: cat ConcatenateCommands: cat Concatenate

  • 8/7/2019 Linux Module 1

    150/305

    150150

    Cat will display text files on the screen.

    Command Format: cat filename

    Example:

    $ cat /etc/passwd

    $ cat /etc/passwd /etc/groups > sysfiles.txt

    4/6/20114/6/2011

    Commands: touchCommands: touch

  • 8/7/2019 Linux Module 1

    151/305

    151151

    Touch allows you to create an empty file. If the filealready exists, then touch will update the last accesstime stamp.

    Command Format: touch filename

    Examples:$ cd$ touch test$ touch test1 test2 test3

    4/6/20114/6/2011

    Commands: cpCommands: cp

  • 8/7/2019 Linux Module 1

    152/305

    152152

    pp

    Copy files and or directories from one location to another

    Command Format: cp [option] source destination

    -i Confirm overwrite-r Recursive copy used in directory coping-p Preserve all information (root)Source Can be files or directoriesDestination Can be filenames or directories

    Example:# cp /home/steve/readme.txt /root/# cp p /home/steve/readme.txt /root/readme2.txt

    4/6/20114/6/2011

    Commands: mvCommands: mv

  • 8/7/2019 Linux Module 1

    153/305

    153153

    Move or rename files or directories.

    Command Format: mv [option] source destination

    -i Confirm overwrite-f Force MoveSource Can be a file or directoryDestination Can be file or directory

    Examples:$ cd;touch waffle;mkdir breakfast$ mv waffle eggs$ mv eggs breakfast

    $ mv breakfast lunch

    4/6/20114/6/2011

    Commands: rmCommands: rm

  • 8/7/2019 Linux Module 1

    154/305

    154154

    Delete files (and directories) with rm.

    Command Format: rm [option] filename

    -i Confirm deletion-r Remove Directory and its contents-f Force removal of files with no write permission

    Examples:

    $ cd;touch babar;mkdir house;touch house/chair$ rm i babar$ rm r house4/6/20114/6/2011

    Commands: mkdirCommands: mkdir

  • 8/7/2019 Linux Module 1

    155/305

    155155

    Mkdir creates an empty directory.

    Command Format: mkdir [option] directory_name

    -p Create directories within directories-m set access permissions

    Examples:$ cd

    $ mkdir m 777 coffee$ mkdir beans$ ls -l

    4/6/20114/6/2011

    Commands: rmdirCommands: rmdir

  • 8/7/2019 Linux Module 1

    156/305

    156156

    The rmdir command only deletes empty directories.

    Command Format: rmdir directory_name

    Example:

    $ cd;mkdir tempdir

    $ rm tempdirIf the directory contained files and you still wanted todelete it, remember to use the rm rf command

    4/6/20114/6/2011

    MetacharactersMetacharacters

  • 8/7/2019 Linux Module 1

    157/305

    157157

    * Asterisk? Question Mark

    [] Brackets; Semi-colon

    4/6/20114/6/2011

    Metacharacters: AsteriskMetacharacters: Asterisk

  • 8/7/2019 Linux Module 1

    158/305

    158158

    *Wildcard Character. Match zero or more characters.

    Slang: Splat,Star

    Example:$ cd /usr/bin$ ls b* List all the files that start with b

    4/6/20114/6/2011

    Metacharacters: Question MarkMetacharacters: Question Mark

  • 8/7/2019 Linux Module 1

    159/305

    159159

    ?Match a single character.Slang: Query

    Example

    $ cd /usr/bin

    $ lsp?? List all the files that start with pbut contain three characters

    4/6/20114/6/2011

    Metacharacters: BracketsMetacharacters: Brackets

  • 8/7/2019 Linux Module 1

    160/305

    160160

    []Square BracketsMatch a single character with either a range [a-c] or

    set [abc] ([bca] is the equivalent of [abc]) [A-z] for upperand lower case matching

    Example:$ cd /usr/bin

    $ ls[ab]* List all the files that start withletters a or b

    $ ls[!ab]* Using the ! Says, don't match thesecharacters4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    161/305

    Metacharacters: Semi ColonMetacharacters: Semi Colon

  • 8/7/2019 Linux Module 1

    162/305

    162162

    Allows for multiple commands on one line

    Command Format:Command;Command;Command

    Example:$ date;pwdSun Oct14 19:43:47 ADT 2001/usr/bin

    4/6/20114/6/2011

    Redirection: > < >Redirection: > < >

  • 8/7/2019 Linux Module 1

    163/305

    163163

    Input to a command can come from the keyboard or byusing a can put put into a file or with a >> can beAppended to the end of a file.

    Error messages are usually displayed on the screen, butBy using a 2> can be redirected to a file.

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    164/305

  • 8/7/2019 Linux Module 1

    165/305

    Redirection:

  • 8/7/2019 Linux Module 1

    166/305

    166166

    Take the contents of a file and uses it as if it were inputfrom the keyboard.

    Command Format: command < file

    Examples:

    $ ls > lists

    $ sort r < lists

    4/6/20114/6/2011

    Redirection: >Redirection: >

  • 8/7/2019 Linux Module 1

    167/305

    167167

    Direct any error messages into a file.

    Command Format: command 2> file

    Example:$ cd$ find /home name ls 2> err.log$ cat err.log

    If err.log doesnt exist, it will be created and the outputwill be put into the file.

    4/6/20114/6/2011

    Redirection: >>Redirection: >>

  • 8/7/2019 Linux Module 1

    168/305

    168168

    Append any error messages into a file.

    Command Format: command 2>> file

    Example:

    $ cd$ ls /usr/rack 2> err.log$ ls /bix 2>> err.log$ cat err.log

    /usr/rack: No such file or directory/bix: No such file or directory

    If err.log doesnt exist, it will be created and the outputwill be put into the file. The second error will be

    appended to the err.log file

    4/6/20114/6/2011

    Multiple RedirectionMultiple Redirection

  • 8/7/2019 Linux Module 1

    169/305

    169169

    You can use all redirectors if you want to.

    Command Format: command > file1 2> file2

    Example:$ cd$ find / -name "*sh" > list.txt 2> err.log

    If the command has some output, then it will be placedin the list.txt file, but if the command has an error, thenit will be placed in the err.log file.The append notation could be used as well (>>)4/6/20114/6/2011

    Redirecting: MiscRedirecting: Misc

  • 8/7/2019 Linux Module 1

    170/305

    170170

    When you run a command, three files are opened and areassociated with that command.

    They Are: Standard Input (STDIN)=0Standard Output (STDOUT)=1Standard Error (STDERR)=2

    So when you redirect input or output, you are manipulatingthese files. When you want to redirect output you use the

    form: command n> file.To redirect output coming from both STDOUT and STDERRinto the same file you would use the form:

    command > file 2>&1 or

    command >> file 2>&1

    4/6/20114/6/2011

    Redirecting: Discarding outputRedirecting: Discarding output

  • 8/7/2019 Linux Module 1

    171/305

    171171

    Sometimes you may not want output from a command tobe displayed on the screen and we may not want itsaved to a file. You can send output to a special file

    called /dev/null which discards any output it receives.It takes the form of:command > /dev/null orcommand > /dev/null 2>&1 orcommand 2> /dev/null

    Example:$ $ find / -name "*sh" > list.txt 2> /dev/null

    This completes the command but all output is sent to the

    bit bucket

    4/6/20114/6/2011

    Piping: |Piping: |

  • 8/7/2019 Linux Module 1

    172/305

    172172

    Piping takes the output of one command and uses it asinput for another command.

    Command Format: command | command

    Example:

    $ ls /usr/bin | more

    $ ls /usr/bin | sort r | more

    You can have more than one pipe within a set of commands4/6/20114/6/2011

    Splitting Direction with :teeSplitting Direction with :tee

  • 8/7/2019 Linux Module 1

    173/305

    173173

    Send the output of a command to the screen and to a file.Commonly used with the pipe command

    Command Format: tee [option] filename-a Append to a file

    Examples:

    $ ls /sbin | tee sbin.list$ date | tee a sbin.list$ date | tee date.txt

    4/6/20114/6/2011

    BashAliasesBashAliases

  • 8/7/2019 Linux Module 1

    174/305

    1741744/6/20114/6/2011

    bash: Aliasesbash: Aliases

  • 8/7/2019 Linux Module 1

    175/305

    175175

    Aliases allow for:Creation of CommandsCreation of alternate forms of a command

    Multiple commands rolled into oneCan be added to the .bashrc, so they can be availiable atlogin. They dont transfer to sub shells.

    Command Format: alias command=new_command

    Examples:$ alias ls='ls F'$ alias c=clear$ alias copy='cp i'$ alias home='cd;ls'

    4/6/20114/6/2011

    bash: Aliasesbash: Aliases

  • 8/7/2019 Linux Module 1

    176/305

    176176

    To view the current aliases in use the alias command.

    Command Format: alias

    To delete an alias use the unalias command.Command Format: unalias alias

    Example:$ unalias ls

    To temporarily bypass an alias use the back slash \

    Example:$ \ls4/6/20114/6/2011

    Bash Command SubstitutionBash Command Substitution

  • 8/7/2019 Linux Module 1

    177/305

    177177

    Bash offers two types of command substitution

    Using the back quotes ``

    Using the brackets ()

    4/6/20114/6/2011

    BackQuotesBackQuotes

  • 8/7/2019 Linux Module 1

    178/305

    178178

    There are some special characters to help puttinginformation into variables.Single back quotes ` ` When a command is put

    between back quotes, its output is used as thevariables informationExample:$ DT=`date`$ echo $DT

    Tue Oct 23 19:38:38 ADT 2001

    4/6/20114/6/2011

    BracketsBrackets

  • 8/7/2019 Linux Module 1

    179/305

    179179

    There are some special characters to help puttinginformation into variables.Single back quotes ` ` When a command is put

    between back quotes, its output is used as thevariables informationExample:$ DT2=$(date)$ echo $DT2

    Tue Oct 23 19:38:38 ADT 2001

    4/6/20114/6/2011

    Single QuotesSingle Quotes

  • 8/7/2019 Linux Module 1

    180/305

    180180

    Single quotes ' ' dont allow for any command or variablesubstitution.

    $WO='uname n'$ echo $WO

    $ WO=`uname n`$ echo ' this computer is named $WO and thetime is `date` 'this computer is named $WO and the time is Tue Oct 2319:48:51 ADT 2001

    4/6/20114/6/2011

    Double QuotesDouble Quotes

  • 8/7/2019 Linux Module 1

    181/305

    181181

    Double quotes allow for commands and variables to beused within the text

    $ echo " this computer is named $WO and the

    time is `date` "

    this computer is named bob and the time is Tue Oct 2319:48:51 ADT 2001

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    182/305

    182182

    Module 5Module 5

    Grep, cut, expand, fmt, join,Grep, cut, expand, fmt, join,nl, od,paste, pr, split, tac, tr,nl, od,paste, pr, split, tac, tr,

    xargs, sedxargs, sed

    4/6/20114/6/2011

    grepgrep

  • 8/7/2019 Linux Module 1

    183/305

    1831834/6/20114/6/2011

    Searching in files: GrepSearching in files: Grep

  • 8/7/2019 Linux Module 1

    184/305

    184184

    Grep allows you to search files for text. Grep can alsoworks with other commands as a filter.

    Command Format: grep [options] pattern filename

    -i ignore case-v Search for all patterns that do not match-w Use pattern as a word-n print line number

    Examples:$ grep root /etc/passwdroot:x:0:1:Super-User:/:/sbin/sh

    4/6/20114/6/2011

    Grep WildcardsGrep Wildcards

  • 8/7/2019 Linux Module 1

    185/305

    185185

    Wildcards^pattern Match only if pattern is at the start of a linePattern$ Match only if pattern is at the end of a line

    . Match exactly one character[list] match exactly one character in list[^list] Don't match any character in list.* Match 1 or more characters* Repeat previous character

    4/6/20114/6/2011

    Grep ExamplesGrep Examples

  • 8/7/2019 Linux Module 1

    186/305

    186186

    cat test.txtabcabbc

    acabghgtcbilabagkcxbcdvbc

    $ grep ab*c test.txt

    $ grep ab.*c test.txt

    $ grep .*g test.txt

    $ grep ^c test.txt

    $ grep k$ test.txt

    $ grep [^ad] test.txt4/6/20114/6/2011

    cutcut

  • 8/7/2019 Linux Module 1

    187/305

    187187

    The cut command allows you to print a selected columnof a text file.

    Command Format: cut [option] fileOption-c print the character in column #-d set field delimiter (default-f# print field number

    Example:To list the second field in the /etc/passwd filecut d : -f 5 /etc/passwd4/6/20114/6/2011

    expandexpand

  • 8/7/2019 Linux Module 1

    188/305

    188188

    Expand replaces tabs with spaces. The default is8 spaces to a tab. This does not affect the originalfile.

    Command Format: expand [options] file-t # replace the tab with # of spaces.

    Example:

    expand t 2 list.txt

    Expand t 2 list.txt > newlist.txt4/6/20114/6/2011

    fmtfmt

  • 8/7/2019 Linux Module 1

    189/305

    189189

    The fmt command formats paragraphs to a uniformlength. By default, fmt will reformat each line of aparagraph to a length of 75 lines

    Command Format: fmt [option] fileOption-u Set one space between words, two spaces

    between sentences.-w set line length default is 75 characters.Example

    4/6/20114/6/2011

    tactac

  • 8/7/2019 Linux Module 1

    190/305

    190190

    Tac is the cat command in reverse.

    Command Format: tac file

    Example: tac grinch.txt

    4/6/20114/6/2011

    joinjoin

  • 8/7/2019 Linux Module 1

    191/305

    191191

    The join command allows you to two files that share acommon field.

    Command Format: join [option] file1 file2Option-j1 field Use field #(column) in file one-j2 field Use field #(column) in file two-j field Use this field for both files

    Example:join j11 j2 2 joiner1.txt joiner2.txt

    4/6/20114/6/2011

    nlnl

  • 8/7/2019 Linux Module 1

    192/305

    192192

    The nl command counts the number of lines in afile, but will adhere to certain formatting rules.The \:\:\: characters signify that the next text willbe a header.The \:\: characters signify the the following will bethe body.The \: characters signify that the next set will the

    footer.

    4/6/20114/6/2011

    nlnl

  • 8/7/2019 Linux Module 1

    193/305

    193193

    Command Format: nl [option] fileOption-b type Body numbering options

    -h type Header number options-f type Footer numbering optionsType:a Number all linesn Do not number linest Number only non empty linespPATTERN Number only lines that contain PATTERN

    4/6/20114/6/2011

    nl examplenl example

  • 8/7/2019 Linux Module 1

    194/305

    194194

    This counts only the lines in the body section that containthe pattern line2

    nl b pline2 nltest.txt

    4/6/20114/6/2011

    odod

  • 8/7/2019 Linux Module 1

    195/305

    195195

    The od command allows you to view files in variousformats. This is useful for viewing binary files.

    Command Format: od [option] fileOption-t type Type of output to be displayed

    Type: a Named Characterc backslashx Hexidecimalo Octal

    4/6/20114/6/2011

    odod

  • 8/7/2019 Linux Module 1

    196/305

    196196

    Examples:

    od t c od.txt

    0000000 a h \n b l a h \n \n0000011

    od t x od.txt0000000 620a6861 0a68616c 0000000a0000011

    4/6/20114/6/2011

    pastepaste

  • 8/7/2019 Linux Module 1

    197/305

    197197

    The paste command connects two or more files vertically.

    Command Format: paste [option] file1 file2

    -d'char' Separate columns by 'char'-s Merge, moving all of the lines of the file into

    one line, and in the next file move all of the

    lines into one line and place it below thefirst line.

    4/6/20114/6/2011

    prpr

  • 8/7/2019 Linux Module 1

    198/305

    198198

    Print a file with headers and page fills. The headerconsists of the date, time, filename and page number.

    Command Format: pr [option] file

    Option-d Double space-h 'header' Use 'header' instead of the filename in the

    header section

    -l # Set the number of lines per page-o # Set the left margin

    Example:pr grinch.txt

    4/6/20114/6/2011

    splitsplit

  • 8/7/2019 Linux Module 1

    199/305

    199199

    Chunk up a file into separate files. The extensions of the newfiles will be in the form of aa, ab, ac

    Command Format: split [option] file splitfilename-n # Split the file into # lines per segment-b # Size in bytes,

    if you use #k it will be in kilobytesif you use #m it will be in megabytes

    Example: split n 50 grinch.txt grinsplit_

    4/6/20114/6/2011

    trtr

  • 8/7/2019 Linux Module 1

    200/305

    200200

    Translate (or replace) characters from one string to thesecond string specified.

    Command format: tr [option] string1 string2Option-d Delete characters from string1 from the output-s Delet repeated characters from string1

    Example:tr Gg VQ < grinch.txt

    4/6/20114/6/2011

    xargsxargs

  • 8/7/2019 Linux Module 1

    201/305

    201201

    Xargs takes the ouput from a command and treats it as alist for another command to process.

    Command Format: xargs [option] commandOption-p Prompt before executing the command

    Example:

    find . type f | xargs grep Grinch

    4/6/20114/6/2011

    sedsed

  • 8/7/2019 Linux Module 1

    202/305

    202202

    Sed is a non interactive text editor. You can edit filesthrough a sed command or through a sed script.

    Command Format: sed [option] 'command' file

    Option-f file Take commands from file-e cmd Next argument is a command (for

    multiple commands in one sedcommand)

    -g All substitutions are global-n Print only what the print cmd tells you to4/6/20114/6/2011

    sedsed

  • 8/7/2019 Linux Module 1

    203/305

    203203

    Editing Commands:

    'Address'd Delete a line or lines

    'Address'p print a line or lines'/string/r file' Read a files/string1/string2/ Substitute one string for another

    Where 'Address' can be a line number or a range of linesto be edited.

    4/6/20114/6/2011

    Sed: Examples: PrintingSed: Examples: Printing

  • 8/7/2019 Linux Module 1

    204/305

    204204

    To print a range of text.

    sed n '5,15p' grinch.txt

    Print the lines that contain the pattern Christmas

    sed n '/Christmas/p' grinch.txt

    4/6/20114/6/2011

    Sed: Examples: SubstitutingSed: Examples: Substituting

  • 8/7/2019 Linux Module 1

    205/305

    205205

    To substitute a pattern, use the 's/string1/string2/' cmd

    sed 's/Grinch/Jimmy/' grinch.txt

    To add the new string to the old string

    sed 's/Grinch/Jimmy&/' grinch.txt

    To make changes globally. If there are paragraphs

    sed 's/Grinch/Jimmy/s' grinch.txt4/6/20114/6/2011

    Sed: Examples: DeletingSed: Examples: Deleting

  • 8/7/2019 Linux Module 1

    206/305

    206206

    To delete a range of text.

    sed '5,15d' grinch.txt

    Delete the lines that contain the pattern Christmas

    sed '/Christmas/d' grinch.txt

    Don't delete lines 10,20

    sed '10,20!d' grinch.txt4/6/20114/6/2011

    Sed: Examples: Insert FileSed: Examples: Insert File

  • 8/7/2019 Linux Module 1

    207/305

    207207

    To insert file aftermatch is found.

    sed '/Grinch/r insert.txt' grinch.txt

    Print the lines that contain the pattern Christmas

    sed n '/Christmas/p' grinch.txt

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    208/305

  • 8/7/2019 Linux Module 1

    209/305

    209209

    Module 6Module 6

    Linux File SystemLinux File System

    fdisk, mkfs, mkswap, df, du,fdisk, mkfs, mkswap, df, du,

    fsck, mount, umount, fuser,fsck, mount, umount, fuser,fstab, mtabfstab, mtab

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    210/305

    210210

    Module 7Module 7

    Disk QuotasDisk Quotas

    Quota, quotaon, quotaoff,Quota, quotaon, quotaoff,

    quotacheck, edquota,quotacheck, edquota,repquotarepquota

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    211/305

    211211

    Module 8Module 8

    Process ControlProcess Control

    Ps, top, pstree, kill, &, fg, bg,Ps, top, pstree, kill, &, fg, bg,

    jobs, nice, renicejobs, nice, renice

    4/6/20114/6/2011

    ProcessesProcesses

  • 8/7/2019 Linux Module 1

    212/305

    212212

    Every programme/ action/ task creates a process.Each process gets a unique number called a PID.Five types of processes:

    Daemon: Started by the kernel and wait for actionParent: First process to be run, if it spawns any

    processes then they are its children. I.e. Terminal sessionChild: A process run from another processOrphan: A process that doesnt end before its

    parent. Sent to the init process to be shutdownZombie: A lost process. Loses its parent and canonly be removed by a reboot.

    4/6/20114/6/2011

    pstreepstree

  • 8/7/2019 Linux Module 1

    213/305

    213213

    Pstree allows you to see how processes are related ordependent on each other. It is presented in a humanreadable form.

    Command Format: pstree [option] [pid|user]Optionsa Show cmd line args used to execute the processG View the tree using vt100 charactersn Sort by pid number instead of alphap Include PIDs in output

    4/6/20114/6/2011

    Processes: pstreeProcesses: pstree

  • 8/7/2019 Linux Module 1

    214/305

    214214

    [steve@bob recipes]$ pstreeinit-+-apmd

    |-atd|-crond

    |-deskguide_apple|-gconfd-1|-gdm---gdm-+-X| `-gnome-session|-gnome-name-serv

    |-gnome-smproxy|-gpm|-httpd---8*[httpd]|-identd---identd---3*[identd]4/6/20114/6/2011

    Viewing process IDs: PSViewing process IDs: PS

  • 8/7/2019 Linux Module 1

    215/305

    215215

    The ps command allows you to view the current processesrunning on the system.

    Command Format: ps [options]

    -a View all processes-u User format , and start time of process-f Display full listing-x Include processes without controlling

    terminals-U user Display users processes-G group Display groups processes

    4/6/20114/6/2011

    PSPS

  • 8/7/2019 Linux Module 1

    216/305

    216216

    Since ps screens can be long its useful to combine it withsome other commands, like more and grep.

    Example:

    $ ps aux | moreUSER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

    root 1 0.0 0.2 1412 520 ? S Mar28 0:04 init [5]

    root 2 0.0 0.0 0 0 ? SW Mar28 0:00 [keventd]

    root 3 0.0 0.0 0 0 ? SW Mar28 0:00 [kapm-idled]

    Or if you want to search for a certain process$ ps aux | grep initroot 1 0.0 0.2 1412 520 ? S Mar28 0:04 init [5]

    4/6/20114/6/2011

    toptop

  • 8/7/2019 Linux Module 1

    217/305

    217217

    Top is like ps, but it will refesh its listing to keep thedisplay current. Top laso displays, memory and swapusage. Uptime, load and cpu status are also displayed.

    Command Format: top [option]Optionsb Run in batch mode. Creates a snap shot.d Set the refresh rate in seconds.

    n # refresh # of times then exitq Run with no delay, should not run as roots Disable interactive commands

    4/6/20114/6/2011

    Top: Interactive commandsTop: Interactive commands

  • 8/7/2019 Linux Module 1

    218/305

    218218

    When top is running, you can use it to modify processes.

    Commands:

    h or ? Display the help screenk Kill a processn Change the number of processes to showr Renice a process (change it's priority)u Show a specific userSpace Update Displayq quit top

    4/6/20114/6/2011

    pgreppgrep

  • 8/7/2019 Linux Module 1

    219/305

    219219

    Pgrep combines ps and grep into one command. This isnew to Solaris 7 & 8.

    Command Format: pgrep [options] string-l Long listing-U Users process-G Groups process

    Example:$ pgrep l init1 init

    4/6/20114/6/2011

    Job ControlJob Control

  • 8/7/2019 Linux Module 1

    220/305

    220220

    Unix allows you to be able to run multiple programsat the same time on the same terminal. This isespecially useful if you are working from a command

    line interface. If you are using a window manager likeKDE/CDE or Gnome then jobs can only be controllingfrom the terminal window that they were startedfrom.

    4/6/20114/6/2011

    Job ControlJob Control

  • 8/7/2019 Linux Module 1

    221/305

    221221

    Commands:jobs Displays what jobs are running and itsID

    bg %n Puts a job into the background (n= jobid)fg %n Brings a job back to the foregroundkill %n Ends the jobControl C Aborts the foreground job

    Control Z Suspends the foreground job& Used at the end of a command to put it

    in the background4/6/20114/6/2011

    Job ControlJob Control

  • 8/7/2019 Linux Module 1

    222/305

    222222

    Examples:$ find / -name core > /tmp/clist 2> /tmp/c.err &Look for all files named core, put the result in the file/tmp/clist, if there are any errors list them in /tmp/c.errand with the & run it in the background.[1] 2372$ jobs[1] + Running find / -name core > /tmp/clist

    Job ID Status Command

    4/6/20114/6/2011

    Job ControlJob Control

  • 8/7/2019 Linux Module 1

    223/305

    223223

    $ ls R / > /dev/null 2> /dev/null &[2] 2385$ jobs[2] + Running ls -R / > /dev/null 2> /dev/null &

    [1] - Running find / -name core > /tmp/clist 2>

    $ fg %1Brings the find job to the foreground$ ^Z(Control Z) suspends the job

    $ bg %1Puts the job back to the background$ kill %2Terminates the first job

    4/6/20114/6/2011

    Terminating ProcessesTerminating Processes

  • 8/7/2019 Linux Module 1

    224/305

    224224

    When a process stops responding or is out of control, ithas to be terminated.Sending an interupt ( control c) will sometimes terminate

    a process.The kill command is another way to end a process,epically if your terminal is locked up and you have to useanother terminal window.

    4/6/20114/6/2011

  • 8/7/2019 Linux Module 1

    225/305

    PkillPkill

  • 8/7/2019 Linux Module 1

    226/305

    226226

    Pkill combines ps and grep with kill to make search forthe process id easier.

    Command Format: pkill string

    Example:$ pkill find

    4/6/20114/6/2011

    nicenice

  • 8/7/2019 Linux Module 1

    227/305

    227227

    The nice command will let you run a command witha lower priority. A processes' priority can range from20 to +19. By default it runs at 0.

    The higher the number,the lower the priority.Normal users can adjust a program from 1 to 19

    Root can adjust a program from 20 to 19Default adjustment is 10

    Command Format: nice [option] commandOptionn -# Adjust the priority to #--4/6/20114/6/2011

    nicenice

  • 8/7/2019 Linux Module 1

    228/305

    228228

    The nice co