Você está na página 1de 11

Scribd Upload a Document Search Documents

Explore
Documents
Books - Fiction
Books - Non-fiction
Health & Medicine
Brochures/Catalogs
Government Docs
How-To Guides/Manuals
Magazines/Newspapers
Recipes/Menus
School Work
+ all categories
Featured
Recent
People
Authors
Students
Researchers
Publishers
Government & Nonprofits
Businesses
Musicians
Artists & Designers
Teachers
+ all categories
Most Followed
Popular
chilkasrikanth
Account
Home
My Documents
My Collections
My Shelf
View Public Profile
Messages
Notifications
Settings
Help
Log Out
1First Page
Previous Page
Next Page
/ 25Sections not available
Zoom Out
Zoom In
Fullscreen
Exit Fullscreen
Select View Mode
View Mode
Book
Slideshow
Scroll Readcast
Add a Comment
Embed & Share
Reading should be social! Post a message on your social networks to let others k
now what you're reading. Select the sites below and start sharing.
Link account
Link accountReadcast this DocumentReadcast Complete!
Click 'send' to Readcast!
edit preferences
Set your preferences for next time...
Choose 'auto' to readcast without being prompted.
chilkasrikanthLink accountLink accountAdvancedCancel
Add a Comment
SubmitCharacters: 400Share & Embed
Add to Collections
Download this Document for FreeAuto-hide: off

