Sunteți pe pagina 1din 80

Ex. No. :01 Date: Aim To understand the concepts of UNIX-Operating System.

UNIX UNIX is a multitasking, multi-user system The name is given to a whole family of related operating systems and their most common application, utility, and compiler programs It is a rich, extensible, and open computing environment The term UNIX refers to a powerful multitasking, multi-user operating system UNIX System Architecture The UNIX system consists of three main software components 1) Kernel 2) Unix Utilities 3) Application Software Kernel The core of the UNIX system is the kernel-the operating system program. The Kernel controls the computers resources allotting them to different users and to different tasks. It interacts directly with the hardware, thus making the programs easy to write and portable across different platforms of hardware. Since the kernel communicates directly with the hardware, parts of the kernel must be customized to each systems hardware features. UNIX Utilities UNIX utilities or commands are a collection of about 200 programs that service the day-to-day processing requirements. These programs are invoked through the shell, which is itself another utility. Study of UNIX OS

GE2155

DCE

Page 1 of 80

GE2155

DCE

Page 2 of 80

Application Software Apart from the utilities that are provided as part of the UNIX operating system, more than a thousand UNIX-based application programs, like database management systems, word processors, accounting software and language processors, are available from independent software vendors. UNIX File System A single disk can store thousands of files. For organizing data on the disk, the operating systems provide a file system. This file system allows you to group files in convenient manner. The UNIX file system has a hierarchical structure and files can be stored under directories. All the files are stored under one main directory called the root directory. The root directory has been further sub-divided into directories. In each directory, files contains related data can be stored. A typical UNIX File System root (/) bin dev etc usr bin File-Naming Conventions In UNIX, file names, can be up to 14 characters long can contain digits, a dot(.) , the hyphen(-) or the underscore symbol(_) anywhere can contain both upper-case and lower-case alphabets are case-sensitive For example, THIS_FILE is not the same as this_file a.h is not the same A>h or A.h Should not have a blank, or a tab user lib temp

GE2155

DCE

Page 3 of 80

GE2155

DCE

Page 4 of 80

Types of Files in UNIX In UNIX all information is treated as a file. So besides the users program files and data files, there are special files such as files that contain information about directory contents or files that store information about various input output devices connected to the system. Ordinary Files All files created by user come under this category of files. These include all data files, program files, object files and executable files. A user can make changes to such files. Directory Files For each directory, there is a file by the same name as the directory which contains information about files under that directory. Special Files Most of the system files in UNIX are special files. Special files are typically associated with input-output devices. Types of Users in UNIX System Administrator The system administrator (SA) is primarily responsible for the smooth operation of the system. It is the System Administrators job to switch on the console. File Owner The user who creates a file is said to be the owner of that file. The owner of a file can perform any operation on that file-copying, deleting and editing. Group Owner A project team of five people of the Smartest Consultants Inc. is working on a software development project-PROJECT-ABC-for a private detective agency. The team is headed by an analyst.

GE2155

DCE

Page 5 of 80

GE2155

DCE

Page 6 of 80

Features of UNIX Multi-Programming Unix allows many programs to be executed simultaneously. The feature is called multi-programming. An executing instance of a program is called process. Time Sharing Multi-Programming is made possible on the Unix system by the concept of time-sharing. Since there is only a single CPU to take care of the various programs to be executed, the programs are queued and CPU time is shared among each of them. Each program is attended for a specific period of time, and then put back on the queue to wait for its turn again as the next program in the queue is taking up. Multi-tasking A program in UNIX is broken down into tasks, where each task can be something like reading from or writing to the disk, or waiting for input from the user and so on. When a program is waiting for completion of a task, the CPU, rather than waste time, starts executing the next task. Therefore, while a program is waiting for the input from the user, another program could be reading the hard disk.

Result Thus the concepts of UNIX operating system were studied.

GE2155

DCE

Page 7 of 80

GE2155

DCE

Page 8 of 80

Ex. No. :02 Date: Aim o Use the following directory commands pwd cd mkdir rmdir ls ls l SHELL COMMANDS

o Use the following file commands in UNIX cat cp rm mv

o Use the following commands in UNIX date tput clear who

o Use the *,? And [] wild card characters with file commands o Set file access permissions o Setuid and stickybit o Define redirection, filter and pipes o Use grep filter with the following options -n -c -v

o Use pg and wc filters

GE2155

DCE

Page 9 of 80

o Use cut and tr filters

GE2155

DCE

Page 10 of 80

GE2155

DCE

Page 11 of 80

