Sei sulla pagina 1di 17

Sanghvi Innovative Academy

Computer Science and Engineering Year : 2011-12

Practical File of

UNIX

Submitted To:
Mr. 0861cs091017

Submitted By:
miss. Hemlata Thakur CS III yr En. No.

CONTENTS
S.no 1. 2. 3. 4. Name
What is UNIX? Write down salient features and architecture of UNIX. What is shell in UNIX and explain its types? Write Commands for performing arithmetic operations with Unix/Linux. 4. In a company an employee is paid as under: If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of basic. If his basic salary is either equal to or above Rs. 2000, then HRA= Rs. 1000 and DA = 94% of basic salary. If the employee's salary is input through the Keyboard write a shell script to find his gross salary. Explain VI editor commands and their 3 modes of operation? 5. Explain the following commands: ls l , chmod, pwd, mkdir , bc, bc l, expr, who ,df, passwd, cat, touch,grep , cat < file1 > file2, ps, write, mail, mv 6. Write a shell script that accepts any 3 digit number and prints them in the Reverse order.

Page No.

Date of Submission

Remarks & Signature

5. 6.

7.

8.

7. Write a shell script to find the smallest of three numbers that are read from the keyboard. 8. Any integer is input through the keyboard. Write a shell script to find out whether it is an odd number or even number. 9. The marks obtained by a student in 5 different subjects are input through the keyboard. the students gets a division as per the following rules : Percentage above or equal to 60 "First Division" Percentage between 50 and 59 - "Second Division" Percentage between 40 and 49 - "Third Division"

9.

10.

Experiment No. 1
Aim :-

What is UNIX? Write down salient features and architecture of UNIX. UNIX :-

The Open Group holds the definition of what a UNIX system is and its associated trademark in trust for the industry. In 1994 Novell (who had acquired the UNIX systems business of AT&T/USL) decided to get out of that business. Rather than sell the business as a single entity, Novell transferred the rights to the UNIX trademark and the specification (that subsequently became the Single UNIX Specification) to The Open Group (at the time X/Open Company). Subsequently, it sold the source code and the product implementation (UNIXWARE) to SCO. The Open Group also owns the trademark UNIXWARE. Today, the definition of UNIX takes the form of the worldwide Single UNIX Specification integrating X/Open Company's XPG4, IEEE's POSIX Standards and ISO C. Through continual evolution, the Single UNIX Specification is the defacto and dejure standard definition for the UNIX system application programming interfaces. As the owner of the UNIX trademark, The Open Group has separated the UNIX trademark from any actual code stream itself, thus allowing multiple implementations. Since the introduction of the Single UNIX Specification, there has been a single, open, consensus specification that defines the requirements for a conformant UNIX system.

Experiment No. 2
Aim :-

What is shell in UNIX and explain its types? A Unix shell:It is the program which reads user input from the command line and executes actions based upon that input. There are two general families of Unix shells, the Bourne family and the C family. The Bourne shell was the original Unix shell. The C shell was the first competing Unix shell. tcsh is an improved variant of the C shell. The Korn Shell (ksh) and the Bourne Again Shell (bash) are improved variants of the Bourne shell.

Types of Shells in UNIX :# sh: The Bourne shell, or sh, was the default Unix shell of Unix Version 7, and replaced the Thompson shell, whose executable file had the same name, sh. It was developed by Stephen Bourne, of AT&T Bell Laboratories, and was released in 1977 in the Version 7 Unix release distributed to colleges and universities. It remains a popular default shell for Unix accounts. The binary program of the Bourne shell or a compatible program is located at /bin/sh on most Unix systems, and is still the default shell for the root superuser on many current Unix implementations. # ash: The Almquist shell (also known as A Shell or ash) was originally Kenneth Almquists clone of the SVR4-variant of the Bourne shell; it is a fast, small, POSIXcompatible Unix shell designed to replace the Bourne shell in later BSD distributions. By intention it did not feature line editing or command history mechanisms originally, because Almquist felt that such should be moved into the terminal driver. Current variants have emacs and vi modes. # dash: Debian Almquist shell (dash) is a POSIX-compliant Unix shell, much smaller than bash. It requires less disk space but is also less feature rich. dash is a direct descendant of the NetBSD version of the Almquist Shell (ash). It was ported to Linux by Herbert Xu in early 1997. It was renamed to dash in 2002.dash executes scripts faster than bash and depends on fewer libraries. It is believed to be more reliable in case of upgrade problems or disk failures. # bash: Bash is a Unix shell written for the GNU Project. The name of the actual executable is bash. Its name is an acronym for Bourne-again shell, a pun on the name of the Bourne shell (sh) (i.e. Bourne again or born again), an early and important Unix shell written by Stephen Bourne and distributed with Version 7 Unix circa 1978. Bash