Unix & Shell Programming 1 Ashoka College of Computer Education Submitted by:
Name: Prabhat Kumar
Class: BCA IInd
Class Roll no. 06
Examination Roll no ...
Submitted to: Mr. Ashu Verma Concerned Lect. in Operating system Ashoka college
of Computer Education Unix & Shell Programing Session - 2009 -10 Certificate Th
is is certified that the
practical file belongs to
Prabhat Kumar, Class roll
no. 06 and Examination
Roll no of session
2009-10 and has
completed all the
practical in the college
computer lab under our
guidance and his
behavior in the college
is good.
Unix & Shell Programming 2 Ashoka College of Computer Education Unix & Shell Pr
ogramming 3 Teacher Incharge Principal Index Ashoka College of Computer Educatio
n Unix & Shell Programming 4 Ashoka College of Computer Education S. no. Name
of Practical Page no. Remarks 1Unix, Types of Unix. 1 2Kernel, Shell, Programs.
2 3Unix Commands. 3 - 12 4WAP to find addition of two numbers. 13 5WAP to find g
reater between two numbers. 14 6WAP to find greatest between three numbers. 15 7
WAP to find factorial of a number. 16 8WAP to generate Fibonacci series. 17 9WAP
to enter the marks and obtain grade. 18 10WAP to find n natural numbers using l
oop. 19 11WAP to generate n natural number in inverse series. 20 12WAP to accept
number from user and display it. 21 13WAP whether the number is even or odd. 22
14WAP to print a table of any number. 23 15WAP to calculate the T.A , H.R.A and
D.A of any employee. 24 16WAP to show state of first character of word. 25 17WA
P to print the contents of a table. 26 18WAP to enter any character from user. 2
7 Unix & Shell Programming 5 UNIX UNIX is an operating system which was first
developed in the 1960s, by Ken Thompson. It is a
popular operating system available for micro and
main frame for scientific and commercial use. By
operating system, we mean the suite of programs
which make the computer work. It is a stable, multi-
user, multi-tasking system for servers, desktops and
laptops. UNIX is designed for effectiveness of
Application Software Development, System Software
Development etc.
UNIX systems also have a graphical user interface
(GUI) similar to Microsoft Windows which provides an
easy to use environment. However, knowledge of
UNIX is required for operations which aren't covered
by a graphical program, or for when there is no
windows interface available, for example, in a telnet
session. In 1974, UNIX was licensed to Universities
for educational purposes
Types of UNIX There are many different versions of UNIX, although
they share common similarities. The most popular
varieties of UNIX are Sun Solaris, GNU/Linux, and
MacOS X. The UNIX operating system is made up of three parts; the kernel, the sh
ell and the programs. Ashoka College of Computer Education Unix & Shell Progra
mming 6 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 communications in
response to system calls.
Shell The shell acts as an interface between the user and
the kernel. When a user logs in, 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 and arranges for them
to be carried out. The commands are themselves
programs: when they terminate, the shell gives the
user another prompt.
Programs A program is the collection of instructions which are
collectively arranged and organized for execution for
performing certain operations. UNIX is made up of
no. of programs, shell and kernel.
UNIX COMMANDS ?ls command : - This command lists your files. Syntax: - # ls Outp
ut:- Ram Dushyant bharat kittu Prabhu rakesh vikas Kishore ?ls-l command:- Lists
your files in long format , which contains lots of useful information, e.g. the ex
act size of file ,who owns the file and who has the right to look at it, and whe
n it was last modified. Syntax:-#ls -l Ashoka College of Computer Education Un
ix & Shell Programming 7 Output:- akhil
Rohit
pankaj
sunil
raka
?ls -a command :- Lists all files, including the ones whose filenames begin in a
. there are any more options. For example to list files by size, by date, recurs
ively etc. Syntax:- # ls [a]* Output:- Akhil Aryan Aniket Atinder ? Is [a e i o
u]* :- This command is used to open the file which started with vowels. Syntax :
-# Is [a e i o u]* Output:- Akhil Ankush Irani Uma orkut umang ?Is [0-9]* :- Thi
s command is used to open the file which starts with number. Syntax:-# Is[0-9]*
Output:- 786 2bca 1bca 86 ?UNAME command : - This command is used to know about
the operating system on which we work. Syntax::- --#uname Output:- Linux ?Uname
r command : - This command is used to know about the version of operating system
. Syntax: -# un a me -r Output:- Ashoka College of Computer Education Unix & S
hell Programming 8 2.6.18-53.el5 ?ls fx command: - This command is used to open
the which list of executable file. Syntax:-#ls-fx Output:- arap.exe window.exe b
cap.exe maon.exe rifgt.exe prog.exe ?BC command : - This command is used to calc
ulator. Syntax: - # bc Output:- 10+21 = 21 ^D ?xcalc command:-This command is us
ed to display the calculator graphically. Syntax:- # xcalc ?mkdir command:-This
command is used to make directory. Syntax: -#mkdir filename. Example: -#mkdir du
shyant ?Remove command:- This command is used to remove the file . Syntax: -#rm
filename
Example: -#rm prabhu
Output::-
remove regular file prabhu ? Y ?CAT > command: -It is used to create a file. Syntax
: -#cat > filename
Example: -#cat > khan
Output:-
My name is khan. Shahrukh khan ^d {Ctrl + D} ?CAT command: -It is also used to v
iew a file. Syntax:- #cat filename
Example: -#cat khan
Output:-
My name is khan. Shahrukh khan Ashoka College of Computer Education Unix & She
ll Programming 9 ?who command: -This command is used to display the user name, t
erminal no. and login time Syntax: -#who Output:- romy .tnfs 44.03 atin .tpgs 23
.90 ?p wd command: -This command is used to know about the present working direc
tories. Syntax: -#p w d Output:- Root prabhu ?tput clear command::- - - This com
mand is used to clear the screen. Syntax: -#tput clear ?man command::- -- This c
ommand is used when we need help then we use man command. Syntax: -#man ls ?ls -
axf command: -This command is used to view the hidden files. Syntax: -#ls-axf Ou
tput:-prabhat Kishore ?cd command: - This command is used to change directories.
Syntax: -#cd filename Example:- #cd prabhat ?ps command: - This command is used
to see all the processes. Syntax: -#p s Output:- PID TTY TIME CMD 9216 pts/0 00
.00.00 bash 9824 pts/0 00.00.00 ps ?wc command : - This command is used to displ
ay the lines, word and character in a file. Syntax:- #wc file name
Example:- #wc dushyant
Output: -
2 23 10:dushyantAshoka College of Computer Education Unix & Shell Programming
10 ?Is *.c command : - This command is used to display all the files with extens
ion .c . Syntax:- #ls *.c Output: -Dushyant prabhat amar ?Touch command : - This
command is used to create the empty file. Syntax::- --#touch
Example::- -- #touch dushyant
Output ::--- Empty file
?cmp command : - This command is used to compare the files. Syntax:- #cmp filena
me1 filename2
Example:- #cmp Kishore prabhu
Output: -
Kishore prabhu: same: line=15 ?Date command : - This command is used to see the
current date. Syntax:-#d a te Output: - 26-jan-2010 ?cal command : - This comman
d is used to display the current calendar. Syntax:- #cal Output: - January Sun m
on tue wed thu fri sat 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19
20 21 22 23 24 25 26 27 28 30 31 ?tty command : - This command is used to know a
bout the terminal number. Syntax:-tty Output: - /device/pts/0 ?tty command : - T
his command is used for setting the terminal. Syntax:- #stty Output: -Speed=5463
0 baud; Line=0; Eol=m_^? ?cat > command : - This command is used to create the h
idden files. Ashoka College of Computer Education Unix & Shell Programming 11
Syntax:- #cat > .filename Example:- #cat > prabhu ?move command : - This command
is used to move the contents of one file to another file. Syntax: -#mv source d
estination Example: -#mv Kishore prabhat Output:-
File moved. ?cp command : - This command is used to copy the contents of one fil
e to another file. Syntax:- #cp source file destination file
Example:- #cp Kishore prabhu
Output: -
File copied. ?Time command : - This command used to show the cumulative amount o
f c.p.u time used. Syntax:- #time Output: -12:30 am ?ps-a command : - This comma
nd is used to list all processes belonging to any terminal . Syntax:- #ps-a Outp
ut: - PID TTY TIME CMD 2912 pts/0 00.00.00 cat 3241 pts/0 00.00.00 cat ?ps-e com
mand : - This command used to display the list of everything i.e. all processes.
Syntax:-#p s - e ?ps-f command : - This command is used fully, instead of brief
, listing : gives additional detail. Syntax:- #ps-f ?ps-I command : - This comma
nd is used for long listing ,gives more detail, including priority, nice value e
tc. Syntax:-#p s - l ?kill command : - This command can be used by the owner of
a process to terminate its execution. Syntax:- #kill process number Example:- #k
ill 43 Ashoka College of Computer Education Unix & Shell Programming 12 Output
: -Process killed. ?sleep command : - This command delays the execution for a sp
ecified no. of seconds it can be used to start a command after a specified pause
. Syntax:- #sleep 10; ls ?history command : - This command is used to know about
the details of whole commands used by the user after login. Syntax:-#h i s to r
y Output: - 24 cat > prabhu 25 Is ?g rep command : - This command is used to se
arches for specified patterns of characters with in its input. If the pattern is
found it display the line containing the patterns. Syntax:- # grep on cities ?fin
d command : - This command is useful facility for operational users, it enables
files conforming to some name or attribute description to be located within a di
rectory tree structure.
Syntax:- # find ?chmod command : - This command changes the permission informati
on associated with a file. Every file (including directories, which Unix treats
as files) on a Unix system is stored with records indicating who has
permission to read, write or execute the file, abbreviated as r, w and x.
These permissions are broken down for three categories of user: first,
the owner of the file; second, a group with which both the user and the
file may be associated; and third, and all other users. These categories
are abbreviated as u for owner (or user), e.g. for group and o for other.
Syntax:- chmod u,o,g+prabhu To allow yourself to execute a file that you own nam
ed my file, enter:Syntax:- chmod u+x rakesh To allow anyone who has access to th
e directory in which my file is stored to read or execute my file, enter: Ashoka
College of Computer Education Unix & Shell Programming 13 Syntax:- chmod o +
rx roop ?vi command : - This command starts the vi text editor to edit a file na
med my file in the current directory, enter Syntax:- vi prabhat ?Rename command
: - You can also use the mv command to rename and to move directories. When you
type the command Syntax:- mv prabhu prabhat The directory called prabhu will be
given the
new name prabhat as long as a directory called prabhat already
existed before the mv command was issued, the result would be to put
the directory prabhu and its files into the directory prabhat.
Shell Scripting ? WAP to find addition of two numbers:- #vi prabhu
Echo enter first number
Read $a
Echo enter second number
Read $b
Echo expr $a + $b
Ashoka College of Computer Education Unix & Shell Programming 14 :wq #sh prabh
u Output Enter first number 2
Enter second number 1
3
?WAP to find greater between two numbers:- # vi prabhu
Echo enter first number
Read $a
Echo enter second number
Read $b
If $a-gt $b
Then
Echo a is greater
Else b is greater
Fi
:wq
#sh prabhu
Ashoka College of Computer Education Unix & Shell Programming 15 Output:- Ente
r the first number 31 Enter the second number 13 a is greater ?WAP to find great
est between three numbers:- # vi honey
Echo enter first number
Read $a
Echo enter second number
Read $b
Echo enter third number
Read $c
If [$a-gt $b]-a [$a-gt $c]
Echo a is greater
Else if [$b-gt $a]-a [$b-gt $c]
Echo b is greater
Else
Echo c is greater
fi
:wq
#sh honey
Output:- Enter first number 8
Enter second number 5
Enter third number 9
c is greater
Ashoka College of Computer Education Unix & Shell Programming 16 ?WAP to find
factorial of a number:- #vi honey
Echo enter a number
Read $a
If [$n-lt0]
Echo no factorial of negative number.
Else if[$n==0]
Echo factorial of zero is 1.
Else
While[$n-gt1]
Do
fact=expr $fact/*$n
n=$n 1
Done
Echo factorial is fact $fact
fi
:wq
#sh honey
Output:- Enter a number 0
factorial of zero is 1.
Enter a number 5
factorial is 120
?WAP to generate Fibonacci series:- #vi prabhu
Echo enter the limit
Read limit
a=0
b=1
c=0
while($c lt $limit)
Ashoka College of Computer Education Unix & Shell Programming 17 do
c= expr $a+$b
echo $c
a= $b
b= $c
done
:wq
#sh prabhu
Output:- Enter the limit 10 0 1 1 2 3 5 8 13 21 34 ?WAP to enter the marks and o
btain grade:- # vi prabhu
Echo enter the marks of five subjects
Read m1 m2 m3 m4 m5
Per= expr\($m1+$m2+$m3+$m4+$m5|)/*5
If [per-ge75]
Then
Echo Distinction
fi
if[per-ge60-a le74]
then
echo grade A
fi
if[per-ge50-a le59]
then
echo grade B
fi
if[per-ge33-a le49]
Ashoka College of Computer Education Unix & Shell Programming 18 then
echo grade C
else
echo fail
fi
:wq
#sh prabhu
Output: - Enter the marks 60 grade A ?WAP to find n natural number using for loo
p:- #vi prabhu
i=1
While($i-le10)
Do
Echo $i
i= expr $i+1
Done
:wq
#sh prabhu
Output:- Ashoka College of Computer Education Unix & Shell Programming 19 1 12
345689 ?WAP to generate n natural number in inverse series: - #vi prabhu
i=10
While($i-le1)
Do
Echo $i
i= expr $i-1
Done
:wq
$sh prabhu
Output:- 9 8 7 6 5 4 3 2 1 0 ?WAP to accept number from user and display it: - #
vi prabhu
Echo enter the number from 1 to 3
Read a
Ashoka College of Computer Education Unix & Shell Programming 20 Case $a in 1)
.echo you have entered 1 ;; 2). echo you have entered 2 ;; 3). echo you have ent
ered 3 ;; *). Echo you have entered wrong choice I say 1 to 3 ;; esac
done
:wq
$sh prabhu
Output: - Enter the number 5 You have entered wrong choice I say 1 to 3 ?WAP whe
ther the number is even or odd: - #vi prabhu
Echo enter the number
Read a
If ($a%2 eq0)
Echo a is even
Else
Echo a is odd
fi
:wq
$sh prabhu
Ashoka College of Computer Education Unix & Shell Programming 21 Output:- Ente
r the number 8 a is even ?WAP to print a table of any number: - #vi honey
Echo enter the number
Read n
Echo enter the limit
Read c
C=1
While($c-le10)
X= expr $n * $c=$x
:wq
$sh honey
Output:- Enter the number 3
Enter the limit 10
3*1=3
3*2=6
3*3=9
3*4=12
3*5=15
3*6=18
Ashoka College of Computer Education Unix & Shell Programming 22 3*7=21
3*8=24
3*9=27
3*10=30
?WAP to calculate the T.A , H.R.A and D.A of any employee: - #vi prabhu
Echo enter basic salary
Read $bs
If[bs-lt1500]
Then
H.R.A= echo $bs\*10/100/bc
D.A= echo $bs\*90/100/bc
Else
H.R.A=500
D.A= echo $bs\*98/100/bc
fi
G.S= echo $bs + $H.R.A + $D.A/bc
Echo gross salary=Rs.$G.S
Done
:wq
$sh prabhu
Output: - Enter the basic salary Gross salary =4460 ?WAP to show state of first
character of word: - #vi prabhu Ashoka College of Computer Education Unix & Sh
ell Programming 23 Echo enter any word from user
Read word
Case $word in
[a e i o u]*) echo you have enter vowels in small letters
;;
[A E I O U]*) echo you have enter vowels in capital letters
;;
[a-z]*) echo you have enter consonants in small letters
;;
[A-Z]*) echo you have enter consonants in capital letters
;;
*) echo you have enter wrong choice
;;
Esac
Done
:wq
$sh prabhu
Output:- Enter the word prabhat You have entered consonant in small letter. ?WAP
to print the contents of a table: - #vi prabhu
For i in 2,4 ,3
Do
c=1
While($c-le10)
Do
t= expr $i * $c
Echo $t
c= expr $c+1
Done
i= expr $i+1
Done
Ashoka College of Computer Education Unix & Shell Programming 24 :wq $sh prabh
u Output:- 2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
?WAP to enter any character from user: - #vi prabhu
Echo enter any character
Read char
Case $char in
[a-z])Echo you have entered small letters.
;;
[A-Z]) Echo you have entered capital letters.
;;
[0-9] echo you have entered digits.
;;
*)
Echo you have have wrong choice.
;;
Esac
Done
:wq
$sh prabhu
Ashoka College of Computer Education Unix & Shell Programming 25 Output:- Ente
r any character T You have entered capital letters. Ashoka College of Computer E
ducation
Shell ProgrammingDownload this Document for FreePrintMobileCollectionsReport Doc
umentReport this document?
Please tell us reason(s) for reporting this document

Spam or junk
Porn adult content
Hateful or offensive
If you are the copyright owner of this document and want to report it, please fo
llow these directions to submit a copyright infringement notice.
Report Cancel
This is a private document.
Info and Rating
Reads:1,396Uploaded:02/13/2010Category:Books - Fiction>Children's LiteratureRate
d:Dont forget to download
unixshell programmingprabhat kumarpractical fileeven numberodd numberssalarycalc
ulatewhether(more tags)unixshell programmingprabhat kumarpractical fileeven numb
erodd numberssalarycalculatewhetheracceptsdisplayspfhradigitshell scriptdigits(f
ewer)prabhat22kumar89
Ads by Google
-Shell Scripting Training
-Best Redhat Partner for 3 years
-Linux Shell Scripting Courses
www.networknuts.net
Red Hat Linux Training
RHCE, RHCSS Training & Exam
Best Red Hat training in Hyderabad
www.cossindia.net
Windows Programming Books
Expert C++ programming tips/tricks
for windows programmers. Go now!
drdobbs.com/go-parallel/cpp

Share & Embed


Related Documents
PreviousNext p. p. p. p. p. p. p. p. p. p. p. p.
More from this user
PreviousNext89 p.9 p.25 p.21 p.
Recent Readcasters
Add a Comment

SubmitCharacters: 400
Print this document
High Quality
Open the downloaded document, and select print from the file menu (PDF reader re
quired).
Download and Print
Add this document to your Collections
This is a private document, so it may only be added to private collections.
+ Create a New Collection
Name:
Description:
Collection Type:public - locked public - moderated private
public locked: only you can add to this collection, but others can view it
public moderated: others can add to this collection, but you approve or reject a
dditions
private: only you can add to this collection, and only you will be able to view
it
Save collectionCancel
Finished? Back to Document
Upload a Document Search Documents Follow Us!scribd.com/scribdtwitter.com/scrib
dfacebook.com/scribdAboutPressBlogPartnersScribd 101Web StuffScribd StoreSupport
FAQDevelopers / APIJobsTermsCopyrightPrivacyCopyright © 2010 Scribd Inc.

Você também pode gostar