Accessing the UNIX through Windows Start->Run->telnet 192.168.10.20 ->(Enter / OK) Commands Logging in Log in: ee<Rollno> Password: Dcelab1 Identifying the current Directory The pwd (Print working directory) command is used to display the full path-name of the current directory. Syntax $pwd<Enter> /user/bin $ Changing the current Directory The cd (change directory) command changes the current directory to the directory to the directory specified. $pwd<Enter> /usr/gomes $cd/user<Enter> $pwd<Enter> /user $ Creating a Directory The mkdir (Make directory) command is used to create directories. Syntax $mkdir prog-files<Enter> $ Removing Directory The rmdir (remove directory) removes the directory specified. $rmdir cob-prog<Enter> $

GE2155

DCE

Page 12 of 80

GE2155

DCE

Page 13 of 80

Listing the contents of a Directory The ls command is used to display the names of files and subdirectories in a directory. $ls/user/gomes<Enter> The directory name is optional with ls, if the names of the files and directories under the current directory are to be listed. Simple file Commands The cat (concentrate) command displays the contents of the file specified. $cat datal<Enter> A Sample file $ Copying Files The cp(copy) command duplicates the contents of the source file into a target file. $ cp data 1 data3 <Enter> In the above example, the contents of data1 are copied to a new file data3. If data3 already exists, its contents will be overwritten by the contents of data1. Removing Files The rm (remove) command is used to delete files. Syntax $rm data1 <Enter> $ Other Commands Date All UNIX systems maintain the current date and time. Users can display the current date and time with the date command. $date<Enter> Sat Feb 18 11:30:05 IST 1989

GE2155

DCE

Page 14 of 80

GE2155

DCE

Page 15 of 80

$tput clear The command tput clear clears the Standard output device, the screen, and positions the cursor on the top left corner of the screen. who The who command is used to display the names of all the users who are currently logged in $who<Enter> gomes dolly anita Paula $ The who am I command displays the name of the current users $ who am I <Enter> gomes $ Wildcard Characters UNIX offers the facility to perform an operation on a set of files without having to specify all the filenames on which the operation has to be performed. This is made possible by the use of certain special characters in the command in place of actual file names. The * Wildcard The * wild-card is interpreted as a string of none, one or more characters $cat c*<Enter> Here, c* will match files whose names start with c. The * wildcard can also be replaced in the command line. $cat chap*.*<Enter> The? Wildcard The? wildcard matches exactly one occurrence of any character. ls*.? tty02 2 10:30 tty02 ttyi3 tty01 tty07 Feb Feb Feb Feb 2 2 2 2 10:30 9:40 9:00 9:00

GE2155

DCE

Page 16 of 80

GE2155

DCE

Page 17 of 80

The [] Wildcard The [] wildcard can be used to restrict the characters to be matched. cat a[123] This command displays the contents of files starting with a and containing 1 or 2 or 3 after the a. i.e a1,a2,a3

GE2155

DCE

Page 18 of 80

GE2155

DCE

Page 19 of 80

vi Editor Objectives o Commands of vi o Opening and closing of files o Saving and quitting a file o Copying Text o Repeating or Undoing the last command Introduction to vi Editor UNIX has a number of editors that can process the contents of text files, whether those files data, source code, or sentences. These are line editors, such as ed and ex, which display a line of the file on the screen; and there are screen editors, such as vi and emacs, which display a part of the file on the terminal screen. vi is the most standard text editor on UNIX system vi is short for Visual Editor and is pronounced vee-eye It uses all of the regular keyboard keys for issuing commands When the keyboard keys are issuing commands, vi is said to be in command mode The vi editor is invoked by the following command at the UNIX $ prompt: Syntax vi filename<Enter> For example $vi sharn.txt [New file] <Enter> It gives a blank screen with a tilde character(~) at the beginning of each line. If the file exists, then its contents are read into memory, and also displayed on the screen. In vi, to add, change or delete text, commands have to be given. Command i A Action or Mode Insert text at current cursor position Append text after current cursor position

GE2155

DCE

Page 20 of 80

GE2155

DCE

Page 21 of 80

Commands

Command H L K J X Dd :wq :q!

Action Move to previous character Move to next character Move to up line Move to down one line Delete character at current cursor position Delete line Save all changes and quit Quit without saving changes

Opening and Closing Files vi copies the file to be edited into a buffer (an area temporarily set aside in memory), displays the buffer (through we can see only one screenful at a time), and lets you add, delete, and change text. Syntax for the vi command is: $ vi practice Since this is a new file, the buffer is empty and the screen appears as follows ~ ~ ~ practice [New File]

