introduction to linux1

Upload: kamar

Post on 03-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Introduction to Linux1

    1/49

    Lab 1

    INTRODUCTION

    TO

    LINUX

  • 7/28/2019 Introduction to Linux1

    2/49

    What is Computer

    A computer is an electronic device that

    accepts information in the form ofdigitalized data and manipulates it for some

    result based on a program or sequence of

    instructions on how the data is to beprocessed.

  • 7/28/2019 Introduction to Linux1

    3/49

    The Computer is a programmable finite

    state machine which can perform precise

    arithmetic and logical operations.

    A programmable finite state machine is

    one that can take a fixed range of values.The computer is called programmable

    because it can be instructed to perform

    tasks within its capacity.

  • 7/28/2019 Introduction to Linux1

    4/49

    Computer System

    Hardware Software Livewire(User)

    Computer System

  • 7/28/2019 Introduction to Linux1

    5/49

    HARDWARE

    The physical circuitry and components areknown as hardware.

    The hardware is categorized into five blocks.

    Namely

    Input Unit

    Arithmetic Logic Unit(ALU)Control Unit

    Memory

    Output Unit

  • 7/28/2019 Introduction to Linux1

    6/49

    CRT Display

    Keyboard

    Mouse

    The Box

    CD-ROMDrive

    Floppy

    Disk

    Drive

  • 7/28/2019 Introduction to Linux1

    7/49

    Software

    Application Software System Software

    Software

  • 7/28/2019 Introduction to Linux1

    8/49

    What is a System Software?A computer program that controls the system hardware

    system and interacts with application software;

    Example- operating system.What is an Application Software?Application software (sometimes shortened toapplication) is any program designed to perform a

    specific function directly for the user or, in some cases,

    for another application program. Typical types of

    application software include: Word processing,Electronic spreadsheet, Database, Email reader, Web

    browser, Graphics software and so on.

  • 7/28/2019 Introduction to Linux1

    9/49

    Operating System?

    It is a set of programs that act as an interfacebetween the user and the hardware.

    It is a system software that lies between

    computer hardware (disk, Memory, Processoretc.) and the Application programs (WordProcessors, Web Browsers, spread Sheetsetc.)

    It controls and co-ordinate the operation of acomputer system.

  • 7/28/2019 Introduction to Linux1

    10/49

    What OS does?

    It loads itself into the memory-Booting.

    It loads the user program in the memory.

    It loads the data required by the program in thememory.

    Interprets the program instruction one at a time.

    Sends instruction to the output device to display

    the result on the screen. Uses the resources like memory, input and

    output devices properly and efficiently.

  • 7/28/2019 Introduction to Linux1

    11/49

    Major OS Functions

    User Interface

    Job/Task Management

    Data Management

    Device Management

    Security

  • 7/28/2019 Introduction to Linux1

    12/49

    Types of OS

    Single User OS

    Multi User OS

    Multi Tasking OS Multi Processing

    Real Time OS

  • 7/28/2019 Introduction to Linux1

    13/49

    Linux OS

    Linux is a free Unix-like operatingsystem Developed under the GNUGeneral Public License

    It is a multi-user, multitasking OS withsupport for Networking

    The source code for Linux is freelyavailable to everyone.

  • 7/28/2019 Introduction to Linux1

    14/49

    History of Development!

    The development of Linux started fromUNIX.

    UNIX is a trade mark of AT & T,originally developed by Ken Thompson,

    Dennis Ritchie and others back in 1970srunning on mainframes andmicrocomputers.

    It is a multitasking and multi user OS.

    Unix is mostly used in servers and webservers.

    It is written with C language

    It is a foundation for many OS like Linux,Novell etc. Ken Thompson, 1943

    Dennis Ritchie, 1941

  • 7/28/2019 Introduction to Linux1

    15/49

    History continues

    Linux OS uses Unix as the base and gives

    further more facilities and applications.

    It was first released by its inventor LinusTorvalds in 1991.

    In Linux GUI is made having Unix as its

    core.

    Linux is the ultimate Unix.

  • 7/28/2019 Introduction to Linux1

    16/49

    History continues

    Many vendors purchased the source code andhave developed their own versions.

    IBM, HP, Sun etc.

    The source code was also made free to collegesand universities.

    UC Berkeley, and MIT have been on the front edge of

    development since the beginning. As a lot of variations are appeared in various

    versions, IEEE comes with a standard POSIX.1(Portable Operating System Interface for UNIX).

  • 7/28/2019 Introduction to Linux1

    17/49

    Linux Came into Picture!!!

    The down side of UNIX is that it is proprietary big and

    expensive, especially for PC version.

    This is where Linux comes in.

    It was designed to be small, fast and inexpensive with

    every functionality available.

    Originally created by Linus Tovalds of university of

    Helsinki, Finlald in 1991 using no code from AT & T. But partially from scratch and partially from using publicly

    available PC based implementation of UNIX called

    MINIX.

  • 7/28/2019 Introduction to Linux1

    18/49

    Linux released!!! Finally Towards the end of 1991

    Linux was made public and in Nov.

    1991 version 0.10 was released.

    In Dec 1991 version 0.11 wasreleased.

    At the same time Torvalds made

    source code free on the Internet and

    asked to work with it.

    Today's version of Linux is 2.6.12.x.

    and freely downloadable from

    www.kernel.org.

    The Big Boss!

    Linus Torvalds,

    1969

  • 7/28/2019 Introduction to Linux1

    19/49

    Linux Distributions

    Several Companies and Organizations began

    gathering and packaging Linux software together

    in to useable forms called distributions Now there are almost more than 350

    distributions available around the world!

    The most popular distributions areRed Hat, SuSe, Debian, Slackware, Mandrake etc.

  • 7/28/2019 Introduction to Linux1

    20/49

    Features of LINUX

    Multi-user Multiple users can logged into and work on the system at the

    same time.

    Each user will have their own private area in the system where

    they can customize their environments for use.

    Multitasking

    Can have many programs running at the same time for the user

    Also Linux runs many of the system processes in the background

    called Daemon processes, which remain ready for ever to serve

    the request of a user. Graphical User Interface.

    Hardware Support

    Linux supports all most all well known hardware.

    Networking Support

  • 7/28/2019 Introduction to Linux1

    21/49

    Advantages!

    Documentations like books, tutorials are freely

    available for download in the web.

    Also a project called Linux Documentation

    project provides free materials

    www.tldp.org

    Help is available by professionals around theworld round the clock.

  • 7/28/2019 Introduction to Linux1

    22/49

    Linux Commands

  • 7/28/2019 Introduction to Linux1

    23/49

    What is a Command?

    A command is an instruction telling acomputer to do something.

    A command is an instruction to

    perform a task in operating system

  • 7/28/2019 Introduction to Linux1

    24/49

    Linux Commands

    A command prompt looks like

    [cs0203@linuxserver cpp]$

    cs0203: user name linuxserver: machine name

    cpp: current working directory

  • 7/28/2019 Introduction to Linux1

    25/49

    Guidelines

    All commands must always be entered in smallcase letters

    Between command name and the options theremust be a space

    The options are usually preceded by a - sign

    Two or more options may be combined like

    lsa -l as lsal

    To repeat a command up-down arrow keys may beused

  • 7/28/2019 Introduction to Linux1

    26/49

    Basic Linux Commands dateprints current date and time

    Syntax:[cs0203@linuxserver cpp]$ date

    O/P: Tue Nov 22 15:24:12 IST 2005

    cal

    Prints calander of current year Syntax:

    [cs0203@linuxserver cpp]$cal 11 2005

    O/P: November 2005

    Su Mo Tu We Th Fr Sa1 2 3 4 5

    6 7 8 9 10 11 12

    13 14 15 16 17 18 19

    20 21 22 23 24 25 26

  • 7/28/2019 Introduction to Linux1

    27/49

    Basic Linux Commands

    who (who am i) Displays the users logged in to the system

    Syntax

    [cs0203@linuxserver cpp]$who

    O/P:ee05183 pts/278 Nov 22 15:23 (192.168.5.8)

    et05428 pts/286 Nov 22 15:29 (192.168.5.9)

    ee05410 pts/285 Nov 22 15:29 (192.168.5.10)

    pwd Displays present working directory

    Syntax:

    [cs0203@linuxserver cpp]$pwd

    O/P: /home/cs0230/cpp

  • 7/28/2019 Introduction to Linux1

    28/49

    Basic Linux Commands

    ls Lists files and folders of current directory

    O/P:

    squid.conf fontforge-20040529-1.i386.rpm squid.newsquid.conf golden collection mukeshpics

    squidGuard.log indlinuxtcp ls -l

    Long listing of files and folders of current directory

    O/P:

    -rw-r--r-- 1 cs01 cs01 2474 Oct 1 17:25 maze.cpp

    drwxrwxr-x 4 cs01 cs01 4096 Oct 25 11:19 linux

    lsal

    List all files in the current working directory in long listing formatshowing permissions, ownership, size, and time and date stamp

  • 7/28/2019 Introduction to Linux1

    29/49

    Getting Help

    man

    Displays the system manual

    Command man displays information on man

    Syntax :

    [cs0203@linuxserver cpp]$man ls

    info

    Displays information in a different format

    Command info displays information on man

    Syntax:

    [cs0203@linuxserver cpp]$info date

  • 7/28/2019 Introduction to Linux1

    30/49

    What is a File?Any named collection of information stored on a disk.

    Application programs and documents are examples of

    files. You make a file when you create information (such

    as text or graphics) using a program, give the material a

    name and save it on a disk.

    What is a Directory?It is a special kind of file that points to or contains

    others files and directories. Directories can benested to any depth. Some software may refer to

    directories and subdirectories by other names, such

    as, folders, lockers, file drawer, etc.

  • 7/28/2019 Introduction to Linux1

    31/49

    Creating a file touch

    Creates an empty file Syntax:

    [cs0203@linuxserver cpp]$touch test.txt

    cat Used to create and display a file.

    cat : displays file contentsSyntax:[cs0203@linuxserver cpp]$cat firstfile.txt

    cat > : creates a file and save with ctrl+d

    Syntax:[cs0203@linuxserver cpp]$cat > firstfile.txt

    cat file1 file2 > file3 : concatenates contents of files file1 & file2 & storeit in file3(if it is not exist then newly created otherwise content of file3 is

    overridden)Syntax:[cs0203@linuxserver cpp]$cat file1 file2 > file3

    Cat file1 file2 >> file3 :concatenates content of files ,if file3 exist&contents some information then new content is appended.

    Syntax:[cs0203@cat file1 file2 >>file3

  • 7/28/2019 Introduction to Linux1

    32/49

    File related commands

    mkdir

    To create directory(s)

    Syntax:

    [cs0203@linuxserver cpp]$mkdir silicon cd

    To change directory

    Syntax:

    [cs0203@linuxserver cpp]$cd silicon file

    Display file type

    Syntax:

    [cs0203@linuxserver cpp]$file firstfile

  • 7/28/2019 Introduction to Linux1

    33/49

    What is Path?Path is the specification of a file or directory in a hierarchical file

    system using pathname separators ("/" in Unix)between

    directories. The pathname tells the shell where in the directorytree to find a file. Files may be referred to by absolute pathname(also called full or complete pathname) orrelative pathname.Absolute path is a path relative to the root directory, the topmostnode of a hierarchical file system. Its first character must be a

    pathname separator, e.g., the Unix forward slash . absolute

    pathname is the full specification of a path beginning with the root

    directory and including all directory levels the system passes

    through to locate the file.relative pathname is the location of the file or directory relative tothe directory in which the user is currently located (the current

    working directory).

  • 7/28/2019 Introduction to Linux1

    34/49

    File commands contd. cp

    Copies srcfile to destfile If destination file is present then overwrites

    Else creates a new file with name destfile

    Syntax:

    [cs0203@linuxserver cpp]$cp test.c test1.c

    clear

    Clears the screen

    Syntax:

    [cs0203@linuxserver cpp]$clear shutdown

    Shuts the system down.

    Syntax:

    [cs0203@linuxserver cpp]$shutdown

    File commands contd

  • 7/28/2019 Introduction to Linux1

    35/49

    File commands contd. mv

    moves/renames a file or directory

    mv : renaming

    mv : moves to path directory

    mv : moves with renaming

    Syntax:

    [cs0203@linuxserver cpp]$mv test.txt test1.c

    rm

    Removes/deletes a file

    Syntax:

    [cs0203@linuxserver cpp]$rm test.c rmdir

    Removes/deletes an empty directory

    Syntax:

    [cs0203@linuxserver cpp]$rmdir cpp

  • 7/28/2019 Introduction to Linux1

    36/49

    Some VI Commands

  • 7/28/2019 Introduction to Linux1

    37/49

    vi is a screen-oriented text editor written by Bill Joy in 1976 .The name vi is derived from the shortest unambiguous

    abbreviation for the command visual in ex.

    vi editor works in 3 different modes

    >> Command Mode

    >> Insert Mode

    >> Last Line Mode

    INTRODUCTION TO VI EDITOR

  • 7/28/2019 Introduction to Linux1

    38/49

    :Insert Mode

    Command Mode

    Last Line Mode

    i, I, o, O, a, A

    EscEsc or Enter

  • 7/28/2019 Introduction to Linux1

    39/49

    [cs0203@linuxserver cpp]$vi

    e.g [cs0203@linuxserver cpp]$vi firstcprog.cIf the file firstcprog.c exists then this command open the fileotherwise it will be created.

    when vi editor starts it will be in command mode. To type we

    must have to go to Insert mode.

    Command to invoke Vi editor

  • 7/28/2019 Introduction to Linux1

    40/49

    Operation on Vi Editor

    Delete Operation

    First move the cursor so that it covers the first character of thegroup you want to delete, then type the desired command as

    below

    x Delete only the current character D Delete to the end of the line

    db Delete from the current character to the beginning of thecurrent word

    de Delete from the current character to the end of thecurrent word

    dd Delete the current line

    dw Delete from the current character to the beginning of thenext word

    [n]dd delete n lines from the current line.

  • 7/28/2019 Introduction to Linux1

    41/49

    Operation on Vi Editor

    Copy & Paste operation

    p

    Paste the specified buffer after the current cursor position or

    line. If no buffer is specified (with the " command.) then 'p' uses

    the general buffer.P

    Paste the specified buffer before the current cursor position or

    line. If no buffer is specified (with the " command.) then 'P' uses

    the general buffer.

    y

    Yank(copy) the current line.

    [n]yy

    Yank n lines from the current line. The buffer can be specified

    with the " command. If no buffer is specified, then the

    general buffer is used.

  • 7/28/2019 Introduction to Linux1

    42/49

    A

    Append at the end of the current line.I

    Insert from the beginning of a line.

    O

    (letter oh) Enterinsertmode in a new line above the current

    cursor position.

    aEnterinsertmode, the characters typed in will be inserted after

    the current cursor position. A count inserts all the text that had

    been inserted that many times.

    i

    Enterinsertmode, the characters typed in will be inserted before the

    current cursor position. A count inserts all the text that had been

    inserted that many times.

    o

    Enterinsertmode in a new line below the current cursor position.

    Inserting New Text ( Change mode from Command to Insert)

  • 7/28/2019 Introduction to Linux1

    43/49

    ZZ (in Command Mode)

    Exit the editor, saving if any changes were made.

    :w (in Last Line Mode)

    Save the current document

    :q (in Last Line Mode)

    Exit the editor if no modification is made.

    :wq (in Last Line Mode)

    Exit the editor, saving if any changes were made.

    :q! (in Last Line Mode)Exit the editor, without saving if any changes were made.

    :wq! (in Last Line Mode)

    Exit the editor, overrides the files saving if any changes

    were made.

    Saving and Quitti ng

  • 7/28/2019 Introduction to Linux1

    44/49

    Search and Replace

    As files become longer, you may need assistancelocating a particular instance of text.

    Simple search / enter

    n: next forward, N: next backward

    Search-Exclusions/wild-card search

    The special characters are: $ . * [ ] ^ \.The slash (/) starts a forward search. And (?) to

    search backwards.

  • 7/28/2019 Introduction to Linux1

    45/49

    Search and Replace

    finding instances of a given string and replacingthem with a new string. It has the following

    : line1, line2s/ oldstring / newstring

    You specify the range of text for the search-and-

    replace command with the line numbers line1 and line2. If you only give line1 and omit the comma,

    then the command only affects that line. If you

    give no line numbers, the command affects the

    current line. The search-and-replace commandonly finds the first occurrence ofoldstringon theline.

  • 7/28/2019 Introduction to Linux1

    46/49

    Search and Replace

    You can repeat a search-and-replace on the currentline by typing an ampersand (&). To repeat it on adifferent line or group of lines, type:

    : linenumber& or

    : line1,line2&

    The command g (for global) can be used with s

    (substitute) to find and replace every occurrenceof a string pattern in an entire file.

    The syntax of the global command is:

    :g/string/commands

  • 7/28/2019 Introduction to Linux1

    47/49

    Search and Replace

    The global command finds each line in the filethat hasstringin it and then applies the commandsto it. You can combine the global and substitute itin the following manner:

    :g/oldstring/s//newstring/g

    You dont need to put oldstringin the searchstring part of the substitute command because theeditor already has the pattern from the globalcommand.

    When specifying oldstring, you can use the specialcharacters as explained in the section SpecialCharacters. vi does not recognize specialcharacters in newstring, since it is performing are lacement not a search.

  • 7/28/2019 Introduction to Linux1

    48/49

    Miscellaneous

    u - undo last change U - undo all changes to the current line

    J - join current line and the line below it

    . - repeat the last command

    :! - command invoke an external "command"

    :%s/frog/toad/ -Replace the first occurrence of

    "frog" with "toad" for all lines in the file.

    dG - delete to end of the file

    1G - move to the beginning of file . . .

  • 7/28/2019 Introduction to Linux1

    49/49

    Set Command

    set nu: This command is used to associate line numberswith the file On which you are working.

    Syntax:

    [esc]:set nu

    Set ic:This command is used to ignore the case while

    searching a pattern in the file.

    Syntax:[esc]:set ic