was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. Bash is the default shell on most Linux systems as well as on Mac OS X and it can be run on most Unix-like operating systems. # fish: fish is a Unix shell. Its name is an acronym for friendly interactive shell. fish focuses on interactive use, discoverability, and user friendliness. The design goal of fish is to give the user a rich set of powerful features in a way that is easy to discover, remember, and use. # ksh: The Korn shell (ksh) is a Unix shell which was developed by David Korn (AT&T Bell Laboratories) in the early 1980s. It is backwards compatible with the Bourne shell and includes many features of the C shell as well, such as a command history, which was inspired by the requests of Bell Labs users. The main advantage of ksh over the traditional Unix shell is in its use as a programming language. Since its conception, several features were gradually added, while maintaining strong backwards compatibility with the Bourne shell. # csh: The C shell (csh) is a Unix shell developed by Bill Joy for the BSD Unix system. It was originally derived from the 6th Edition Unix /bin/sh (which was the Thompson shell), the predecessor of the Bourne shell. Its syntax is modeled after the C programming language. The C shell added many feature improvements over the Bourne shell, such as aliases and command history. Today, the original C shell is not in wide use on Unix; it has been superseded by other shells such as the Tenex C shell (tcsh) based on the original C shell code, but adding filename completion and command line editing, comparable with the Korn shell (ksh), and the GNU Bourne-Again shell (bash). # tcsh: tcsh (pronounced TC-Shell or T-shell) is a Unix shell based on and compatible with the C shell (csh). It is essentially the C shell with (programmable) filename completion, command-line editing, and a few other features. # es: The es shell is a command line interpreter that uses a scripting language similar to the rc shell. It is intended to provide a fully functional programming language as a Unix shell. The bulk of es development occurred in the early 1990s. Unlike other modern shells, es does not have job control. Patches to provide job control have been offered, but the currently available ones have memory leak problems. # rc: rc is the command line interpreter for Version 10 Unix, Plan 9, and Inferno operating systems. It resembles the Bourne shell, but its syntax is somewhat simpler. It was created by Tom Duff, who is better known for an unusual C programming language construct called Duffs device.

# scsh: Scsh is a POSIX API layered on top of the Scheme programming language (currently only a Scheme 48 implementation exists, but others are planned) in a manner to make the most of schemes capability for scripting. It is limited to 32-bit platforms. # sash: Stand-alone shell (sash) is a Unix shell designed for use in recovering from certain types of system failures. The built in commands of sash have all libraries linked statically, s .

Experiment No. 3
Aim: Introduction:
There are various operators supported by each shell. Our tutorial is based on default shell (Bourne) so we are going to cover all the important Bourne Shell operators in the tutorial.

There are following operators which we are going to discuss: Arithmetic Operators. Relational Operators. Boolean Operators. String Operators. File Test Operators. The Bourne shell didn't originally have any mechanism to perform simple arithmetic but it uses external programs, either awk or the must simpler program expr.

Arithmetic Operators: There are following arithmatic operators supported by Bourne Shell. Assume variable a holds 10 and variable b holds 20 then: Show Examples Operator Description Example + Addition - Adds values on either side of the operator `expr $a + $b` will give 30 Subtraction - Subtracts right hand operand from left hand operand `expr $a - $b` will give -10 * Multiplication - Multiplies values on either side of the operator `expr $a * $b` will give 200

Division - Divides left hand operand by right hand operand `expr $b / $a` will give 2 % Modulus - Divides left hand operand by right hand operand and returns remainder `expr $b % $a` will give 0 = Assignment - Assign right operand in left operand a=$b would assign value of b into a == Equality - Compares two numbers, if both are same then returns true. [ $a == $b ] would return false. != Not Equality - Compares two numbers, if both are different then returns true. [ $a != $b ] would return true. It is very important to note here that all the conditional expressions would be put inside square braces with one spaces around them, for example [ $a == $b ] is correct where as [$a==$b] is incorrect. All the arithmetical calculations are done using long integers.

Experiment No. 4

10. Aim:In a company an employee is paid as under: If his basic salary is less than Rs. 1500, then HRA = 10% of basic salary and DA = 90% of basic. If his basic salary is either equal to or above Rs. 2000, then HRA= Rs. 1000 and DA = 94% of basic salary. If the employee's salary is input through the Keyboard write a shell script to find his gross salary.

Experiment No. 5
Aim:Explain VI editor commands and their 3 modes of operation? VI editor commands :-

The default editor that comes with the UNIX operating system is called vi (visual editor). [Alternate editors for UNIX environments include pico and emacs, a product of GNU.] The UNIX vi editor is a full screen editor and has two modes of operation: Command mode commands which cause action to be taken on the file, and Insert mode in which entered text is inserted into the file. In the command mode, every character typed is a command that does something to the text file being edited; a character typed in the command mode may even cause the vi editor to enter the insert mode. In the insert mode, every character typed is added to the text in the file; pressing the <Esc> (Escape) key turns off the Insert mode. While there are a number of vi commands, just a handful of these is usually sufficient for beginning vi users. To assist such users, this Web page contains a sampling of basic vi commands. The most basic and useful commands are marked with an asterisk (* or star) in the tables below. With practice, these commands should become automatic. NOTE: Both UNIX and vi are case-sensitive. Be sure not to use a capital letter in place of a lowercase letter; the results will not be what you expec

The vi editor can be a little difficult to learn, so I've been writing some vi tutorials here recently. One of the first things to know about vi is that it typically functions in three different modes:

Command mode Insert mode Last line mode Here's a quick description of each vi mode.

vi command mode When you first start editing a file with the vi editor you will be in vi command mode. In this mode you can issue many vi commands, including commands like insert, append, and delete, and other search and navigation commands that let you move around your file.

Possibly the most important thing to know is that when you're in command mode you can't insert text immediately. You first need to issue an insert, append, or open command to insert text. These commands are actually fairly simple, and I've documented them in this vi insert commands tutorial.

vi insert mode Once you issue a vi insert, append, or open command, you will be in vi insert mode. If you're working with a modern vi or vim implementation, your vi editor is typically configured to show the current mode of operation, so when you go into insert mode, you'll see a text string like this on the last line of your vi editor window:

-- INSERT --At this point you can (a) type text into your file and (b) use the arrow keys to navigate around your file just as you would do with

any other text editor. (There may be some complications with older Unix systems, like HP-UX systems, but this statement is generally true.) vi last line mode:The last vi mode is known as vi last line mode. You can only get to last line mode from command mode, and you get into last line mode by pressing the colon key, like this:

: After pressing this key, you'll see a colon character appear at the beginning of the last line of your vi editor window, and your cursor will be moved to that position. This indicates that vi is ready for you to type in a "last line command".

From this vi command prompt you can do all sorts of really amazing things. You can do simple things, like quitting your vi session, like this:

:q or this:

:q! or this:

Experiment No. 6
Aim:
Explain the following commands: ls l , chmod, pwd, mkdir , bc, bc l,

expr, who ,df, passwd, cat, touch,grep , cat < file1 > file2, ps, write, mail, mv

ls -l :long listing, permissions, buildtimes, owner, points to links, etc chmod :(a=all u=user g=group o=other) +/-/= (r=read w=write x=execute) simplest way of changing permissions. eg chmod a-w <filename> : removes write permissions w for all a chmod u+x <filename> : adds execute permissions x for user u(the user is generally the person who created the file, and therefore the owner) - removes ,+ adds, = makes permissions exactly as specified In the long listing, permissions are specified user/group/other as in rwxr-xr-x 421= rwx, as in chmod 755 <filename> means rwx for user, r and x for group and others chmod 4777 : (4 = u+s) : Adding the set user id or suid bit. When you run the file, you become the user/owner : rwsrwxrwx In front of the whole lot there are sometimes other characters: b = block device, c = character device, - =an ordinary file, d = directory. Directory permissions: t at the end denotes a sticky bit - everyone has permissions but only user can alter files. 1777 1 = +t passwd :use to change password. Follow instructions. As root: passwd <username> does not require old password to be entered, can be changed directly mkdir :create directory cat:cat filename : views contents of file. Use -n option to number lines. cat filename > anotherfilename.txt sends output to a file that is created or overwritten cat filename >> anotherfilename.txt appends output to selected file
cat < file1 > file2:cat file1.txt file2.txt > file3.txt : contents of two files can be combined The cat command can be used as a quick text editor: cat > friends.txt

Joan Scott Meredith Tim [EOT](Ctl -d) ps:-

ps : processes running ps ax or ps -e :all users and processes without a controlling terminal (tty) ps axf :as above, showing child processes mv file1 file2 : rename or move files and directories To rename a directory, specify the old directory name and new directory name: mv mydir newdir mv -i file1 file2 asks for permission to overwrite an existing file. mv -b : creates a backup mv -bi file1 file2 mail :Opens the mail program with the first message in the mail (if applicable). Mail is a very un-friendly e-mail program. I'd recommend sticking with pine. However, you can send files easily with mail by typing C$ mail jschmoe@wjh.harvard.edu < filename who :- show who is logged on write:Sends a message directly to the user specified. Useful if you want to get someone's attention who's logged on. (Beware, though, some people are very irritated by write messages...) To end the write session, hit control-D touch:touch is a standard Unix program used to change a file's access and modification timestamps. It is also used to create a new empty file. grep:Grep searches the named input FILEs (or standard input if no files

are named, or the file name - is given) for lines containing a match to the given PATTERN. By default, grep prints the matching lines. df :df (abbreviation for disk free) is a standard Unix computer program used to display the amount of available disk space for filesystems on which the invoking user has appropriate read access. df is usually implemented by reading the mtab file or using statfs.

Experiment No.7
Aim:Write a shell script that accepts any 3 digit number and prints them in the Reverse order.

Experiment No. 8
Aim:Any integer is input through the keyboard. Write a shell script to find out whether it is an odd number or even number

Experiment No.9
Aim:Any integer is input through the keyboard. Write a shell script to find out whether it is an odd number or even number.

Experiment No. 10
Aim:The marks obtained by a student in 5 different subjects are input through the keyboard. the students gets a division as per the following rules : Percentage above or equal to 60 "First Division" Percentage between 50 and 59 - "Second Division"

Percentage between 40 and 49 - "Third Division" Percentage less than 40 "Fail" Write a shell script to calculate the division obtained by the student.

Potrebbero piacerti anche