GE2155

DCE

Page 22 of 80

The tildes (~) down the left-hand column of the screen indicate that there is no text in the file, not even blank lines. The prompt line (also called the status line) at the bottom of the screen echoes the name and status of the file. Result Thus the vi editor concepts and shell commands and their syntax and usage were studied well and exercised successfully.

GE2155

DCE

Page 23 of 80

Ex. No. : 03 Date: Finding Odd or Even

Aim To write the Shell Script code for find weather the given number is Odd or Even Algorithm 1) Start the program 2) Read a Integer value from the user 3) Find the remainder of the given number by using the divisor 2 4) If the remainder is 0, then the number is Even else the number id Odd 5) Display the Result 6) Stop the Program Shell Script Code

GE2155

DCE

Page 24 of 80

Sample Input and Output

GE2155

DCE

Page 25 of 80

Result Thus the program for finding weather the number is even or odd is executed successfully

GE2155

DCE

Page 26 of 80

GE2155

DCE

Page 27 of 80

Ex. No. : 04 Date: Aim To write the Shell Script code for find area and circumference of the circle Algorithm 1) Start the program 2) Read the value of radius of the circle from the user 3) Find the Area and Circumference of the circle by using following formula 4) area=3.14*r*r and circumference=2*3.14*r 5) Print the results 6) Stop Shell Script Code Area and Circumference of a Circle

GE2155

DCE

Page 28 of 80

Sample Input and Output

GE2155

DCE

Page 29 of 80

Result Thus the program for finding the Area and Circumference of the circle was executed successfully.

GE2155

DCE

Page 30 of 80

Ex. No. : 05

Finding Leap Year

GE2155

DCE

Page 31 of 80

Date:

Aim To write the Shell Script code for find weather the given year is Leap year or not. Algorithm 1) Start the program 2) Read the year value from the user 3) Find the remainder of the given number by using the divisor 4 4) If the remainder is 0, then the year is Leap year else the year is not leap 5) Display the Result 6) Stop the Program Shell Script Code

GE2155

DCE

Page 32 of 80

Sample Input and Output

GE2155

DCE

Page 33 of 80

Result Thus the program for finding the leap year was executed successfully

GE2155

DCE

Page 34 of 80

GE2155

DCE

Page 35 of 80

Ex. No. : 06 Date: Biggest in Three Numbers

Aim To write a shell script to find biggest in three numbers Algorithm 1) Start 2) Read three values form the user 3) Check the following condition a>b and a>c if it is true than display A is Big 4) Else check the following condition b>c if it is true than display B is Big 5) Otherwise display C is Big 6) Stop Shell Script Code

GE2155

DCE

Page 36 of 80

Sample Input and Output

GE2155

DCE

Page 37 of 80

Result Thus the program for finding the biggest number in three number was successfully executed.

GE2155

DCE

Page 38 of 80

GE2155

DCE

Page 39 of 80

Ex. No. : 07 Date: Aim To write a shell script to do all arithmetic operations using case statement. Algorithm 1) 2) 3) 4) 5) Start Read two values from the user Display the operation to be performed Get the option from the user Using switch case select the option and do the corresponding arithmetic operation 6) Display the result 7) Stop Shell Script Code Arithmetic Operations

GE2155

DCE

Page 40 of 80

Sample Input and Output

GE2155

DCE

Page 41 of 80

Result Thus the Arithmetic Operation performing using switch case was successfully executed.

GE2155

DCE

Page 42 of 80

GE2155

DCE

Page 43 of 80

Ex. No. : 08 Date: Calculate Gross Salary

Aim To write a Shell Script code for calculate the gross salary

Algorithm
1)

Start the program Read the value of basic payment from user Calculate the gross salary, HRA, DA Calculate the gross salary by using following formula Gross=da+hra+basic

2) 3) 4)

5)

Display the result Stop

6)

Shell Script Code

GE2155

DCE

Page 44 of 80

Sample Input and Output

GE2155

DCE

Page 45 of 80

Result Thus the program for finding gross salary was verified and successfully executed.

GE2155

DCE

Page 46 of 80

GE2155

DCE

Page 47 of 80

Ex. No. : 9 Date: Aim To write a Shell Script for generate a series of natural numbers up to given limit Algorithm 1) Start the program 2) Get the limit from the user 3) Initialize i=1 4) Print the ith value if i<n 5) Increment I by 1 and goto step 4 6) Stop the program Shell Script Code Generate N natural numbers

