cp lab ii lab manual

Upload: barbara-lee

Post on 05-Apr-2018

261 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 Cp Lab II Lab Manual

    1/104

    EEXX NNOO :: 11 SS TT UU DDYY OO FF UU NN IIXX OOPP EERR AATT IINN GG SSYYSS TTEE MM

    DDAATT EE::

    AA IIMM :: TToo ss ttuudd yy aa bboo uu tt uunn iixx oopp ee rr aa tt iinn gg ss yyss tt eemm..

    WHAT IS UNIX

    UNIX is an operating system which was developed first in the

    1960s and has under constant development ever since by operating

    system we mean the suite of programs which make the computer work.

    It is a stable, multi-user, multi-tasking operating system for servers,

    desktops and laptops.

    UNIX operating system also have graphical user interface

    (GUI) similar to Microsoft windows operating system which provides

    an easy to environment. However knowledge of unix is required for

    operations which are not covered by graphical program or for when

    there is no windows interface available.

    TYPES OF UNIX

    There are many different versions of unix, although they share

    the common similarities. The most popular varieties of unix are Sun

    Solaris, GNU/Linux and Macos X.

    THE UNIX OPERATING SYSTEM

    The Unix Operating system is made up of three parts

    1.

    The Kernel2. The Shell3. The Programs

    THE KERNEL

    The Kernel of Unix is the hub of the operating system. It

    allocates time and memory to programs and handles the file store and

    communication in response to system calls.

    As an illustration of the way that the shell and the kernel work

  • 7/31/2019 Cp Lab II Lab Manual

    2/104

    The shell scratches the filestore for the file containing the program

    rm. And then requests the kernel, through system calls to rm myfile

    finished running, the shell then returns the unix prompt % to the user,

    indicating execute the program rm on myfile. When the process that

    i t is waiting for future commands.

    THE SHELL

    The shell acts as an interface between the user and the

    kernel. When user login, the login program checks the username and

    password, and then starts another program called the shell. The shell is

    a command line interpreter (CLI). It interprets the commands the user

    types in an arranges for them to be carried out. The commands are

    themselves programs. When they terminate, the shell gives the user

    another prompt (% on our system). By typing part of the name of a

    command, filename and directory and pressing the [tab] key, the shell

    will complete the rest of them automatically. If shell finds more than

    one name beginning with those letters you have typed, it will beep,

    prompting to type a few more letters before pressing the tab key again.

    The shell keeps the list of the commands you have typed

    in, if you need to repeat a command, use the cursor key to scroll up and

    down the list or type history for a list of previous commands. Different

    users may use different shells. Initially, your system administrator will

    supply a default shell , which can be overridden or changed.

    The most commonly available shells are:

    Bourne shell (sh) C shell (csh) Korn shell (ksh) TC Shell (tcsh) Bourne Again Shell (bash)Each shell also includes its own programming language. Command

    files, called "shell scripts" are used to accomplish a series of tasks.

  • 7/31/2019 Cp Lab II Lab Manual

    3/104

    editing file maintenance printing sorting programming support online info

    Modular: single functions can be grouped to perform more complex

    tasks.

    The Bourne shell is one of the oldest shells and is the most efficient for

    background work. However it provides few facilit ies for interactive

    users.

    The C shell provides sophisticated interactive capabilities lacking in

    the Bourne shell. Features of this shell include a command history

    buffer, command aliases and file name completion. The C shell has a

    syntax which resembles the C programming language.

    The C shell is the default shell for interactive work on many UNIX

    systems. It will be covered in this document, although most of the

    basic commands given here are relatively standard across all the main

    shells.

    The Korn shell was written by David Korn from AT&T and in it he

    attempted to merge the preferred features of both the Bourne and C

    shells as well as adding some additional features.

    Unfortunately the Korn shell was not available for free, as other UNIX

    shells were, so many users and companies did not chose to use of it .

    The Bash shell was based on the Bourne shell (Bourne again shell) and

    as with Korn it attempted to combine the best features of the othershells which were available at the time. This shell however was

    available for free. Bash was initially adopted for LINUX although

    several varieties of LINUX now exist e.g. RedHat, SuSE and Debian-

    GNU.

  • 7/31/2019 Cp Lab II Lab Manual

    4/104

    A file is collection of datas. They are created by users using text

    editors, running, compilers etc.

    Examples of files

    Document The text of a program written in some high level language.All files are grouped together in the directory structure. The file system

    is arranged in a hierarchical structure, l ike inverted tree. The top of the

    hierarchy is traditionally called root (written [/] slash)

    FEATURES OF UNIX

    1. MultitaskingMultitasking is the capability of the operating system to perform

    various tasks simultaneously. I .e. A single user can run multiple

    programs (tasks) concurrently.

    2. Multi-user CapabilityMulti-user capability of UNIX allows several users to use the

    same computer to perform their tasks. Several terminals (keyboards and

    monitors) are connected to a single powerful computer (Unix server)

    and each user can work with their terminals.

    3. SecurityUnix allows sharing of data. Every user must have a login name

    and a password. So, accessing another user s data is impossible withoutpermission.

    I.e. Invalid users cannot access data.

    4. PortabilityUNIX is portable because it is written in a high level language.

    So, UNIX can be run on different computers.

  • 7/31/2019 Cp Lab II Lab Manual

    5/104

    o Between the different terminals connected to the UNIXserver.

    o Between the users of one computer to the users of anothercomputer located elsewhere in the network.

    6. Programming facilityUNIX is highly programmable, the UNIX shell programming

    language has all necessary ingredients like conditional and control

    structure (Loops) and variables, that establish it as a programming

    language in its own right.

    ADVANTAGES OF U NIX

    UNIX is a very stable operating system. UNIX supports the Multi-User feature. UNIX is a Multitasking operating system. UNIX can be loaded to any type of computer hardware. UNIX is optimized for program development. UNIX has rich set of small commands and utili t ies that do

    specific tasks.

    UNIX has a powerful unified file system, everything in a filedata, program and all physical devices.

    UNIX has the ability to string commands and utili t ies together inunlimited ways to accomplish more complicated tasks.

    UNIX allows only authorized users to modify files anddirectories.

    UNIX allows only System Administrators to make changes inSystem Configuration files.

  • 7/31/2019 Cp Lab II Lab Manual

    6/104

    RESULT:Thus study of unix operating system was complete.

  • 7/31/2019 Cp Lab II Lab Manual

    7/104

    Ex. No: 1.2 BASIC UNIX COMMANDS

    DATE:

  • 7/31/2019 Cp Lab II Lab Manual

    8/104

    Aim

    To study and execute Unix commands.

    Unix is security conscious, and can be used only by those persons who have an

    account. Telnet (Telephone Network) is a Terminal emulator program for TCP/IP

    networks that enables users to log on to remote servers.

    To logon, type telnet server_ipaddress in run

    window.

    User has to authenticate himself by providing username and password. Once

    verified, a greeting and $ prompt appears. The shell is now ready to receivecommands from the user. Options suffixed with a hyphen () and arguments are

    separated by space.

    General commands

    Command Functiondate Used to display the current system date and time.date +%D Displays date onlydate +%T Dis la s time onl

    date +% Y Displays the year part of datedate +% H Displays the hour part of timecal Calendar of the current monthcalyear Displays calendar for all months of the specified yearcalmonth year Displays calendar for the specified month of the yearwho Login details of all users such as their IP, Terminal No, User name,who am i Used to display the login details of the usertty Used to display the terminal nameuname Displays the Operating Systemunamer Shows version number of the OS (kernel).unamen Displays domain name of the server

    echo "txt" Dis la s the iven text on the screenecho $HOME Displays the user's home directorybc Basic calculator. Press Ctrl+d to quitlpfile Allows the user to spool a job along with others in a print queue.

    mancmdname Manual for the given command. Press q to exithistory To display the commands used by the user since log on.exit Exit from a process. If shell is the only process then logs out

  • 7/31/2019 Cp Lab II Lab Manual

    9/104

    Directory commands

    Command Functionpwd Path of the present working directorymkdirdir A directory is created in the given name under the currentmkdirdir1 dir2 A number of sub-directories can be created under one stroke

    cdsubdir Change Directory. If the subdir starts with / then path starts

    cd To switch to the home directory.cd / To switch to the root directory.

  • 7/31/2019 Cp Lab II Lab Manual

    10/104

    Command Functioncd .. To move back to the parent directoryrmdirsubdir Removes an empty sub-directory.

    File commands

    Command Functioncat >filename To create a file with some contents. To end typing press

    catfilename Displays the file contents.

    cat >>filename Used to append contents to a file

    cpsrc des Copy files to given location. If already exists, it will be

    cpi src des Warns the user prior to overwriting the destination filecpr src des Copies the entire directory, all its sub-directories and files.

    mv old new To rename an existing file or directory. i option can also bemvf1 f2 f3 dir To move a group of files to a directory.

    mvv old new Display name of each file as it is moved.

    rmfile Used to delete a file or group of files. i option can also be usedrm * To delete all the files in the directory.rmr * Deletes all files and sub-directoriesrmf * To forcibly remove even write-protected filesls Lists all files and subdirectories (blue colored) in sortedlsname To check whether a file or directory exists.lsname* Short-hand notation to list out filenames of a specific pattern.lsa Lists all files including hidden files (files beginning with .)lsxdirname To have specific listing of a directory.lsR Recursive listing of all files in the subdirectorieslsl Long listing showing file access rights (read/write/execute-

    cmpfile1 file2 Used to compare two files. Displays nothing if files are

    wcfile It produces a statistics of lines (l), words(w), and characters(c).

    chmodperm file Changes permission for the specified file. (r=4, w=2, x=1)

    chmod 740 file sets all rights for user, read only for groups

    The commands can be combined using the pipeline (|) operator. For example,number of users logged in can be obtained as.

    who | wc -l

    Finally to terminate the unix session execute the command exit or logout.

  • 7/31/2019 Cp Lab II Lab Manual

    11/104

    [vijai@localhost vijai]$ date

    Sat Apr 9 13:03:47 IST 2011

    [vijai@localhost vijai]$ date +%D

    04/09/11

    [vijai@localhost vijai]$ date +%T

    13:05:33

    [vijai@localhost vijai]$ date +%Y

    2011

    [vijai@localhost vijai]$ date +%H

    13

    [vijai@localhost vijai]$ cal

    April 2011

    Su Mo Tu We Th Fr Sa

    1 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 27 28 29 30

    [vijai@localhost vijai]$ cal 08 1998

    August 1998

    Su Mo Tu We Th Fr Sa

    1

    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 27 28 29

    30 31

    mailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhost
  • 7/31/2019 Cp Lab II Lab Manual

    12/104

    [vijai@localhost vijai]$ cal 1800

    1800

    January February March

    Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

    1 2 3 4 1 1

    5 6 7 8 9 10 11 2 3 4 5 6 7 8 2 3 4 5 6 7 8

    12 13 14 15 16 17 18 9 10 11 12 13 14 15 9 10 11 12 13 14 15

    19 20 21 22 23 24 25 16 17 18 19 20 21 22 16 17 18 19 20 21 22

    26 27 28 29 30 31 23 24 25 26 27 28 23 24 25 26 27 28 29

    30 31

    October

    November December

    Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa

    1 2 3 4 1 1 2 3 4 5 6

    5 6 7 8 9 10 11 2 3 4 5 6 7 8 7 8 9 10 11 12 13

    12 13 14 15 16 17 18 9 10 11 12 13 14 15 14 15 16 17 18 19 2019 20 21 22 23 24 25 16 17 18 19 20 21 22 21 22 23 24 25 26 2726 27 28 29 30 31 23 24 25 26 27 28 29 28 29 30 31

    30

    [vijai@localhost vijai]$ who

    root :0 Apr 9 08:41

    vijai pts/0 Apr 9 13:00 (scl-64)cse1 pts/3 Apr 9 13:18 (scl-41.smkfomra.com)ecea pts/4 Apr 9 13:18 (scl-29.smkfomra.com)

    [vijai@localhost vijai]$ who am i

    vijai pts/0 Apr 9 13:00 (scl-64)

    [vijai@localhost vijai]$ tty

    /dev/pts/0

    [vijai@localhost vijai]$ uname

    mailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhost
  • 7/31/2019 Cp Lab II Lab Manual

    13/104

    Linux

    [vijai@localhost vijai]$ uname -r

    2.4.20-8smp

    [vijai@localhost vijai]$ uname -n

    localhost.localdomain

    [vijai@localhost vijai]$ echo "How are you"

    How are you

    [vijai@localhost vijai]$ echo $HOME

    /home/vijai

    [vijai@localhost vijai]$ echo $USER

    vijai

    [vijai@localhost vijai]$ bc

    bc 1.06

    Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.

    3+5

    8

    2%3

    2

    [vijai@localhost loops]$ pwd

    /home/vijai/shellscripts/loops

    [vijai@localhost vijai]$ mkdir filter

    [vijai@localhost vijai]$ ls

    filter list.sh regexpr shellscripts

    mailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhost
  • 7/31/2019 Cp Lab II Lab Manual

    14/104

    [vijai@localhost vijai]$ cd shellscripts/loops/

    [vijai@localhost loops]$

    [vijai@localhost loops]$ cd

    [vijai@localhost vijai]$

    [vijai@localhost loops]$ cd /

    [vijai@localhost /]$

    [vijai@localhost /]$ cd /home/vijai/shellscripts/loops/

    [vijai@localhost loops]$ cd ..

    [vijai@localhost shellscripts]$

    [vijai@localhost vijai]$ rmdir filter

    [vijai@localhost vijai]$ ls

    list.sh regexpr shellscripts

    [vijai@localhost vijai]$ cat > greet

    hi ece-a

    wishing u the best

    [vijai@localhost vijai]$ cat greet

    hi ece-a

    wishing u the best

    [vijai@localhost vijai]$ cat >> greet

    bye

    [vijai@localhost vijai]$ cat greet

    hi ece-a

    wishing u the best bye

    mailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhost
  • 7/31/2019 Cp Lab II Lab Manual

    15/104

    [vijai@localhost vijai]$ ls

    greet list.sh regexpr shellscripts

    [vijai@localhost vijai]$ ls -a

    . .bash_logout .canna .gtkrc regexpr .viminfo.tmp

    .. .bash_ rofile .emacs .kde shellscri ts .xemacs

    .bash_history .bashrc greet list.sh .viminfo

    [vijai@localhost vijai]$ ls -l

    total 16

    -rw-rw-r-- 1 vijai vijai 32 Apr 11 14:52 greet

    -rw-rw-r-- 1 vijai vijai 30 Apr 4 13:58 list.shdrwxrwxr-x 2 vijai vijai 4096 Apr 9 14:30 regexpr

    drwxrwxr-x 7 vijai vijai 4096 Apr 4 14:57 shellscripts

    [vijai@localhost vijai]$ cp greet ./regexpr/

    [vijai@localhost vijai]$ ls

    mailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhost
  • 7/31/2019 Cp Lab II Lab Manual

    16/104

    greet list.sh regexpr shellscripts

    [vijai@localhost vijai]$ ls ./regexpr demo greet

    [vijai@localhost vijai]$ cp -i greet ./regexpr/

    cp: overwrite 'greet'? n

    [vijai@localhost vijai]$ mv greet greet.txt

    [vijai@localhost vijai]$ ls

    greet.txt list.sh regexpr shellscripts

    [vijai@localhost vijai]$ mv greet.txt ./regexpr/[vijai@localhost vijai]$ ls list.sh regexpr

    shellscripts [vijai@localhost vijai]$ ls

    ./regexpr/ demo greet.txt

    [vijai@localhost vijai]$ ls

    fact.sh list.sh prime.sh regexpr shellscripts

    [vijai@localhost vijai]$ rm -i *.sh rm: remove

    regular file `fact.sh'? y rm: remove regular file

    `list.sh'? n rm: remove regular file `prime.sh'? y

    [vijai@localhost vijai]$ ls

    list.sh regexpr shellscripts

    [vijai@localhost vijai]$ wc list.sh

    4 9 30 list.sh

    [vijai@localhost vijai]$ wc -l list.sh

    4 list.sh

    [vijai@localhost vijai]$ cmp list.sh fact.sh

    list.sh fact.sh differ: byte 1, line 1

    [vijai@localhost vijai]$ ls -l list.sh

    -rw-rw-r-- 1 vijai vijai 30 Apr 4 13:58 list.sh

    mailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhost
  • 7/31/2019 Cp Lab II Lab Manual

    17/104

    [vijai@localhost vijai]$ chmod ug+x list.sh [vijai@localhost vijai]$ ls -l

    list.sh

    -rwxrwxr-- 1 vijai vijai 30 Apr 4 13:58 list.sh

    [vijai@localhost vijai]$ chmod 740 list.sh

    [vijai@localhost vijai]$ ls -l list.sh

    -rwxr----- 1 vijai vijai 30 Apr 4 13:58 list.sh

    mailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhostmailto:vijai@localhost
  • 7/31/2019 Cp Lab II Lab Manual

    18/104

    RESULT

    Thus the stud y and execution of Unix commands has been completed

    Successful ly.

  • 7/31/2019 Cp Lab II Lab Manual

    19/104

    Ex. No: 1.3 STUDY OF VI EDITOR

    DATE

    Aim

    To introduce the concept of text editing vi editor and the options regarding the

    control of the editor.

    vi

    Editor

    A text editor is one of the most common and useful tools in all Operating

    Systems. Unix provides a versatile editor vi, a full-screen editor and owes its origin

    to Bill Joy. "vi" stands for visual editor. A vi session begins by invoking vi with or

    without a filename

    $vi

    $vifilename

    The user is presented with a full empty screen, each line beginning with a ~. This is

    vi's way of indicating non-existent lines. Out of 25 lines on the terminal, 24 can be

    used to enter text. The last line is reserved for commands and also used by the system

    to display messages. vi functions in three modes namely:

    1. Input modeWhere any key depressed is entered as text

    2. Command modeWhere keys are used as commands to act on text (initial

    mode)

    3. ex modeex mode commands that can be entered in the last line to act on text

  • 7/31/2019 Cp Lab II Lab Manual

    20/104

    INPUT MODE

  • 7/31/2019 Cp Lab II Lab Manual

    21/104

    vi modes

    vistarts with command mode. To insert text any of the following commands should be

    used.

    Commands Functioni Inserts text to the left of the cursor.I Inserts text at the beginning of line.a Appends text to right of cursorA Appends text at end of lineo Opens line belowO Opens line above

    In Input mode the editor displays INSERT in the last line. Press Enter key to start a

    fresh line of text in Input mode and the ~ disappears. To quit inputmode pressEsc key.

    COMMAND MODE

    EDIT COMMANDS

    Command FunctionR Replaces more than a single character. The editor displays

    s Deletes a single character to the left and switches to Input mode.x Deletes the character in the current cursor position?text Locates the text in the file. If not found, the message "Pattern not

    "U or u Reverses the last chan

    dd Cuts the entire linedw Cuts the entire wordd$ Cuts a line from cursor position to the end of the lined0 Cuts from the cursor position to the start of the line

    Co ies ( anks the entire lineyw Copies the entire wordp Pastes the text

  • 7/31/2019 Cp Lab II Lab Manual

    22/104

  • 7/31/2019 Cp Lab II Lab Manual

    23/104

    Command Functionb Moves back to beginning of a wordw Moves forward to beginning of word| Moves to start of the line

    $ Moves to end of the linek Up one linej Down one lineh Left one characterl Right one characterCtrl+f Scrolls a page forwardCtrl+b Scrolls a page backwardlG To move to the specific line

    One of the most notable features of vi is the facility of prefixing a number to

    most commands. When prefixed, commands interpret the instruction to be repeated as

    many times. For example 3x deletes the next three character.

    THE EX

    MODE

    The essential save and exit commands form the features of ex mode. Press :

    (colon) in command mode to switch to ex mode. The : is displayed in the last line.

    Type the command and pressEnterkey to execute the same.

    Command Functionw Saves file, displays the number of lines & characters and

    wfile The file is saved under the given nameL1,L2 wfile Used to write specific line numbers to some file. The . (dot)

    q Quits vi session and returns to $ prompt. vi has a safety

    q! Quits vi session without saving any changes made since the lastwq Save and exitsh Escape to shell%s/Sstr/Rstr/g This is yet another powerful feature known as substitution.

    It is similar to Find and Replace. % represents all lines, g

    rfile To insert another file into the current file.

    newfile Splits screen into multiple windows and opens the file.

  • 7/31/2019 Cp Lab II Lab Manual

    24/104

  • 7/31/2019 Cp Lab II Lab Manual

    25/104

    ~

    ~

    ~

    ~

    ~~

    ~

    ~

    ~

    Sample.txt [New File]

    This is vi improved vim

    A rudimentary text

    ~

    ~

    ~

    ~

    ~

    ~

    ~

    ~

    ~

    Sample.txt 2L, 30C written

    vi Editorfor new file

  • 7/31/2019 Cp Lab II Lab Manual

    26/104

  • 7/31/2019 Cp Lab II Lab Manual

    27/104

  • 7/31/2019 Cp Lab II Lab Manual

    28/104

    RESULT

    Thus the study of text manipulation using vi editor has been completedsuccessfully.

  • 7/31/2019 Cp Lab II Lab Manual

    29/104

    EXP NO: Finding the Cube

    DATE:

    AIM

    ALGORITHM

    1. Enter the value of a number.2. Perform the product of the given number thrice.3. Display the result.

  • 7/31/2019 Cp Lab II Lab Manual

    30/104

    PROGRAM:

    echo "enter a number"

    read a

    let b=$a*$a*$a

    echo " the cube is $b"

  • 7/31/2019 Cp Lab II Lab Manual

    31/104

  • 7/31/2019 Cp Lab II Lab Manual

    32/104

    OUTPUT

    enter a number

    3

    the cube is 27

  • 7/31/2019 Cp Lab II Lab Manual

    33/104

    RESULT

    EX NO: Student Details

    DATE:

    AIM

    ALGORITHM

    1. Start the program.2. Get name,DOB,reg.no and percentage respectively.3. Display the details4. Stop the program

  • 7/31/2019 Cp Lab II Lab Manual

    34/104

    PROGRAM:

    echo "enter the name"

  • 7/31/2019 Cp Lab II Lab Manual

    35/104

    read n

    echo "enter the DOB"

    read d

    echo "enter the reg.no"

    read r

    echo "enter the percentage"

    read p

    echo "name: $n"

    echo "DOB: $d"

    echo "reg.no: $r"

    echo "percentage: $p"

  • 7/31/2019 Cp Lab II Lab Manual

    36/104

    OUTPUT:

    enter the name

    murugan

    enter the DOB

    14.5.1993

    enter the reg.no

    48

    enter the percentage

    95

    name: murugan

  • 7/31/2019 Cp Lab II Lab Manual

    37/104

    DOB: 14.5.1993

    reg.no: 48

    percentage: 95

    RESULT:

    EX NO: Sum Of N Numbers

    DATE:

  • 7/31/2019 Cp Lab II Lab Manual

    38/104

    AIM:

    ALGORITHM:

    1. Enter the limit as n.2. Initialize i as 1 and sum as 0.3. Compute the value of sum and i until i is less than or equal to n.4. Sum is computed by adding the value of sum and i.5. i is computed by adding one to i.6. Display the result by sum.

  • 7/31/2019 Cp Lab II Lab Manual

    39/104

    PROGRAM:

    echo "enter limit"

    read n

    i=1

    sum=0

    while [ $i -le $n ]

    do

    let sum=$sum+$i

    let i=$i+1

    done

  • 7/31/2019 Cp Lab II Lab Manual

    40/104

    echo " the sum of $n numbers is $sum"

    OUTPUT:

  • 7/31/2019 Cp Lab II Lab Manual

    41/104

    enter limit

    8

    the sum of 8 numbers is 36

  • 7/31/2019 Cp Lab II Lab Manual

    42/104

    RESULT

    EX NO : PROGRAM IMPLEMENTING FOR LOOP

    DATE:

    AIM:

    ALGORITHM:

  • 7/31/2019 Cp Lab II Lab Manual

    43/104

    PROGRAM:

    echo "program implementing for loop"

    sum=0

  • 7/31/2019 Cp Lab II Lab Manual

    44/104

    for i in 1 2 3 4 10

    do

    sum=`expr $sum + $i`

    done

    echo "the sum is $sum"

  • 7/31/2019 Cp Lab II Lab Manual

    45/104

    OUTPUT:

    program implementing for loop

    the sum is 20

  • 7/31/2019 Cp Lab II Lab Manual

    46/104

    RESULT:

    EXP NO : Electricity Bill Calculation

    DATE:

    AIM:

  • 7/31/2019 Cp Lab II Lab Manual

    47/104

    ALGORITHM:

    1. Get the previous unit and current unit.2. Calculate the current consumed.3. If the current consumed is greater than 1000 then amount is the product of current

    consumed and 0.9.

    4. If the current consumed is greater than 500 and less than 1000 then amount is theproduct of current consumed and 0.6.

    5. If the current consumed is less than 500 then amount is the product of currentconsumed 0.9.

    6. Display the amount for the current consumed.

  • 7/31/2019 Cp Lab II Lab Manual

    48/104

    PROGRAM:

    echo "enter the previous unit and current unit"

    read pu cu

    let cc=$cu-$pu

    if [ $cc -gt 1000 ]

    then

    let amt=$cc*9/10

    elif [ $cc -gt 500 -a $cc -le 1000 ]

    then

    let amt=$cc*6/10

    else

  • 7/31/2019 Cp Lab II Lab Manual

    49/104

    let amt=$cc*3/10

    fi

    echo "the amount is : $amt"

    OUTPUT:

    enter the previous unit and current unit

  • 7/31/2019 Cp Lab II Lab Manual

    50/104

    1000 2000

    the amount is : 600

  • 7/31/2019 Cp Lab II Lab Manual

    51/104

    RESULT:

    EX NO: NET SALARY

    DATE:

    AIM:

    ALGORITHM

    1. Enter the basic pay,hra,ta,da and pf.2. Add the basic pay,hra, ta,da and save it as the gross salary.3. If gross salary is greater then 10000 then income tax equals the product of gross

    salary and 0.5.

    4. If gross salary is less than 10000 then income tax equals the product of grosssalary and 0.2.

    5. Assign deduction as the sum of pf and it.6. Net salary the difference between gross salary and deduction.

  • 7/31/2019 Cp Lab II Lab Manual

    52/104

    PROGRAM:

    echo "enter the basic pay,hra,ta,da and pf"

  • 7/31/2019 Cp Lab II Lab Manual

    53/104

    read bp hra ta da pf

    let gs=$bp+$hra+$ta+$da

    if [ $gs -ge 10000 ]

    then

    let it=$gs*5/100

    else

    let it=$gs*2/100

    fi

    let de=$pf+$it

    let ns=$gs-$de

    echo "net salary : $ns"

  • 7/31/2019 Cp Lab II Lab Manual

    54/104

    OUTPUT:

    enter the basic pay,hra,ta,da and pf

    1200 350 450 800 250

    net salary : 2494

  • 7/31/2019 Cp Lab II Lab Manual

    55/104

    RESULT:

    EX NO : MULTI WAY BRANCHING USING CASE STATEMENT

    DATE:

    AIM:

  • 7/31/2019 Cp Lab II Lab Manual

    56/104

    ALGORITHM:

  • 7/31/2019 Cp Lab II Lab Manual

    57/104

    PROGRAM:

    echo "concept of multi-way branching using case statement"

    clear

    echo "1.To know your current directory"

    echo "2.todays date"

    echo "3.list of users"

    echo "enter your choice"

    read choice

    case $choice in

    1) pwd;;

    2) date;;

    3) who;;

  • 7/31/2019 Cp Lab II Lab Manual

    58/104

    *)echo "only give inputs from 1 to 3"

    esac

    OUTPUT:

  • 7/31/2019 Cp Lab II Lab Manual

    59/104

    1.To know your current directory

    2.todays date

    3.list of users

    enter your choice

    1

    /home/linuxpert

  • 7/31/2019 Cp Lab II Lab Manual

    60/104

    RESULT:

    EX NO: CHECKING WHETHER A NUMBER IS PRIME OR NOT

    DATE:

    AIM:

    ALGORITHM:

    1. Read the value of n.2. Assign the value of x as 0 and i as 2.3. Increment the value of i until it reaches n.4. Perform the modulo of n with i and store it in s.5. If s equals zero then assign x as 1.6. IF x equals 1 then print n is not a prime number.7. If x doesn't equal 1 the print n is a prime number.

  • 7/31/2019 Cp Lab II Lab Manual

    61/104

    PROGRAM:

    echo "enter the number"

    read n

    x=0

  • 7/31/2019 Cp Lab II Lab Manual

    62/104

    for((i=2;i

  • 7/31/2019 Cp Lab II Lab Manual

    63/104

    OUTPUT:

    enter the number

    7

    7 is a prime number

  • 7/31/2019 Cp Lab II Lab Manual

    64/104

    RESULT

    EX NO FACTORIAL NUMBER

    DATE:

    AIM:

    ALGORITHM:

  • 7/31/2019 Cp Lab II Lab Manual

    65/104

    1. Read the value of n.2. Assign the value of i and fact as 1.3. Find the product of fact and i until i is less than or equal to 1.4. Increment the value of i value by 1.5.

    Print the factorial value.

    PROGRAM:

    echo "enter the limit"

    read n

    i=1

    fact=1

    while [ $i -le $n ]

    do

    let fact=$fact*$i

    let i=$i+1

    done

    echo "factorial of $n is $fact"

  • 7/31/2019 Cp Lab II Lab Manual

    66/104

    OUTPUT:

    enter the limit

    7

    factorial of 7 is 5040

  • 7/31/2019 Cp Lab II Lab Manual

    67/104

    RESULT:

    EX NO: ARITHMETIC OPERATION USING SWITCH CASE

    DATE:

    AIM:

    ALGORITHM:

    1. Get the values and choice.

  • 7/31/2019 Cp Lab II Lab Manual

    68/104

    2. If choice is one, addition is performed and sum is displayed.3. If choice is two, subtraction is performed and difference is displayed.4. If choice is three, multiplication is performed and product is displayed.5. If choice is four, division is performed and quotient is displayed.

    PROGRAM

    echo "1.addition 2.subtraction 3.multiplication 4.division"

    echo "enter the choice"

    read n

    echo "enter the values"

    read a b

    case $n in

    1)let x=$a+$b

    echo "the sum is $x";;

    2)let x=$a-$b

    echo "the difference is $x";;

    3)let x=$a*$b

    echo "the product is $x";;

    4)let x=$a/$b

  • 7/31/2019 Cp Lab II Lab Manual

    69/104

    echo "the quotient is $x";;

    *)echo "invalid choice"

    exit

    esac

    OUTPUT:

    1.addition 2.subtraction 3.multiplication 4.division

    enter the choice

    4

    enter the values

    4 2

    the quotient is 2

  • 7/31/2019 Cp Lab II Lab Manual

    70/104

    RESULT:

    EX NO : FIBONACCI SERIES

    DATE:

    AIM:

    ALGORITHM:

  • 7/31/2019 Cp Lab II Lab Manual

    71/104

  • 7/31/2019 Cp Lab II Lab Manual

    72/104

    PROGRAM:

    echo "enter a number"

    read n

    a=0

    b=1

    i=3

    echo "fibonacci series"

    echo $a

    echo $b

    while [ $i -le $n ]

    do

    c=`expr $a + $b`

    echo "$c"

    a=$b

  • 7/31/2019 Cp Lab II Lab Manual

    73/104

    b=$c

    i=`expr $i + 1`

    done

    OUTPUT:

    enter a number

    5

    fibonacci series

    0

    1

  • 7/31/2019 Cp Lab II Lab Manual

    74/104

    1

    2

    3

  • 7/31/2019 Cp Lab II Lab Manual

    75/104

    RESULT:

    EX NO : ODD OR EVENDATE:

    AIM:

    ALGORITHM:

    1. Get the number as x.2. read num.3. check if x % 2 equal 0 and if yes display the given number is even.4. Else display the given number is odd.

  • 7/31/2019 Cp Lab II Lab Manual

    76/104

    PROGRAM:

    echo "enter the numbers"

    read num

    x=`expr $num % 2`

    if test $x -eq 0

    then

  • 7/31/2019 Cp Lab II Lab Manual

    77/104

    echo "$num is an even number"

    else

    echo "$num is an odd number"

    fi

  • 7/31/2019 Cp Lab II Lab Manual

    78/104

    OUTPUT:

    enter the numbers

    4

    4 is an even number

  • 7/31/2019 Cp Lab II Lab Manual

    79/104

    RESULT:

    EX NO GREATEST OF THREE NUMBERS

    DATE:

    AIM:

    ALGORITHM:

    1. Read the variables.2. Check if A is greater than B and C

  • 7/31/2019 Cp Lab II Lab Manual

    80/104

    3. If so,Print A is greater.4. Else, check if B is greater than C.5. If so, print B is greater, else print C is greater.

  • 7/31/2019 Cp Lab II Lab Manual

    81/104

    PROGRAM:

    echo -e "\t\t biggest among 3 nos\n"

    echo "enter 3 values"

    read a b c

    if [ $a -gt $b ] && [ $a -gt $c ]

    then

    echo "$a is big"

    elif [ $b -gt $c ]

    then

    echo "$b is big"

    else

    echo "$c is big"

    fi

  • 7/31/2019 Cp Lab II Lab Manual

    82/104

    OUTPUT:

    biggest among 3 nos

    enter 3 values

    6 9 8

    9 is big

  • 7/31/2019 Cp Lab II Lab Manual

    83/104

    RESULT:

  • 7/31/2019 Cp Lab II Lab Manual

    84/104

    EX NO : POSITIVE OR NEGATIVE

    DATE:

    AIM:

    ALGORITHM:

    1. Get the number as num.2. Check if num is greater than 0 , if yes display the given number is negative.3. Else display the given number is negative.

    PROGRAM:

    echo "enter a number"

    read a

    if [ $a -ge 0 ]

    then

    echo "$a is positive"

    else

    echo "$a is negative"

    fi

  • 7/31/2019 Cp Lab II Lab Manual

    85/104

    OUTPUT:

    enter a number

    -6

    -6 is negative

    enter a number

    4

    4 is positive

  • 7/31/2019 Cp Lab II Lab Manual

    86/104

    RESULT:

    EX NO : CHECK WHETHER NUMBERS ARE EQUAL OR NOT

  • 7/31/2019 Cp Lab II Lab Manual

    87/104

    DATE:

    AIM:

    ALGORITHM:

    1. Read a and b2. If a equals b then print numbers are equal.3. Else print numbers are not equal.

  • 7/31/2019 Cp Lab II Lab Manual

    88/104

    PROGRAM:

    echo "enter a number"

    read a

    echo "enter another number"

    read b

    if test $a -eq $b

    then

    echo "numbers are equal"

    else

  • 7/31/2019 Cp Lab II Lab Manual

    89/104

    echo "number are not equal"

    fi

    OUTPUT:

  • 7/31/2019 Cp Lab II Lab Manual

    90/104

    enter a number

    4

    enter another number

    5

    number are not equal

    RESULT:

  • 7/31/2019 Cp Lab II Lab Manual

    91/104

    EX NO : NATURAL NUMBER UPTO LIMIT N

    DATE:

    AIM:

    ALGORITHM:

  • 7/31/2019 Cp Lab II Lab Manual

    92/104

    PROGRAM:

  • 7/31/2019 Cp Lab II Lab Manual

    93/104

    echo enter the limit

    read n

    echo N natural number upto the limit $n is

    i=0

    while [ $i -lt $n ]

    do

    i=`expr $i + 1`

    echo $i

    done

  • 7/31/2019 Cp Lab II Lab Manual

    94/104

    OUTPUT:

    enter the limit

    4

    N natural number upto the limit 4 is

    1

    2

    3

    4

  • 7/31/2019 Cp Lab II Lab Manual

    95/104

    RESULT:

    EX NO: SWAPPING OF TWO NUMBERS

    DATE:

  • 7/31/2019 Cp Lab II Lab Manual

    96/104

    AIM :

    ALGORITHM:

    1. Enter the two numbers such as and b to be swapped.2. Assign a to the temp variable t.3. Assign the value of b to a.4. Assign the temp value to b.5. Display the value of a and b.

  • 7/31/2019 Cp Lab II Lab Manual

    97/104

    PROGRAM

    echo "enter two numbers"

    read a b

    t=$a

    a=$b

    b=$t

    echo "a=$a b=$b"

  • 7/31/2019 Cp Lab II Lab Manual

    98/104

    OUTPUT:

    enter two numbers

  • 7/31/2019 Cp Lab II Lab Manual

    99/104

    3 4

    a=4 b=3

  • 7/31/2019 Cp Lab II Lab Manual

    100/104

    RESULT

    EX NO: AREA OF CIRCLE

    DATE:

    AIM:

    ALGORITHM:

  • 7/31/2019 Cp Lab II Lab Manual

    101/104

  • 7/31/2019 Cp Lab II Lab Manual

    102/104

    pi=`expr "scale=2; 22 / 7"| bc`

    readonly pi

    echo -n "enter value for radius:"

    read radius

    area=`expr "scale=2; $pi * $radius * $radius" | bc`

    circum=`expr "scale=2; 2 * $pi * $radius" | bc`

    echo "area: $area"

    echo "circumference: $circum"

  • 7/31/2019 Cp Lab II Lab Manual

    103/104

    OUTPUT:

    enter value for radius:12

    area: 452.16

    circumference: 75.36

  • 7/31/2019 Cp Lab II Lab Manual

    104/104

    RESULT: