rootsan technologies pvt ltd linux modul033

Upload: prasanna3980

Post on 08-Apr-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    1/184

    Welcome to RedHat Linux

    RH033

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    2/184

    Hardware Requirements

    Pentium Pro or better with 256 MB RAMOr

    64-bit Intel/AMD with 512 MB RAM

    2-6 GB disk space

    Bootable CD

    Other processor architectures supported

    Itanium 2, IBM Power, IBM Mainframe

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    3/184

    Lesson 1 Fundamentals of

    Linux

    IntroductionLinux is an open source operating system with

    highly advanced features.

    Topics

    Brief History of Linux

    Why is Linux?Linux Distributions

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    4/184

    Brief History of Linux

    Linux was originally developed by LinusTorvald in 1991.

    Linux is distributed under the GNU licenses.

    GNU stands for Gnu Not UNIX, it is an opensource movement started by RichardStallman in the year 1984.

    The main aim of GNU is to provide the O.Sand its source code freely.

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    5/184

    Why Linux?

    Linux is an Open Source Software

    Multi-user and multi-tasking

    Supports most of modern PC hardware

    Fully supported distribution

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    6/184

    Linux Distributions

    To install Linux, choose a Linux Distribution

    A distribution is the Linux kernel, plus aninstallation program, plus some set of

    applications

    There are four general distributions RedHat SuSE Mandriva Linux Debian

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    7/184

    Linux Distributions

    The Red Hat and SuSE distributions are produced by

    companies by the same names.

    They aim at providing an easy installation procedure, andfor a pleasant desktop experience. They are also good asservers, sold in boxes, with an installation CD and printed

    manual. Both can also be downloaded via the network.

    Mandriva Linux (also known as Mandrake Linux) wasoriginated by Gael Duval.

    Mandriva Linux is also notable for compiling its packages

    with optimizations for Pentium-class and more advancedprocessors which are incompatible with older CPU versionssuch as 386 and 486.

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    8/184

    Linux Distributions

    The Debian distribution is produced by avolunteer organization.

    Its installation is less easy: You have to

    answer questions during the installation theother distributions deduce automatically.Nothing complicated as such, but requiringunderstanding of and information abouthardware most PC users don't want to worryabout.

    On the other hand, after installation, Debian

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    9/184

    Logging In and GeneralOrientation

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    10/184

    Module 2 Logging In and

    General Orientation

    IntroductionIn Linux, a terminal session starts by

    logging in through the terminal. When theuser logs in for the first time, the user

    account is set and provided with apassword.

    Topics Typical terminal session Concept of Login and Logout Opening of Shell Prompt Command Line Format

    Basic commands vi Editor

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    11/184

    A Typical Terminal Session

    Provides login prompt to the user

    Linux has two modes of terminals

    Graphical User InterfaceCharacter User Interface

    Linux has seven terminals by default (F1 F6)

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    12/184

    Logging In and Out

    A Graphical login screen Graphical Logout Session

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    13/184

    Opening a Shell Prompt

    Snapshot

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    14/184

    Command Line Format

    Pattern of issuing the command

    The commands are separated with optionsusing spaces and symbols.

    The options are usually prefixed with thehyphen ( - )

    Command line has three basic parts Command Options Arguments

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    15/184

    Shell Interpretation

    Shell prompt accepts commands to perform various functions like:Execute commands

    Variable assignment

    Variable substitution

    Filename generationI/O redirection

    Pipelines

    Command substitution

    Interpretive Programming language

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    16/184

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    17/184

    Basic Commands

    vi opens a text editor

    rm remove files

    mv move or rename the files

    cp copy the files

    rmdir removes the directory

    pwd display present working

    exit or logout leave the session

    man command Read man pages on command

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    18/184

    vi Editor

    vi (visual) editor was written in 1976 by BillJoy at the University of California, Berkeley.

    vi uses a small amount of memory, which

    allows efficient operation when the networkis busy.

    vi is the only editor which provides basic textediting capabilities.

    There are three modes of operation for vi.

    They are: Command mode

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    19/184

    Usage of vi Editor

    A text editor is a program used to edit files thatare composed of text which can be a

    Simple regular text

    The source code of a program orConfiguration file

    The vi text editor

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    20/184

    Lab Exercises

    Type vi editor and get the vi session

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    21/184

    Navigating the File Systems

    d l i i h

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    22/184

    Module 4 Navigating the

    File SystemsIntroduction

    A file system is the methods and the data structures that anoperating system uses to keep track of files.

    Topics

    The Tree Structure

    The File System Hierarchy

    Path Names

    Basic File System Commands

    Create and Remove Directories

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    23/184

    Th T St t

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    24/184

    The Tree Structure

    Linux File Structure

    Example:/home/condron/source/xntp

    Th Fil S t Hi h

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    25/184

    The File System Hierarchy

    File System Hierarchy Standard (FHS)

    The directories and files noted here are small subsets of those specifiedby the FHS document.

    The /dev/ Directory

    The /etc/ Directory

    The /lib/ Directory

    The /mnt/ Directory

    The /opt/ Directory

    The /proc/ Directory

    The /sbin/ Directory

    P th N

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    26/184

    Path Names

    A PATH is an environment variable that is a

    list of directories that the operating systemlooks in to find commands issued by theuser.

    Example 1: # whereis ls

    ls: /bin/ls /usr/share/man/man1/ls.1.gz

    There are two types of path names

    Relative Path

    Absolute Path

    Contd

    P th N

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    27/184

    Path Names

    Absolute path

    Accessing a particular directory or file from the otherlocation, by typing the full details of path.

    Absolute path starts with the root (/) directory. It

    includes all directories and sub-directories. A relative path starts in your present working directory.

    Relative path

    Accessing a particular directory or file from samelocation, by typing the file or directory name.

    In the case of relative path, the path does not start

    with a slash.

    B i Fil S t C d

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    28/184

    Basic File System Commands

    pwd It displays the users present

    working directory.

    ls Lists the contents of the files

    and directories

    cd Changes and also opens thedirectory.

    cat It combines files and print onthe standard output

    find Command The find command

    C t d R

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    29/184

    Create and Remove

    Directories Creating directories

    Use mkdir command to create a new directory

    Syntax

    # mkdir

    Example: mkdir dir1

    Removing directories There are two commands you can use for removing

    directories. rmdir

    rm -r

    L b E i

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    30/184

    Lab Exercise

    How will you create a new directory?

    Use rm r to remove the existing directory.

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    31/184

    Managing Files

    Mod le 5 Managing Files

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    32/184

    Module 5 Managing Files

    Introduction

    On a Linux system, everything is a file;if something is not a file, it is a process.

    Topics

    What is a File?

    File CharacteristicsWhat can we do with Files?

    What is a File?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    33/184

    What is a File?

    A file is a container for data or link to a

    device.

    Every file has a name and may hold datathat resides on a disk.

    A file is a name and the associated data isstored on a mass storage device. It is a

    stream of data bytes.

    The different types of files are: Regular files

    Can be text, data and drawings. Executable ro rams.

    File Characteristics

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    34/184

    [root@localhost root]# ls -l

    total 1872

    -rw-r--r-- 1 root root 1134 Sep 28 12:31 anaconda-ks.cfg

    drwxr-xr-x 3 root root 4096 Oct 3 15:29 Desktop

    drwx------ 8 root root 4096 Oct 3 15:15 evolution

    -rw-r--r-- 1 root root 47186 Sep 28 12:30 install.log

    -rw-r--r-- 1 root root 3436 Sep 28 12:30 install.log.syslogdrwxr-xr-x 3 root root 4096 Oct 1 12:48 intro-linux

    -rw------- 1 root root 1832960 Oct 1 12:42 intro-linux.html.tar

    drwx------ 7 root root 4096 Oct 1 14:45 Mail

    -rw-r--r-- 1 root root 51 Oct 3 12:44 new.txt

    [root@localhost root]#

    File Characteristics

    A file has several characteristics associated

    with it. They can be displayed using the ls lcommand as shown below:

    Contd

    File Characteristics

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    35/184

    File Characteristics

    Example:

    -rw-r--r-- 1 root root 1134 Sep 2812:31 anaconda-ks.cfg0 1 2 3 4 5

    6 7 The explanation of output is as follows:

    File Type regular file d directory l link file c character special file b block special file p pseudo special file Permissions No. Of links to the File

    Contd

    File Characteristics

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    36/184

    File Characteristics

    Owner

    Group

    File Size BytesTime Stamp

    File Name

    What can we do with Files?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    37/184

    What can we do with Files?

    A file is a collection of data, stored on disk

    and that can be manipulated by listing thecontents in the directory, changing thelocations of files and directories, viewingfiles, creating and editing files, moving,copying and deleting files.

    The user can also create directories, change

    directories, delete directories and view PDFfiles.

    A directory is also a file that acts as a folder

    for other files.

    Manipulating files and

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    38/184

    Manipulating files and

    directoriesCopying files

    Copying files and directories is done using the cp command. Thecp command is used to copy the files and directories from the specifiedsource to the specified destination. The user can copy a file into thedirectory, but under a different name.

    Syntax

    cp

    Example: # cp file1 dir1

    Removing files

    The rm command is used to remove single files, rmdir toremove empty directories (Use ls -a to check whether a directory isempty or not). The rm command also has options for removing non-empty directories with all their subdirectories, read the Info pages fordifferent options of rm command.

    Contd

    Manipulating files and

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    39/184

    Manipulating files and

    directoriesMoving and Renaming files

    The mv command is used to move a file from its source to anylocation within the file structure.

    Example of moving a file: # mv file1 /iiht/file1

    Example of moving a file: # mv file1 /iiht/file1

    The above example says, the file file1 is moved to a different directory iiht.

    The mv command is also used to rename a file or a directory

    Example of renaming a directory: # mv iiht dir1

    Contd

    Manipulating files and

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    40/184

    Manipulating files and

    directoriesLinking filesA link is nothing more than a way of matching two or more file names to

    the same set of file data. There are two ways to achieve this:

    Hard link

    Soft link

    Hard link

    Associates two or more file names with the same inode. Hard links sharethe same data blocks on the hard disk, while they continue to behave asindependent files.

    Soft link or symbolic link (or symlink)

    Soft link is a small file that is a pointer to another file. A symbolic linkcontains the path to the target file instead of a physical location on the hard disk.Since inodes are not used in this system, soft links can span across partitions.

    Lab Exercise

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    41/184

    Lab Exercise

    Create a directory by name testand create

    the files file1 file2 and file3, createhardlinkfor file1 to new file data.

    Differentiate deleting hard link files and softlink files.

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    42/184

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    43/184

    File Permission and Access

    Module 6 File Permission

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    44/184

    Module 6 File Permission

    and Access Introduction

    Linux is a multi-user system where users can assigndifferent access permission to their files. Access permissionscan be set per file for owner, group and others on the basisof read (r), write (w) and execute permissions (x).

    Topics File Permissions and Access

    Types of Access

    Who has to Access to a File?

    Access Control Lists

    Contd

    File Permissions and Access

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    45/184

    File Permissions and Access

    Every file is owned by a particular user.

    File permissions specifies who has the access to file andwhat type of access the user has.

    On a Linux system, there is typically more than one userthat provides a mechanism known as file permissions(rwx), which protect user files from accessing by otherusers.

    Types of permissions r read

    w write

    x execute

    Contd

    File Permissions and Access

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    46/184

    File Permissions and Access

    read permission

    The read permission lets a user read the contents of the file.For directories, read permission lets the user list the contents ofthe directory (using ls).

    write permisisonThe write permission lets the user write and modify the file.

    For directories, write permission lets the user create new files ordelete files within the directory.

    execute permissionThe execute permission lets the user run the file as a program

    or shell script (if the file is a program or shell script). Fordirectories, execute permission lets the user open the directory.

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    47/184

    Types of Access

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    48/184

    Types of Access

    Default file permissions

    By default, the Linux system assigns certain permissions to anewly created file. The maximum permissions that we can set for anordinary file is 666 and for directories and an executable files is 777.

    The default file permission for an ordinary user is 664 and for

    root it is 644.

    Displaying the umask

    The default umask file permissions for ordinary users are 002and for root it is 022.

    where, 002 imply masking write permission for others and

    022 implies masking write permission for the group and others.

    Contd

    Types of Access

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    49/184

    Displaying the umask

    To display the default mask use the umaskcommand.

    Example

    # umask

    Displaying the default umask value

    Types of Access

    Contd

    Types of Access

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    50/184

    Changing the umask

    To change the default umask use the command Syntax

    # umask

    Example: umask 004

    Types of Access

    Who has to Access a File?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    51/184

    Access permission user(owner) group

    Who has to Access a File?

    The owner and the root have the main

    access rights over a file.Example

    First column gives the access permissions to theuser, group and others.

    Second column shows the user or owner of thefile.

    Third column shows the group to which the filebelongs.

    Contd

    Who has to Access a File?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    52/184

    Changing permissions

    chmod command

    chmod changes the access permissions accordingto the options for directories and files.

    Syntax

    # chmod o+w

    Who has to Access a File?

    Contd

    Who has to Access a File?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    53/184

    Who has to Access a File?

    The chmod command can be used with

    alphanumeric or numeric options. Example of symbolic method

    chmod u+rw,g-rwx,o-rwx file1 The above example, adds the read and write permission to the

    user (owner) removes the read, write and execute permission

    from the group to which the file belongs and removes the read,write and execute permissions for others.

    Example of numeric method

    # chmod 600 file1 6 indicates user (owner), 0 indicates group and the last number

    0 indicates others.

    Contd

    Who has to Access a File?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    54/184

    Who has to Access a File?

    Changing ownership

    chown command chown changes the owner and group of the file and

    directory.

    Syntax # chown

    Example # chown user1 file1.txt

    Contd

    Who has to Access a File?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    55/184

    Special File Permissions

    There are three types of special file permissions

    set user identity (SUID)

    set group identity (SGID)

    sticky bit

    Who has to Access a File?

    Contd

    Who has to Access a File?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    56/184

    Who has to Access a File?

    Contd

    SUID or setuid

    It is represented by the character s in the user permission

    field.

    When this mode is set on an executable file, the other userscan login and run the executable file.

    The roots id is set to the process.

    Syntax

    #chmod u+s

    where,

    u user

    s - suid

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    57/184

    Who has to Access a File?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    58/184

    Who has to Access a File?

    Sticky bit

    If the sticky bit is set on directory, even others can read andwrite the data to the file, but can not delete the file except theowner.

    Syntax

    #chmod o+t

    where,

    o others

    t - sticky bit

    Example: # chmod o+t /tmp

    Contd

    Access Control Lists (ACLs)

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    59/184

    Access Control Lists (ACLs)

    ACL is an object associated with a file and contains entries

    specifying the access that individual users or groups ofusers have to the file.

    It provides a simple way of granting or denying access for aspecified user or groups of users on single file at the same

    time.

    Using the chmod command the user can set permissions toowner, group or others.

    Using ACL, the owner can set the different permissions on asingle file for different users.

    Contd

    Access Control Lists (ACLs)

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    60/184

    Contd

    Setting ACL using Setfacl

    setfacl - set file access control lists

    Syntax setfacl u::

    Access Control Lists (ACLs)

    Access Control Lists (ACLs)

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    61/184

    Access Control Lists (ACLs)

    Contd

    Getting ACL using getfacl

    The getfacl displays the file name, owner, thegroup, and the Access Control List (ACL).

    Syntax

    # getfacl

    Access Control Lists (ACLs)

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    62/184

    Contd

    o o ( )

    Copying ACL

    The acls can be copied to any files, for which thefiles get the same acl permissions from its sourcefile.

    Syntax

    getfacl | setfacl --set-file= -

    where,

    --set-file options set the acl of a file or a directory

    Lab Exercise

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    63/184

    Change the permission of the following file

    using chmod command.-rwx-rw-r-- file2.txt

    From the following example change thepermissions to

    User read, write, execute

    Group read and execute Others - only execute

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    64/184

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    65/184

    Shell Basics

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    66/184

    What is a Shell?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    67/184

    A shell manages the interaction between the

    system and its users.A shell is a program which takes user input

    (e.g. commands which you type) andtranslates them into instructions that theoperating system can understand.The shell allows the user to handle a system

    in a very flexible way.

    Contd

    What is a Shell?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    68/184

    Contd

    Shell Features

    Command history The command history buffer stores the commands you enter and

    let you display them at any time.

    Command aliases

    The command aliases feature lets you abbreviate long commandlines or rename commands.

    File name completion

    The file name completion feature saves typing by allowing you to

    enter a portion of the file name. When you press the tab/esc key,the shell will complete the file name for you.

    Command line editing

    This allows you to retrieve a previously entered command and editit.

    What is a Shell?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    69/184

    Contd

    Types of shells

    sh or Bourne Shell This is the basic shell, a small program with few features. This

    shell does not support any of the shell features such ashistory, command line completion, command line editing.

    bash or Bourne Again shell The standard GNU shell, intuitive and flexible. bash is the

    standard shell for common users. This shell is a so-calledsuperset of the Bourne shell. This means that the BourneAgain shell is compatible with the Bourne shell: commands

    that work in sh, also work in bash.

    What is a Shell?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    70/184

    Types of shells

    csh or C shell: This shell has a syntax that resembles that of the highly popular C

    programming language and thus preferred by programmers.

    tcsh or Turbo C shell

    This shell is based on csh but also has programmable filenamecompletion, command-line editing, a history mechanism and otherfeatures lacking in csh.

    ksh or the Korn shell:

    This shell is a superset of sh. It also features built-in arithmeticevaluation and advanced scripting capabilities similar to those foundin powerful programming languages such as awk, sed and perl.

    Aliasing

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    71/184

    Contd

    g

    The command aliases allow the user to abbreviate long

    command lines with small names easy to use and type.

    Creating Aliases

    To create aliases, use the alias command. The format of the aliascommand is:

    Syntax

    alias aliasname=command

    The aliasname entry specifies the name you want to use.

    The alias helps for alternate names for complicated commands.

    Example:

    [root@localhost root]# alias cls=clear

    [root@localhost root]# cls

    Aliasing

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    72/184

    Display Aliases

    To display alias definitions, enter the followingcommand:

    # alias

    Remove Aliases To remove an alias for the current login session,

    use the unalias command.

    The general format of the unalias command is the

    following: unalias

    g

    File Name Completion

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    73/184

    File name completion is one of the most useful features of

    the Linux command line.

    The shell lets you enter a portion of a file name orpathname at the shell prompt and the shell automaticallywill match and complete the name.

    Example # vi us Press Enter

    Then the entire file name will be completed as follows if itis unique name,

    # vi user123.filnename.txt

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    74/184

    User profiles

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    75/184

    The user profile is a personalized settings of the user

    and the shell script and gets executed whenever theuser logins.

    The profile can be classified into:

    System wide

    The changes to system wide profile will effect the workenvironment of all users. These files are available in /etc.

    User Specific

    User specific profiles effect the work environment of only

    that particular user and it stores in the home directory of each user.

    What Happens At Login

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    76/184

    When a user logs into a system it executes the

    start up scripts in the following sequence:/etc/profile sets the environmental variables andsettings for all users.

    /etc/profile.d. runs the login script for all users.

    ~/.bash_profile - sets the environmental variables andsettings for particular user.

    ~/.bashrc - runs the login script for particular user.

    /etc/bashrc - sets the environmental variables for bashshell.

    Variables

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    77/184

    A variable is a label that has a value.

    Variables are used to configure the shell.

    To set a variable in the shell, use an equal sign toassign it a value. If the variable does not already exist,

    it is created.

    Example A new variable is defined as follows: $ MYVARIABLE=hello

    To display the value of a variable, prefix the variablesname with a $ symbol.

    Contd

    Variables

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    78/184

    Types of Variables

    There are two types of variables Shell variables or local variables

    Environment variables

    Shell variables or local variables are available only to the currentshell which is used to configure shell.

    Environment variables are available to all shells and used toconfigure other commands. e keyboard arrows. To move up anddown in the history command shell. It helps to change the mainvariables like prompt settings, color settings by changing within theprofile to make effect for the entire settings.

    Contd

    Variables

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    79/184

    Display variable

    set command is used to display the local andenvironment variables in a system.

    env command is used to display onlyenvironmental variable.

    There are two commonly used Variables Local variables

    Environment variables

    Contd

    Variables

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    80/184

    Local variables

    HISTFILESIZE - specifies the number of commands ofhistory to be saved when the shell exit.

    COLUMNS- sets the width of the terminal.

    LINES- sets the height of the terminal.

    Environment variables HOME- path to the user home directory.

    LANG- sets default language.

    PWD- present working directory.

    PATH- the path for the command locations. These variables are stored in the profile file (.bashrc).

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    81/184

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    82/184

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    83/184

    Module 8 Shell Advanced

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    84/184

    FeaturesIntroduction

    In Linux systems, the shells are often referredto as command line interfaces. The shell capabilitiesprovide a configurable environment allowing the usersto modify commands and prompts.

    Topics Shell Substitution Capabilities

    Setting Shell Variables

    Quoting Characters File Name Generationss

    Shell Substitution Capabilities

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    85/184

    Substitution capabilities are used to speed

    up command line typing and execution.

    The shell substitutions are of three types:

    Variable Substitution

    Command substitution

    Tilde Substitution

    Contd

    Shell Substitution Capabilities

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    86/184

    Variable Substitution

    Variable substitution is assigning the absolute pathof a file or directory to any variable. This allowsthe user to access the directory or file fromanywhere in the file hierarchy.

    Syntax: =$

    Example: myfile=$HOME/file1

    Contd

    Shell Substitution Capabilities

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    87/184

    Command substitution

    Command substitution is the mechanism used toreplace a command with its output, within thesame command line.

    Syntax: =$(command)

    Example: mydir=$ (pwd)

    Contd

    Shell Substitution Capabilities

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    88/184

    Tilde Substitution

    A tilde is replaced for the quick reference ofhome directory.

    Syntax: ~

    Example: ls ~

    Setting Shell Variables

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    89/184

    The new variable can be created and assigned to an

    existing environmental variable such as path.

    The new value replaces the old value in theenvironment and the same can be displayed by

    using the display value commands.Syntax

    =

    Example

    myfile_name=/root/file1

    Contd

    Setting Shell Variables

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    90/184

    Displaying variable values

    The variables can be displayed by using $.

    It can be local variable (assigned by the user) or

    environmental variable (default variable). All setting variables can be displayed by using thecommand set.

    Quoting Characters

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    91/184

    There are some characters in the Unix system and

    each has the meaning for the shell and is called asspecial characters. The special characters are:

    -

    $

    #

    *

    < >

    Quoting removes the special meaning of the above

    characters. The quoting characters are: \ Backslash

    Single quotes

    Double quotes Contd

    Quoting Characters

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    92/184

    Contd

    Backslash ( \ )

    Backslash removes the special meaning of thecharacter immediately following the backslash.

    Quoting Characters

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    93/184

    Single quotes ( )

    The single quote is used to preserve the literalvalue of special character enclosed within the quotes.

    Contd

    Quoting Characters

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    94/184

    Double quotes ( )

    Double quotes removes the special meaning ofall the characters except \ , $ (variable name), $(command).

    File Name Generation

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    95/184

    The file name generation has the timesaving feature for

    typing the filenames. This feature is called file name

    generation or filename expansion.

    Advantages of file name generation

    File name generating characters are interpreted by the shell.

    The command operates on the generated file names. The shell will generate file names that satisfy the requested pattern.

    File name generation is done before the command is executed.

    The special characters that are interpreted by the shell forfile name generation are: ? Matches any single character except a leading dot

    * Matches zero or more characters except a leading dot

    Contd

    File Name Generation

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    96/184

    Usage of the special character ?

    Contd

    File Name Generation

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    97/184

    Usage of the special character *

    Lab Exercise

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    98/184

    Give one example on usage of single quotes

    command with the variable substitution

    Display the files which has 9 characters andwith the extension .jpg

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    99/184

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    100/184

    Input and Output Redirection

    Module 9 Input and OutputRedirection

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    101/184

    Redirection Introduction

    One important thing you have to know to understand I/O

    redirection is file descriptors. There are three types of I/O, calleda file descriptor. They are standard input, standard output,standard error.

    Topics Input Redirection

    Output Redirection

    Error Redirection

    Filter

    Pipes

    Input Redirection

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    102/184

    The standard input (stdin) by default is any text

    entered from the keyboard.

    Standard input can be redirected through the use ofcommand line argument and redirection operators (like

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    103/184

    Output Redirection

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    104/184

    The default standard output (stdout) is the display

    screen.

    The command line programs automatically send theiroutput to the screen.

    Standard output can be redirected through the use ofcommand line argument and redirection operators (like>).

    The standard output can be redirected from the screento any file or to the printer.

    Contd

    Output Redirection

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    105/184

    Example of output redirection

    # ls > list.file

    Syntax# command > (file name

    Error Redirection

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    106/184

    By default the standard error (stderr) displays on

    the terminal and can be redirected into a file,printer and any other program.

    Standard error can be redirected with the

    standard error redirection operator (i.e 2>, 2>>).

    The error messages can be redirected to any file,so that the error messages will not appear on the

    screen and it is written to the file.

    Contd

    Error Redirection

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    107/184

    Example of error redirection

    # ll myfile 2>error_message

    Syntaxcommand (filename) 2> (filename)

    Common RedirectionOperators

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    108/184

    Operators There are two common redirection operators

    >

    >>

    > operator sends the input of command or file to theother file as standard input, overwriting the existingfile.

    > > operator sends the input of command or file to the

    other file as standard input, appending text to anexisting file, instead of overwriting the file.

    Contd

    Common RedirectionOperators

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    109/184

    OperatorsUsage of > operator

    Syntax# cat > (filename)

    Contd

    Common RedirectionOperators

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    110/184

    Contd

    Usage of the >> operatorOperators

    Filters

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    111/184

    Filters take standard input and perform an operation upon it andsend the results to standard output.

    Example for filters: grep root /etc/passwd

    The grep command is used to filter the root user from the /etc/passwd

    file.

    Pipes

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    112/184

    A pipe is a mechanism for interprocess communication.

    The data written to the pipe by one process can be readby another process. It is handled in a first-in, first-out(FIFO) order.

    Pipes ( | ) let you redirected output from one commandto become input to another command.

    Example: simple pipe with morels -l | more

    Contd

    Pipes

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    113/184

    The tee command

    The tee command copies the standard input to standard outputand also to any files given with an argument.

    This is useful when you want not only to send some data down apipe, but also to save a copy.

    If a file being written which does not already exist, it is created.

    If a file being written which already exists, the data contained isoverwritten unless the -a option (appends the standard input to

    the given files rather than overwriting)

    Contd

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    114/184

    Lab Exercise

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    115/184

    Filter and display the word blue from the file

    my_sortfile

    Sort and redirect the data from one file toanother

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    116/184

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    117/184

    Networking in Linux

    Networking in Linux

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    118/184

    IntroductionA computer network is defined as a number of systems that

    are connected to each other and exchange information across thenetwork connection. The system network is configured by settingthe IP address which is assigned by the system administrator.The IP address provides base services for transmitting databetween networks in TCP/IP (Transmission control

    protocol/Internet protocol).

    Topics

    Network Connectivity

    IP address Accessing Remote system

    Transferring files

    Internet configuration

    Networking in Linux

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    119/184

    The Linux system can be connected to the network with the helpof network hardware.

    Network hardware can be LAN (Local area network) card, cables,hub/switch or router. To configure the network for the system,TCP/IP (Transmission Control Protocol/Internet Protocol) addressis required from the system administrator.

    The IP address can also be obtained from the DHCP (Dynamichost configuration protocol) server configured by the systemadministrator.

    When the system is connected to the network, the resources canbe shared and data can be transferred among the systems.

    The LAN services (telnet, SSH - Secure Shell, FTP File transferprotocol) enables the file transfer and remote login to the system.

    IP Address

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    120/184

    An IP address is a 32 bit binary number usuallyrepresented as 4 decimal values, each representing 8

    bits, in the range 0 to 255 (known as octets) separatedby decimal points.

    Every system in network is assigned a uniqueidentifying number called IP address.

    It is used in order to identify and communicate withdifferent systems present in the network.

    The data is sent across the network and contains a

    source and destination IP address.

    Example:

    10.10.1.240

    130.130.1.10

    192.168.1.200

    IP Address

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    121/184

    Configuring IP address

    The system can be a part of network byconfiguring the IP address. The IP address can be setby two options in CUI mode and GUI mode.

    Static IP

    Dynamic IP (DHCP)

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    122/184

    IP Address

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    123/184

    Static IP address in CUI mode

    Configuration of the static IP address

    Syntax

    Type the command # netconfig (Press Enterkey) at the command prompt in the terminal window.

    IP Address

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    124/184

    network service

    Syntax# service network restart

    IP Address

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    125/184

    # ifconfig

    IP Address

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    126/184

    # ping

    IP Address

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    127/184

    Dynamic IP address in CUI mode

    Configuration of the dynamic IP address

    Syntax

    # netconfig (Press Enter key)

    IP Address

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    128/184

    Static IP address in GUI mode

    Network configuration in static IP

    IP Address

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    129/184

    Dynamic IP address in GUI mode

    DHCP settings

    IP Address

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    130/184

    Host NameA hostname is the unique name assigned to each host

    on the network. The hostname is used to identify a particularIP address. Hostnames are used by various naming systemslike telnet, ssh, FTP, GFTP, NIS and DNS.

    There are three ways to resolve host names to IPaddresses on a Linux system:

    /etc/hosts

    DNS (Domain name service)

    NIS (Network information service)

    Contd

    IP Address

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    131/184

    etc/hosts is a configuration file maintained locally on each hostto resolve hostnames to IP addresses. On a small network, it is

    easy to maintain the name resolution of hostnames toaddresses. When adding or removing hosts, or reassigning IPaddresses, the user have to update the /etc/hosts file.

    DNS (Domain name service) will resolve the host names into

    IP addresses in a large network.

    NIS (Network information service) provides a central point ofadministration for common configuration files like /etc/passwd,

    /etc/hosts. It preserves the consistency of the configuration

    files across all the systems on the network. It simplifiesconfiguration file updates considerably.

    Accessing Remote System

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    132/184

    Systems in the network can be accessed remotely withhelp of network connectivity and using IP addresses in

    two ways:

    Telnet

    SSH

    Telnet

    Telnet is a terminal program for TCP/IP networks such as the Internet.

    The telnet program runs on your computer and connects your system tothe other system present in the network.

    To start a telnet session, you must log in to other system by entering avalid username and password of the other system.

    Contd

    Accessing Remote System

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    133/184

    Contd

    telnet session

    Syntax# telnet

    Accessing Remote System

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    134/184

    SSHSSH is a program for logging into a remote machine and

    for executing commands on a remote machine

    The root user can login through SSH and execute thesystem administrative command.

    ssh command

    Syntaxssh

    Transferring files

    Files can be transferred among various systems in

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    135/184

    Files can be transferred among various systems inthe network by using FTP, GFTP and SCP (secure

    copy). FTP FTP (File transfer protocol) is a program that allows you to

    transfer the files between computers present in the network. Itcan also transfer the files among different operating systems.

    Example: Linux to Linux, Linux to Windows, Windows to Linux.

    Syntax

    # lftp

    Transferring files

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    136/184

    GFTP

    GFTP (Graphical file transfer protocol) is the toolused for uploading and downloading the files in agraphical mode.

    GFTP (Graphical file transfer protocol)session

    Contd

    Transferring files

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    137/184

    SCP (secure copy)

    The scp command is used to copy the files fromother system present in network.

    Syntax

    # scp :

    Example: scp file1 192.168.1.171:/root

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    138/184

    Internet configuration

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    139/184

    Step 2: Proxy configuration

    Contd

    Internet configuration

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    140/184

    Step 3: Setting the proxy IP and the port

    number

    Contd

    Internet configuration

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    141/184

    Contd

    Step 4: Verifying the Internet connectivity

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    142/184

    Internet configuration

    C i i h h d

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    143/184

    Connection to internet through modem

    Lab Exercise

    H t fi th IP dd i CUI d ? A

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    144/184

    How to configure the IP address in CUI mode? Assumethat your system administrator or lab in-charge has given

    you the IP Address as 192.168.1.60?

    Check your system to be a part of network andcommunicate with other systems present in the work

    Configure your system with Dynamic IP Address usingDHCP

    Name the command to copy the files among the system

    in the network with out using ftp?

    Name the command to copy the files among the systemin the network with out using ftp?

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    145/184

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    146/184

    Process Control

    Module 11 Process Control

    I t d ti

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    147/184

    Introduction A process is a running occurrence of a program,including all variables and other conditions. It is anexecuting program.

    Each process contains a system wide unique processnumber (PID- Process Identification).

    Topics Identifying Process

    Managing Process

    Background Processing Putting Jobs in Background

    The operating system will execute the processes by

    Identifying Process

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    148/184

    The operating system will execute the processes bydefault and the user can also create a process.

    The process can be identified which is in executionalong with its PID (process identification number).

    Process creation

    Processes are created with the fork system call (theoperation of creating a new process is called forking).

    Example: vi

    Contd

    Vi i th i i

    Identifying Process

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    149/184

    Viewing the process origin

    The pstree command is used to display theprocess origin.

    Contd

    Identifying Process

    Vie ing the c ent p ocess

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    150/184

    Viewing the current process

    The ps command is one of the tools for visualizingprocesses. It displays the current working shell. Sinceps command does not give detailed information aboutthe process, the grep command in a pipe is used toselect a particular process out of the list of all

    processes.

    The bg command is used to check and

    Managing Process

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    151/184

    The bg command is used to check and

    move a job to background

    Contd

    Example for foreground

    Managing Process

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    152/184

    Example for foreground

    Contd

    Managing Process

    Process Scheduling

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    153/184

    Process Scheduling

    The Linux kernel uses a process scheduler to decide which process

    has to be executed first. It is done by using process priority.

    Scheduling Priorities

    Every process has a scheduling priority. The operating systemdetermines the priority of a process based on nice value method.

    To calculate this priority is difficult, but users can affect the priorityby setting the nice value. The niceness value is the numberranging from -20 (highest priority) to 19 (lowest priority) It has adefault value of zero. Process with a high priority gets to run moreoften, while the low priority background tasks, run less frequently.

    Contd

    Priorities for programs

    Managing Process

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    154/184

    Priorities for programs

    The nice values of active processes can be viewed using

    the ps command with the l or f option for long output.

    Example for nice command:

    The nice command is used to modify the default niceness

    value. To set the niceness value to a different value, usethe n option:

    Example:

    Contd

    Showing priorities of different process

    Managing Process

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    155/184

    Contd

    Showing priorities of different process

    Managing Process

    Usage of top command

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    156/184

    Contd

    Usage of top command

    The top program displays all the system and usersprocess priorities running in all the terminals.

    The process running on your system is updated once inevery five seconds.

    A process in the running state is highlighted.

    Managing Process

    Altering priorities of running programs

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    157/184

    Contd

    Altering priorities of running programs

    The users can reduce the priority of currentlyrunning jobs using the renice command. Only thesuperuser is permitted to move up the priority ofcurrently running processes.

    Example of renice command

    Managing Process

    Terminating the process

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    158/184

    Contd

    Terminating the process

    The process is terminated when it receives asignal.

    There are multiple signals that the user can send

    to a process. The kill command is used to send a signal to aprocess.

    The command kill -l shows a list of signals which

    the user wants to terminate.

    killall command will perform an orderly

    Managing Process

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    159/184

    Contd

    killall command will perform an orderly

    shutdown of the process.

    killing a process

    Managing Process

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    160/184

    killing a process

    Background Processing

    A background process is the child of the process.

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    161/184

    A background process is the child of the process.

    It refers to processes that are run with a relatively low priority,require little or no input, and produce a minimum of output.

    The background is also used for long tasks that requiremassive amount of computation and thus CPU time.

    Daemon (Disk and execution Monitor)

    A daemon is a background process that is considered to runindependently, with little or no user interference.

    Example: Apache web server http daemon (httpd)

    Putting Jobs in Background

    The shell offers a feature called job control which allows

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    162/184

    The shell offers a feature called job control which allowseasy handling of multiple processes. This mechanism

    switches processes between the foreground and thebackground. Using this system, programs can also bestarted in the background immediately.

    putting jobs in background

    jobs command is used to verify the background process

    Contd

    Putting Jobs in Background

    Suspending a process

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    163/184

    Suspending a process

    A process can be suspended temporarily withoutbeing killed. Suppose that & symbol is missed outby mistake, use ^z and the process will besuspended.

    The process still exists but is idling. To resume theprocess in the background type the bg command(background).

    Lab Exercise

    Create a process viwith filename and send the process to

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    164/184

    p pbackground and check background process

    Check the background running process and bring it to the foreground

    How to send running process to the background and bring it back tothe foreground?

    Start a Process using find command with the priority of -18

    Display and manage the priorities with the single command

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    165/184

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    166/184

    Offline File Storage

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    167/184

    Storage files to Media

    Backing up of a system is the most major task to be

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    168/184

    g p y jperformed by a system administrator.

    Computers have the major advantage of storing thedata, which makes it significant.

    Backups are important because of the possibility ofloss of data.

    The possibility of data loss can be by:

    File system corruption

    Accidental removal of files

    Hardware failures

    System crashContd

    Backup Media

    Storage files to Media

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    169/184

    Contd

    p

    The following are some of the methods of back up through

    media floppy disks

    Tapes

    removable hard disks

    rewritable CD-ROMs

    Backup tools

    tar

    dd

    Dump cpio

    Storage files to Media

    Backup using tar command

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    170/184

    Contd

    An archiving program designed to store and extract files from an

    archive file known as a tarfile. The tar is the most commonly usedcommand for the backup.

    tar options

    tar cvf (creating the tar file)

    tar tvf (listing the contents of tar file)

    tar xvf (extracting the contents of tar file)

    where,

    c create

    t list

    x extract

    v verbose

    f file

    Backup using dd command

    Storage files to Media

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    171/184

    Contd

    p g

    dd copies a file from source to destination. It copies aninput file (if) file and sends the result to the output file (of) whichconverts and formats according to the options.

    Syntax

    # dd if= of=

    Exampledd if=bootdisk.img of=/dev/fd0

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    172/184

    Storage files to Media

    Example:

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    173/184

    Contd

    a pdump -0 f /home_dumps/mydumps /home

    where,-0 - dump level (full backup)

    -f - write a backup to file

    Storage files to Media

    Backup using restore command

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    174/184

    Contd

    The restore command is used to view and restore the dumpfile.

    Syntax:# restore -

    Example: restore if mydumps

    where,

    -i is interactive restoration

    -f is read backup from file

    Backup using cpio command

    Storage files to Media

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    175/184

    Contd

    p g p

    The cpio command is a tool for creating and extractingarchives, or copying files from one place to another,which contains other files and information about them,such as their file name, owner, timestamps, and access

    permissions.

    It handles a number of cpio formats as well as readingand writing tar files. The archive can be another file on

    the disk, a magnetic tape, or a pipe.

    cpio has three operating modes.

    Storage files to Media

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    176/184

    Contd

    copy-out mode, cpio copies files into an archive.

    copy-in mode, cpio copies files out of an archive or liststhe archive contents.

    copy-pass mode, cpio copies files from one directorytree to another, combining the copy-out and copy-in

    steps without actually using an archive.

    Syntax for creating the cpio file

    Storage files to Media

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    177/184

    Contd

    find (source file name) | cpio (options) > (target file name)

    Example: find file1 | cpio -o > file1_back.cpio

    Syntax for extracting the cpio file

    cat | cpio (options)

    Example:

    cat file1_back.cpio | cpio idvm

    where,

    d make directories

    i extract m modification time

    o create

    v verbose

    Storage files to Media

    Compression tools

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    178/184

    Contd

    Zipzip is a compression and file packaging utility. The program is

    useful for packaging a set of files for distribution, archiving files andsaving disk space by temporarily compressing unused files ordirectories. The zip program puts one or more compressed files into asingle zip archive, along with information about the files. An entiredirectory structure can be packed into a zip archive with a singlecommand.

    Syntaxzip

    Example:zip install install.log

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    179/184

    Storage files to Media

    Gzip

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    180/184

    Contd

    By default, gzip keeps the original file name and

    timestamp in the compressed file. These are used whendecompressing the file with the N option. The mainadvantage of gzip over compress is it has a better

    compression capacity than other compression tools.

    Syntax

    gzip

    Example

    gzip install.log

    Gunzipd h f l d b k l

    Storage files to Media

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    181/184

    Contd

    gunzip decompress the files created by gzip. It takes a list

    of files on its command line and replaces each file ending with.gz, -gz, .z, -z, _z or .Z and which begins with the correctnumber with an uncompressed file without the originalextension. gunzip also recognizes the special extensions .tgz and.taz as shortcuts for .tar.gz and .tar.Z respectively.

    Syntax

    gunzip

    Example: gunzip install.log.gz

    Storage files to Media

    Bzip2b i 2 i bl k ti fil It t li t f fil

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    182/184

    Contd

    bzip2 is a block-sorting file compressor. It expects a list of file

    names to accompany the command-line tools. Each file is replacedby a compressed version of itself, with the nameoriginal_name.bz2. Each compressed file has the same modificationdate, permissions and when possible ownership as the correspondingoriginal, so that these properties can be correctly restored atdecompression time.

    Syntaxbzip2

    Example:bzip2 install.log

    Storage files to Media

    Bunzip2bunzip2 (or bzip2 d) decompresses all specified files bzip2

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    183/184

    bunzip2 (or bzip2 -d) decompresses all specified files. bzip2

    attempts to guess the filename for the decompressed file from that ofthe compressed file. If the file does not end in one of the recognizedendings, .bz2, .bz, .tbz2 or .tbz, bzip2 gives an error message that itcannot guess the name of the original file, and uses the original namewith .out.

    Syntaxbunzip

    Example:

    bunzip install.log.bz2

    Backup any desired directory using tar command

    Lab Exercise

  • 8/6/2019 Rootsan Technologies Pvt Ltd Linux Modul033

    184/184

    Compress the file mydata from the data directoryand uncompress into a new directory by name

    backup usingzip and unzip commands

    Backup the /tmp directory into a new directory byname tmp_backup using dump command