GE2155

DCE

Page 48 of 80

Sample Input and Output

GE2155

DCE

Page 49 of 80

Result Thus the program generating natural numbers was executed successfully

GE2155

DCE

Page 50 of 80

GE2155

DCE

Page 51 of 80

Ex. No. : 10 Date: Aim

Sum of N odd numbers

To write a Shell Script to find the sum of N odd numbers Algorithm 1) Start the program 2) Read the upper limit from the user 3) Initialize the counter variable i value 1 and sum value 0 4) Check the upper limit value with counter variable if the counter variable value is lesser than upper limit then sum = sum + i 5) Increment counter variable value by 2
6)

If counter variable < upperlimit value then goto step 4

7) Stop the program Shell Script Code

GE2155

DCE

Page 52 of 80

Sample Input and Output

GE2155

DCE

Page 53 of 80

Result Thus the program for finding the sum of N odd numbers was successfully executed.

GE2155

DCE

Page 54 of 80

Ex. No. : 11 Date: GE2155

Finding Factorial

DCE

Page 55 of 80

Aim To write a C program for find the factorial of the given number. Algorithm 1)
2)

Start the program Read a number from the user Assign fact = 1 and i = 1 By using while loop check the condition i <= n if condition true then fact=fact*i Value of i is increment by 1 else goto step 5

3) 4)

5) 6)

Print the factorial of the given number Stop

Shell Script Code

GE2155

DCE

Page 56 of 80

Sample Input and Output

GE2155

DCE

Page 57 of 80

Result Thus a program to find factorial of a given number is executed successfully.

GE2155

DCE

Page 58 of 80

GE2155

DCE

Page 59 of 80

Ex. No. : 12 Date: Aim To write a Shell Script code for generate Fibonacci series up to given limit Algorithm 1) Start the program 2) Read the limit from the user 3) Assign f=-1, s=1 and i=1 4) Calculate val = f + n and i=i+1 5) Interchange the value f = n, n=val 6) Goto step 4 if limit < i 7) Display the result 8) Stop Shell Script Code Fibonacci Series

GE2155

DCE

Page 60 of 80

Sample Input and Output

GE2155

DCE

Page 61 of 80

Result Thus the program for generating the Fibonacci series was verified and successfully executed.

GE2155

DCE

Page 62 of 80

GE2155

DCE

Page 63 of 80

Ex. No. : 13 Date: Aim To write a C program for sort the numbers using arrays Algorithm 1) Open the terminal 2) Include header files 3) Declare the variables 4) Get the array limit and values from the user 5) By using nested loop we sort the elements in the array 6) Display the array elements 7) Stop Program Sorting

GE2155

DCE

Page 64 of 80

Sample Input and Output

GE2155

DCE

Page 65 of 80

GE2155

DCE

Page 66 of 80

GE2155

DCE

Page 67 of 80

Result Thus the program for sorting was compiled and successfully executed and verified the results also. GE2155 DCE Page 68 of 80

GE2155

DCE

Page 69 of 80

Ex. No. : 14 Date: Swapping by using pointers

Aim To write a C program for swapping two numbers using pointers. Algorithm 1) Start the program 2) Open vi editor 3) Press i key for entering the code 4) Include the header files 5) Declare the variables 6) Define the function 7) Swap the two values 8) Run the program 9) Display the result 10) Stop the program Program

GE2155

DCE

Page 70 of 80

Sample Input and Output

GE2155

DCE

Page 71 of 80

GE2155

DCE

Page 72 of 80

GE2155

DCE

Page 73 of 80

Result Thus the program for swapping the two values by using pointers was compiled and executed successfully.

GE2155

DCE

Page 74 of 80

GE2155

DCE

Page 75 of 80

Ex. No. : 15 Date: Functions

Aim To write a C program for addition of two integers, two doubles and two characters by using function overloading. Algorithm 1) Start the program 2) Open vi editor 3) Include the header files 4) Define a function named add with integer arguments 5) Define the function named add with double arguments 6) Define the function named add with char arguments 7) Call the function with integer, double and character values 8) Run the program 9) Display the result 10) Stop the program Program

GE2155

DCE

Page 76 of 80

Sample Input and Output

GE2155

DCE

Page 77 of 80

GE2155

DCE

Page 78 of 80

GE2155

DCE

Page 79 of 80

Result Thus the program for function overloading was verified, compiled and successfully executed.

GE2155

DCE

Page 80 of 80

S-ar putea să vă placă și