SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
UN
NEIL M
NIX
MATHEW
PRO
W - A23
OGR
3247100
RAM
002 - 3C
MMIN
CS4 – Y3
NG L
305
LABB
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
1
INDEX
UNIX LAB FILE
1. WHAT IS UNIX? 2
2. UNIX STRUCTURE 3
3. DIFFERENCE BETWEEN UNIX AND WINDOWS 4
4. BASIC UNIX COMMANDS 5
5. VI EDITOR 12
6. SHELL SCRIPTING 13
7. LOOPING SYNTAX 14
8. DESCISION MAKING SYNTAX 15
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
2
WHAT IS UNIX?
The UNIX operating system is a set of programs that act as a link between
the computer and the user.
The computer programs that allocate the system resources and coordinate all
the details of the computer's internals is called the operating system or
kernel.
Users communicate with the kernel through a program known as the shell.
The shell is a command line interpreter; it translates commands entered by
the user and converts them into a language that is understood by the kernel.
• Unix was originally developed in 1969 by a group of AT&T employees
at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy,
and Joe Ossanna.
• There are various Unix variants available in the market. Solaris Unix,
AIX, UP Unix and BSD are few examples. Linux is also a flavour of Unix
which is freely available.
• Several people can use a UNIX computer at the same time; hence
UNIX is called a multiuser system.
• A user can also run multiple programs at the same time; hence UNIX
is called multitasking.
The ma
Kernel:
most of t
Shell: T
your term
shell use
famous s
Comma
your day
utilities.
3rd party
Files an
directorie
ain concept
The kernel
the tasks lik
he shell is t
minal, the s
es standard
shells which
nds and Ut
y to day ac
There are
y software.
nd Director
es. These d
NEIL M
UN
t that unit
is the hea
ke memory
the utility th
shell interpr
syntax for a
h are availab
tilities: The
ctivities. cp,
over 250 s
All the com
ries: All dat
irectories ar
MATHEW – A2
NIX S
tes all ver
art of the o
managemen
hat processe
rets the com
all comman
ble with mos
ere are vario
mv, cat an
standard com
mands com
ta in UNIX
re organized
2324710002 –
STRUC
rsions of
operating sy
nt, task sch
es your requ
mmand and
ds. C Shell,
st of the Un
ous comma
nd grep etc.
mmands plu
me along wit
is organized
d into a tree
– 3CS4 – Y33
CTURE
UNIX is t
ystem. It in
heduling and
uests. When
calls the p
, Bourne Sh
ix variants.
nd and utili
are few ex
us numerou
h various op
d into files.
e-like struct
305
E
he followin
nteracts wit
d file manag
n you type i
program tha
hell and Kor
ties which y
xamples of
us others p
ptional optio
All files are
ure called t
ng four ba
h hardware
gement.
n a comma
at you want
n Shell are
you would u
commands
provided thr
ons.
e organized
he file syste
3
asics:
e and
nd at
. The
most
use in
s and
rough
d into
em.
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
4
DIFFERENCE BETWEEN
UNIX & WINDOWS
NO: UNIX WINDOWS
1 It is a Free Source OS. It is a licensed OS.
2
Less administration and maintenance is
needed in maintaining a UNIX system
More administration and maintenance is
needed in maintaining a Windows system
3 UNIX uses daemons. Windows has service processes.
4 UNIX is more secure. Windows is more vulnerable.
5
Unix is much better at handling multiple
tasks for a single user or for multiple
users than windows.
Windows is inferior in this regard.
6
UNIX preferred by programmers for its
more flexible nature.
Windows preferred by less sophisticated
users.
7
When a new process is created by a UNIX
application, it becomes a child of the
process that created it.
Windows processes on the other hand do not
share a hierarchical relationship
8
It uses the Unix file system (UFS) also
known as Fast File System (FFS)
Windows uses the
FAT32 and NTFS File system.
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
5
BASIC
UNIX COMMANDS
The various commands are:
who
who : Shows other nodes connected to same server.
who am I : Shows your node.
$ who am i
aib ttyp1 Jul 20 02:19
$ who
aib ttyp0 Jul 20 00:58
aib ttyp1 Jul 20 02:19
aib ttyp2 Jul 20 02:19
aib ttyp3 Jul 20 02:22
aib ttyp4 Jul 20 02:22
aib ttyp5 Jul 20 02:14
aib ttyp6 Jul 20 02:05
aib ttyp7 Jul 20 02:06
aib ttyp8 Jul 20 02:18
aib ttyp9 Jul 20 02:06
aib ttyp10 Jul 20 02:15
pwd
pwd : Present Working Directory
$ pwd
/usr/aib
Banner
banner <name> : display <name> in a banner-like format
$ banner SCIENCE
##### ##### ### ####### # # ##### #######
# # # # # # ## # # # #
# # # # # # # # #
##### # # ##### # # # # #####
# # # # # # # # #
# # # # # # # ## # # #
##### ##### ### ####### # # ##### #######
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
6
cal
cal : Calender
$ cal 2011
2011
Jan Feb Mar
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 1 2 3 4 5 1 2 3 4 5
2 3 4 5 6 7 8 6 7 8 9 10 11 12 6 7 8 9 10 11 12
9 10 11 12 13 14 15 13 14 15 16 17 18 19 13 14 15 16 17 18 19
16 17 18 19 20 21 22 20 21 22 23 24 25 26 20 21 22 23 24 25 26
23 24 25 26 27 28 29 27 28 27 28 29 30 31
30 31
Apr May Jun
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6 7 1 2 3 4
3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11
10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18
17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25
24 25 26 27 28 29 30 29 30 31 26 27 28 29 30
Jul Aug Sep
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 1 2 3 4 5 6 1 2 3
3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10
10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17
17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24
24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30
31
Oct Nov Dec
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 1 2 3 4 5 1 2 3
2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10
9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17
16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24
23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31
30 31
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
7
date
date +% _ : Shows date, with specified formats
$date
Wed Jul 20 02:26:01 IST 2011
$ date +%H <-- Hours (Time Capital)
02
$ date +%M <-- Minutes
26
$ date +%S <-- Seconds
19
$ date
Wed Jul 20 02:26:31 IST 2011
$ date +%d <-- Day (Date LowerCase)
20
$ date +%m <-- Month
07
$ date +%y <-- Year (two digits)
11
$ date +%Y <-- Year (all four digits)
2011
$date +%T <-- Time
02:27:14
touch
touch <filename> : Creates files without data
cat
cat > (existing/new filename) : Write data to file (also creates)
cat < (existing filename) : Read data from file
$ touch FOLM1 FOLM2 FOLM3
$ cat > FOLM2
Yosh.
$ cat > FOLM1
DOOM DOT.
$ cat < FOLM2
Yosh.
$ cat < FOLM1
DOOM DOT.
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
8
mv
mv <filename1> <filename2> : Renames file from 1 to 2
cp
cp <filename1> <filename2> : Copies from one to another
rm
rm <filename1> : deletes file
$ touch Olaf
$ cat > Olaf
Boom Box Reloaded.
$ cat < Olaf
Boom Box Reloaded.
$ mv Olaf Heimer <-- Renamed
$ cat < Olaf <-- Therefore Olaf no longer exists
Olaf: cannot open
$ cat < Heimer
Boom Box Reloaded.
$ rm Heimer <-- Deleted
$ cat < Heimer
Heimer: cannot open
$ touch dwarf
$ cat > dwarf
Ain't I small?
$ cat <dwarf
Ain't I small?
$ cp dwarf Elf <-- Copy
$ cat <Elf
Ain't I small?
-i
<command> -i <files> : With Permission
$ rm -i mini miniME
remove mini ? y
remove miniME ? n
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
9
wc
wc <filename> : Word Count ( lines, words, characters)
-l : only lines
-w : only words
-c : only characters
-wl : words & lines
-wc : words & characters
-lc : lines & characters
$ cat < PUMA2
Jump & move it.
Jump & move it..
Jump & move it...
Yo!
$ wc PUMA2
4 13 55 PUMA2
$ wc -w PUMA2
13 PUMA2
$ wc -c PUMA2
55 PUMA2
$ wc -l PUMA2
4 PUMA2
Head
head -n <filename> : displays the first n lines of a file
Tail
tail -n <filename> : displays the last n lines of a file
$ cat < PUMA2
Jump & move it.
Jump & move it..
Jump & move it...
Yo!
$ head -1 PUMA2
Jump & move it.
$ tail -2 PUMA2
Jump & move it...
Yo!
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
10
Sort
sort <filename> : Sorts files taking each line as separate entity
sort -r <filename> : reverse order (descending)
sort -o<to_filename> <from_filename> : save sorted file
sort <filename> <filename2> : Combines both and sorts it all.
sort -o<TO_file> <FROM_file1> <FROM_file2> : Saves the combined and sorted.
-m : treats each file as an entity instead of the lines within it
-u : avoids repetition when common entities from 2 files repeat
$ cat > JLA
Clark Kent
Bruce Wayne
Diana
Barry Allen
Hal Jordan
Arthur Curry
J'onn J'onzz
$ sort JLA
Arthur Curry
Barry Allen
Bruce Wayne
Clark Kent
Diana
Hal Jordan
J'onn J'onzz
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
11
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
12
VI EDITOR
Vi editor, is a widely-used and popular UNIX-based text editor.
Like most UNIX system interfaces and other text editors, it lets you control
the system by using the keyboard rather than a combination of mouse
selections and keystrokes. The succinctness of the interface makes it highly
useful for people who work at a computer all day, especially programmers
entering or manipulating language statements.
There are two modes in the Vi Editor.
1. Command Mode
2. Insertion Mode
The editor begins in command mode, where the cursor movement and text
deletion and pasting occur. Insertion mode begins upon entering an insertion
or change command. [ESC] returns the editor to command mode. Most
commands execute as soon as you type them except for "colon" commands
which execute when you press the return key.
ENTERING THE INSERT MODE
a append text, after the cursor;
i insert text, before the cursor;
R enter Overtype Mode;
A append text, after end of line;
I insert text, before first non-whitespace character;
o open new line below cursor in Insert Mode;
O open new line above cursor in Insert Mode;
EXITING THE INSERT MODE
ESC Exit insertion mode and return to command mode
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
13
SHELL SCRIPTING
A shell script is a text file that contains a sequence of commands for a
UNIX-based operating system. It's called a shell script because it combines
into a single file (script) a sequence of commands that would otherwise have
to be presented to the system from a keyboard one at a time.
A shell script is usually created for command sequences for which a user has
a repeated need. You initiate the sequence of commands in the shell script by
simply entering the name of the shell script on a command line.
Often, writing a shell script is much quicker than writing the equivalent code
in other programming languages. The many advantages include easy program
or file selection, quick start, and interactive debugging. A shell script can be
used to provide a sequencing and decision-making linkage around existing
programs, and for moderately-sized scripts the absence of a compilation step
is an advantage.
On the other hand, shell scripting is prone to costly errors. Inadvertent typing
errors such as rm -rf * / are folklore in the Unix community; a single extra
space converts the command from one that deletes everything in the sub-
directories to one which deletes everything - and also tries to delete
everything in the root directory. Similar problems can transform cp and mv
into dangerous weapons, and misuse of the > redirect can delete the
contents of a file. This is made more problematic by the fact that many UNIX
commands differ in name by only one letter: cp, cd, dd, df, etc.
Another significant disadvantage is the slow execution speed and the need to
launch a new process for almost every shell command executed. When a
script's job can be accomplished by setting up a pipeline in which efficient
filter commands perform most of the work, the slowdown is mitigated, but a
complex script is typically several orders of magnitude slower than a
conventional compiled program that performs an equivalent task.
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
14
LOOPING SYNTAX
FOR LOOP
Syntax:
for { <variable_name> } in { <list of variable> }
do
<commands>
done
WHILE LOOP
Syntax:
while [ <condition> ]
do
<command1>
<command2>
done
UNTIL LOOP
Syntax:
until cond
do
Statement(s) to be executed until command is true
done
NEIL MATHEW – A2324710002 – 3CS4 – Y3305
15
DECISION MAKING SYNTAX
SWITCH CASE
It is a control statement used for decision making.
Syntax:
case $<variable> in
<option1>)
<statement>
;;
<option2>)
<statement>
;;
esac
IF CONDITION
It is a control statement used for decision making.
Syntax:
if [ $<variable> <logical operator> $<variable>
then
<statement>
fi
( IF - ELSE IF )
if [ $<variable> <logical operator> $<variable> ]
then
<statement>
elif [$<variable> <logical operator> $<variable> ]
then
<statement>
else
<statement>
fi
INDEX
SHELL PROGRAMMING
3/8/2011 1. FIND SUM OF 5 NATURAL NUMBERS P2
10/8/2011 2. FIND THE AREA OF CIRCLE P3
10/8/2011 3. CALCULATE THE SIMPLE INTEREST P4
17/8/2011 4. SWAP TWO NUMBERS P5
24/8/2011 5. FIND THE LARGEST NUMBER P6
24/8/2011 6. CHECK IF THE YEAR IS LEAP YEAR OR NOT P7
31/8/2011 7. MAKE A CALCULATOR USING SWITCH CASE P8
7/9/2011
8. INPUT STUDENT RESULT MARKS AND CATEGORIZE
WHETHER IN FAIL, 1ST OR 2ND DIVISION P9
14/9/2011 9. FIND FACTORIAL OF A NUMBER P10
21/9/2011 10.FIND FIBONACCI SERIES P11
21/9/2011 11.FIND REVERSE OF A NUMBER P12
28/9/2011
12.ENTER A FIVE DIGIT NUMBER AND CALCULATE
THE SUM OF ITS DIGITS P13
5/10/2011 13.CHECK IF NUMBER IS A PRIME NO P14
P2
SHELL PROGRAMMING >
Q1. FIND SUM OF 5 NATURAL NUMBERS
metalwihen@metalwihen:~$ vi Question1
echo "Enter 5 numbers: "
read a
read b
read c
read d
read e
sum=` expr $a + $b + $c + $d + $e `
echo "Sum of 5 numbers = $sum"
"Question1" 12L, 109C written
metalwihen@metalwihen:~$ sh Question1
Enter 5 numbers:
10
12
14
16
18
The Sum is: 70
P3
SHELL PROGRAMMING >
Q2. FIND THE AREA OF CIRCLE
metalwihen@metalwihen:~$ vi Question2
echo "Enter the radius of the Circle: "
read r
area=` expr 22 / 7 * $r * $r`
echo "Ans is $area"
"Question2" 7L, 104C written
metalwihen@metalwihen:~$ sh Question2
Enter the radius of the Circle:
2
Ans is 12
P4
SHELL PROGRAMMING >
Q3. CALCULATE THE SIMPLE INTEREST
metalwihen@metalwihen:~$ vi Question3
echo "Enter the Principal: "
read P
echo "Enter the Rate per year: "
read R
echo "Enter the Time in years: "
read T
SI=`expr $P * $R * $T / 100`
echo "The Simple Interest is " $SI
"Question3" 14L, 179C written
metalwihen@metalwihen:~$ sh Question3
Enter the Principal:
1000
Enter the Rate per year:
2
Enter the Time in years:
3
The Simple Interest is 60
P5
SHELL PROGRAMMING >
Q4. SWAP TWO NUMBERS
metalwihen@metalwihen:~$ vi Question4
echo "Enter the First Number: "
read a
echo "Enter the Second Number: "
read b
temp=$a
a=$b
b=$temp
echo "First Number is now: $a"
echo "Second Number is now: $b"
"Question4" 13L, 167C written
metalwihen@metalwihen:~$ sh Question4
Enter the First Number:
7
Enter the Second Number:
3
First Number is now: 3
Second Number is now: 7
P6
SHELL PROGRAMMING >
Q5. FIND THE LARGEST NUMBER
metalwihen@metalwihen:~$ vi Question5
echo "Enter the First Number: "
read a
echo "Enter the Second Number: "
read b
echo "Enter the Third Number: "
read c
if [ $a -gt $b ] && [ $a -gt $c ]
then
echo "$a is the greatest!"
elif [ $b -gt $a ] && [ $b -gt $c ]; then
echo "$b is the greatest!"
else
echo "$c is the greatest!"
fi
"Question5" 18L, 294C written
metalwihen@metalwihen:~$ sh Question5
Enter the First Number:
0
Enter the Second Number:
9
Enter the Third Number:
5
9 is the greatest!
P7
SHELL PROGRAMMING >
Q6. CHECK IF THE YEAR IS A LEAP YEAR OR NOT
metalwihen@metalwihen:~$ vi Question6
echo "Enter the Year: "
read y
rem=`expr $y % 4`
if [ $rem -eq 0 ]
then
echo "$y is a leap year!"
else
echo "$y is NOT a leap year!"
fi
"Question6" 12L, 139C written
metalwihen@metalwihen:~$ sh Question6
Enter the Year:
2008
2008 is a leap year!
P8
SHELL PROGRAMMING >
Q7. MAKE A CALCULATOR USING SWITCH CASE
metalwihen@metalwihen:~$ vi Question7
echo "Enter the First Number:"
read a
echo "Enter the Second Number:"
read b
echo
echo "Options:"
echo "To Add, Enter +"
echo "To Subtract, Enter -"
echo "To Multiply, Enter *"
echo "To Divide, Enter /"
echo -n "Your Choice: "
read ch
case $ch in
+)
res=`expr $a + $b`
echo "Sum is: $res"
;;
-)
res=`expr $a - $b`
echo "Remainder is: $res"
;;
*)
res=`expr $a * $b`
echo "Product is: $res"
;;
/)
res=`expr $a / $b`
echo "Quotient is: $res"
;;
esac
"Question7" 40L, 458C written
metalwihen@metalwihen:~$ sh Question7
Enter the First Number:
4
Enter the Second Number:
6
Options:
To Add, Enter +
To Subtract, Enter -
To Multiply, Enter *
To Divide, Enter /
Your Choice: *
Product is: 24
P9
SHELL PROGRAMMING >
Q8.INPUT STUDENT RESULT MARKS AND CATEGORIZE
WHETHER IN FAIL, 1ST DIVISION
OR 2ND DIVISION
metalwihen@metalwihen:~$ vi Question8
echo "Enter Final Marks: "
read res
if [ $res -ge 85 ]; then
echo "You are in First Division!"
elif [ $res -ge 70 ]; then
echo "You are in Second Division!"
elif [ $res -lt 40 ]; then
echo "You have FAILED!"
else
echo "No Division. AVERAGE"
fi
"Question8" 14L, 247C written
metalwihen@metalwihen:~$ sh Question8
Enter Final Marks:
84
You are in Second Division!
metalwihen@metalwihen:~$ sh Question8
Enter Final Marks:
56
No Division. AVERAGE
P10
SHELL PROGRAMMING >
Q9. FIND FACTORIAL OF A NUMBER
metalwihen@metalwihen:~$ vi Question9
echo "Enter Number:"
read n
f=1
while [ $n -gt 0 ]
do
f=`expr $f * $n`
n=`expr $n - 1`
done
echo "Factorial is: $f"
"Question9" 16L, 124C written
metalwihen@metalwihen:~$ sh Question9
Enter Number:
5
Factorial is: 120
P11
SHELL PROGRAMMING >
Q10. FIND FIBONACCI SERIES
metalwihen@metalwihen:~$ vi Question10
echo "Enter limiting number:"
read n
num1=0
num2=1
echo -n "Fibonacci Series:"
echo -n " $num1"
while [ $n -gt 1 ]
do
temp=$num2
num2=`expr $num2 + $num1`
num1=$temp
echo -n " + $num2"
n=`expr $n - 1`
done
echo
"Question10" 23L, 220C written
metalwihen@metalwihen:~$ sh Question10
Enter limiting number:
6
Fibonacci Series: 0 + 1 + 2 + 3 + 5 + 8
P12
SHELL PROGRAMMING >
Q11. FIND REVERSE OF A NUMBER
metalwihen@metalwihen:~$ vi Question11
echo "Enter the number:"
read n
num=$n
rev=0
while [ $num -gt 0 ]
do
digit=`expr $num % 10`
rev=`expr $rev * 10 + $digit`
num=`expr $num / 10`
done
echo "Reverse of $n is $rev"
"Question11" 17L, 184C written
metalwihen@metalwihen:~$ sh Question11
Enter the number:
345
Reverse of 345 is 543
P13
SHELL PROGRAMMING >
Q12. ENTER A FIVE DIGIT NUMBER
AND CALCULATE THE SUM OF ITS DIGITS
metalwihen@metalwihen:~$ vi Question12
echo "Enter the Number:"
read num
sum=0
while [ $num -gt 0 ]
do
digit=`expr $num % 10`
sum=`expr $sum + $digit`
num=`expr $num / 10`
done
echo "Sum of digits: $sum"
"Question12" [New] 16L, 171C written
metalwihen@metalwihen:~$ sh Question12
Enter the Number:
12345
Sum of digits: 15
P14
SHELL PROGRAMMING >
Q13. CHECK IF NUMBER IS A PRIME NO
metalwihen@metalwihen:~$ vi Question12
echo "Enter the number:"
read n
flag=1
i=2
while [ $i -lt $n ]
do
rem=`expr $n % $i`
if [ $rem -eq 0 ]
then
flag=0
fi
i=`expr $i + 1`
done
if [ $flag -eq 0 ]
then
echo "Number is NOT Prime."
else
echo "Number is Prime."
fi
"Question13" 30L, 236C written
metalwihen@metalwihen:~$ sh Question13
Enter the number:
5
Number is Prime.
metalwihen@metalwihen:~$ sh Question13
Enter the number:
6
Number is NOT Prime.

Más contenido relacionado

La actualidad más candente

Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
Vaibhav Bajaj
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
Ankit Katiyar
 

La actualidad más candente (20)

Introduction to Shell script
Introduction to Shell scriptIntroduction to Shell script
Introduction to Shell script
 
operating system lecture notes
operating system lecture notesoperating system lecture notes
operating system lecture notes
 
Analysis modeling & scenario based modeling
Analysis modeling &  scenario based modeling Analysis modeling &  scenario based modeling
Analysis modeling & scenario based modeling
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Chapter 2: Operating System Structures
Chapter 2: Operating System StructuresChapter 2: Operating System Structures
Chapter 2: Operating System Structures
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
 
Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- Introduction
 
Ch 7 Knowledge Representation.pdf
Ch 7 Knowledge Representation.pdfCh 7 Knowledge Representation.pdf
Ch 7 Knowledge Representation.pdf
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
Communication primitives
Communication primitivesCommunication primitives
Communication primitives
 
software design principles
software design principlessoftware design principles
software design principles
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Intruders
IntrudersIntruders
Intruders
 
Distributed operating system
Distributed operating systemDistributed operating system
Distributed operating system
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
Kernel mode vs user mode in linux
Kernel mode vs user mode in linuxKernel mode vs user mode in linux
Kernel mode vs user mode in linux
 
Distributed and clustered systems
Distributed and clustered systemsDistributed and clustered systems
Distributed and clustered systems
 

Similar a Unix Programming Lab

Introduction to Unix - POS420Unix Lab Exercise Week 3 ATopics.docx
Introduction to Unix - POS420Unix  Lab Exercise Week 3 ATopics.docxIntroduction to Unix - POS420Unix  Lab Exercise Week 3 ATopics.docx
Introduction to Unix - POS420Unix Lab Exercise Week 3 ATopics.docx
mariuse18nolet
 
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdfHailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
cookie1969
 

Similar a Unix Programming Lab (20)

Introduction to Unix - POS420Unix Lab Exercise Week 3 ATopics.docx
Introduction to Unix - POS420Unix  Lab Exercise Week 3 ATopics.docxIntroduction to Unix - POS420Unix  Lab Exercise Week 3 ATopics.docx
Introduction to Unix - POS420Unix Lab Exercise Week 3 ATopics.docx
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Basic unix commands
Basic unix commandsBasic unix commands
Basic unix commands
 
Foss manual (1)
Foss manual (1)Foss manual (1)
Foss manual (1)
 
Unix notes
Unix notesUnix notes
Unix notes
 
BPF Tools 2017
BPF Tools 2017BPF Tools 2017
BPF Tools 2017
 
bcc/BPF tools - Strategy, current tools, future challenges
bcc/BPF tools - Strategy, current tools, future challengesbcc/BPF tools - Strategy, current tools, future challenges
bcc/BPF tools - Strategy, current tools, future challenges
 
Unix
UnixUnix
Unix
 
Putty
PuttyPutty
Putty
 
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdfHailey_Database_Performance_Made_Easy_through_Graphics.pdf
Hailey_Database_Performance_Made_Easy_through_Graphics.pdf
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
 
Linuxs1
Linuxs1Linuxs1
Linuxs1
 
Linux.pdf
Linux.pdfLinux.pdf
Linux.pdf
 
Nithi
NithiNithi
Nithi
 
Linux Basic commands and VI Editor
Linux Basic commands and VI EditorLinux Basic commands and VI Editor
Linux Basic commands and VI Editor
 
Tensorflow and python : fault detection system - PyCon Taiwan 2017
Tensorflow and python : fault detection system - PyCon Taiwan 2017Tensorflow and python : fault detection system - PyCon Taiwan 2017
Tensorflow and python : fault detection system - PyCon Taiwan 2017
 
17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboards17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboards
 
Redhat 6 & 7
Redhat 6 & 7Redhat 6 & 7
Redhat 6 & 7
 
Introduction to UNIX
Introduction to UNIXIntroduction to UNIX
Introduction to UNIX
 
Sge
SgeSge
Sge
 

Más de Neil Mathew

Más de Neil Mathew (20)

AMIZONER: Weekly Progress Reports
AMIZONER: Weekly Progress ReportsAMIZONER: Weekly Progress Reports
AMIZONER: Weekly Progress Reports
 
AMIZONER: Final Report
AMIZONER: Final ReportAMIZONER: Final Report
AMIZONER: Final Report
 
Computer Graphics Lab
Computer Graphics LabComputer Graphics Lab
Computer Graphics Lab
 
Programming in C Lab
Programming in C LabProgramming in C Lab
Programming in C Lab
 
Role of IT & Computer in Environment
Role of IT & Computer in EnvironmentRole of IT & Computer in Environment
Role of IT & Computer in Environment
 
French Open
French OpenFrench Open
French Open
 
Data Structures Lab
Data Structures LabData Structures Lab
Data Structures Lab
 
DBMS Lab
DBMS LabDBMS Lab
DBMS Lab
 
Communication Assessment File
Communication Assessment FileCommunication Assessment File
Communication Assessment File
 
Cloud Computing and Google's advancement in the field
Cloud Computing and Google's advancement in the fieldCloud Computing and Google's advancement in the field
Cloud Computing and Google's advancement in the field
 
The Cube - Class XII Project
The Cube - Class XII ProjectThe Cube - Class XII Project
The Cube - Class XII Project
 
Copywriting & Storyboarding (Advertising & Sales Promotion)
Copywriting & Storyboarding (Advertising & Sales Promotion)Copywriting & Storyboarding (Advertising & Sales Promotion)
Copywriting & Storyboarding (Advertising & Sales Promotion)
 
American Airlines Merger (Management In Action Case Study)
American Airlines Merger (Management In Action Case Study)American Airlines Merger (Management In Action Case Study)
American Airlines Merger (Management In Action Case Study)
 
Good Governance Leads To Flourish Society & Nation (BS SAP)
Good Governance Leads To Flourish Society & Nation (BS SAP)Good Governance Leads To Flourish Society & Nation (BS SAP)
Good Governance Leads To Flourish Society & Nation (BS SAP)
 
High Fortune (Product Brand Management)
High Fortune (Product Brand Management)High Fortune (Product Brand Management)
High Fortune (Product Brand Management)
 
Cost Benefit Analysis in Public Project Appraisal (PPAC)
Cost Benefit Analysis in Public Project Appraisal (PPAC)Cost Benefit Analysis in Public Project Appraisal (PPAC)
Cost Benefit Analysis in Public Project Appraisal (PPAC)
 
Corportate Entrepreneurship at WIPRO
Corportate Entrepreneurship at WIPROCorportate Entrepreneurship at WIPRO
Corportate Entrepreneurship at WIPRO
 
Consumer Perception of Job Seekers in updating their Job Profiles on Job Portals
Consumer Perception of Job Seekers in updating their Job Profiles on Job PortalsConsumer Perception of Job Seekers in updating their Job Profiles on Job Portals
Consumer Perception of Job Seekers in updating their Job Profiles on Job Portals
 
How OLX changed the consumer involvement in the Scrap Market
How OLX changed the consumer involvement in the Scrap MarketHow OLX changed the consumer involvement in the Scrap Market
How OLX changed the consumer involvement in the Scrap Market
 
Innovation Jockeys 3 - Gramseva: Kisan
Innovation Jockeys 3 - Gramseva: KisanInnovation Jockeys 3 - Gramseva: Kisan
Innovation Jockeys 3 - Gramseva: Kisan
 

Último

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Último (20)

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 

Unix Programming Lab

  • 1. UN NEIL M NIX MATHEW PRO W - A23 OGR 3247100 RAM 002 - 3C MMIN CS4 – Y3 NG L 305 LABB
  • 2. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 1 INDEX UNIX LAB FILE 1. WHAT IS UNIX? 2 2. UNIX STRUCTURE 3 3. DIFFERENCE BETWEEN UNIX AND WINDOWS 4 4. BASIC UNIX COMMANDS 5 5. VI EDITOR 12 6. SHELL SCRIPTING 13 7. LOOPING SYNTAX 14 8. DESCISION MAKING SYNTAX 15
  • 3. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 2 WHAT IS UNIX? The UNIX operating system is a set of programs that act as a link between the computer and the user. The computer programs that allocate the system resources and coordinate all the details of the computer's internals is called the operating system or kernel. Users communicate with the kernel through a program known as the shell. The shell is a command line interpreter; it translates commands entered by the user and converts them into a language that is understood by the kernel. • Unix was originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Douglas McIlroy, and Joe Ossanna. • There are various Unix variants available in the market. Solaris Unix, AIX, UP Unix and BSD are few examples. Linux is also a flavour of Unix which is freely available. • Several people can use a UNIX computer at the same time; hence UNIX is called a multiuser system. • A user can also run multiple programs at the same time; hence UNIX is called multitasking.
  • 4. The ma Kernel: most of t Shell: T your term shell use famous s Comma your day utilities. 3rd party Files an directorie ain concept The kernel the tasks lik he shell is t minal, the s es standard shells which nds and Ut y to day ac There are y software. nd Director es. These d NEIL M UN t that unit is the hea ke memory the utility th shell interpr syntax for a h are availab tilities: The ctivities. cp, over 250 s All the com ries: All dat irectories ar MATHEW – A2 NIX S tes all ver art of the o managemen hat processe rets the com all comman ble with mos ere are vario mv, cat an standard com mands com ta in UNIX re organized 2324710002 – STRUC rsions of operating sy nt, task sch es your requ mmand and ds. C Shell, st of the Un ous comma nd grep etc. mmands plu me along wit is organized d into a tree – 3CS4 – Y33 CTURE UNIX is t ystem. It in heduling and uests. When calls the p , Bourne Sh ix variants. nd and utili are few ex us numerou h various op d into files. e-like struct 305 E he followin nteracts wit d file manag n you type i program tha hell and Kor ties which y xamples of us others p ptional optio All files are ure called t ng four ba h hardware gement. n a comma at you want n Shell are you would u commands provided thr ons. e organized he file syste 3 asics: e and nd at . The most use in s and rough d into em.
  • 5. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 4 DIFFERENCE BETWEEN UNIX & WINDOWS NO: UNIX WINDOWS 1 It is a Free Source OS. It is a licensed OS. 2 Less administration and maintenance is needed in maintaining a UNIX system More administration and maintenance is needed in maintaining a Windows system 3 UNIX uses daemons. Windows has service processes. 4 UNIX is more secure. Windows is more vulnerable. 5 Unix is much better at handling multiple tasks for a single user or for multiple users than windows. Windows is inferior in this regard. 6 UNIX preferred by programmers for its more flexible nature. Windows preferred by less sophisticated users. 7 When a new process is created by a UNIX application, it becomes a child of the process that created it. Windows processes on the other hand do not share a hierarchical relationship 8 It uses the Unix file system (UFS) also known as Fast File System (FFS) Windows uses the FAT32 and NTFS File system.
  • 6. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 5 BASIC UNIX COMMANDS The various commands are: who who : Shows other nodes connected to same server. who am I : Shows your node. $ who am i aib ttyp1 Jul 20 02:19 $ who aib ttyp0 Jul 20 00:58 aib ttyp1 Jul 20 02:19 aib ttyp2 Jul 20 02:19 aib ttyp3 Jul 20 02:22 aib ttyp4 Jul 20 02:22 aib ttyp5 Jul 20 02:14 aib ttyp6 Jul 20 02:05 aib ttyp7 Jul 20 02:06 aib ttyp8 Jul 20 02:18 aib ttyp9 Jul 20 02:06 aib ttyp10 Jul 20 02:15 pwd pwd : Present Working Directory $ pwd /usr/aib Banner banner <name> : display <name> in a banner-like format $ banner SCIENCE ##### ##### ### ####### # # ##### ####### # # # # # # ## # # # # # # # # # # # # # ##### # # ##### # # # # ##### # # # # # # # # # # # # # # # # ## # # # ##### ##### ### ####### # # ##### #######
  • 7. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 6 cal cal : Calender $ cal 2011 2011 Jan Feb Mar Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 1 2 3 4 5 1 2 3 4 5 2 3 4 5 6 7 8 6 7 8 9 10 11 12 6 7 8 9 10 11 12 9 10 11 12 13 14 15 13 14 15 16 17 18 19 13 14 15 16 17 18 19 16 17 18 19 20 21 22 20 21 22 23 24 25 26 20 21 22 23 24 25 26 23 24 25 26 27 28 29 27 28 27 28 29 30 31 30 31 Apr May Jun Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 1 2 3 4 5 6 7 1 2 3 4 3 4 5 6 7 8 9 8 9 10 11 12 13 14 5 6 7 8 9 10 11 10 11 12 13 14 15 16 15 16 17 18 19 20 21 12 13 14 15 16 17 18 17 18 19 20 21 22 23 22 23 24 25 26 27 28 19 20 21 22 23 24 25 24 25 26 27 28 29 30 29 30 31 26 27 28 29 30 Jul Aug Sep Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 1 2 3 4 5 6 1 2 3 3 4 5 6 7 8 9 7 8 9 10 11 12 13 4 5 6 7 8 9 10 10 11 12 13 14 15 16 14 15 16 17 18 19 20 11 12 13 14 15 16 17 17 18 19 20 21 22 23 21 22 23 24 25 26 27 18 19 20 21 22 23 24 24 25 26 27 28 29 30 28 29 30 31 25 26 27 28 29 30 31 Oct Nov Dec Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 1 2 3 4 5 1 2 3 2 3 4 5 6 7 8 6 7 8 9 10 11 12 4 5 6 7 8 9 10 9 10 11 12 13 14 15 13 14 15 16 17 18 19 11 12 13 14 15 16 17 16 17 18 19 20 21 22 20 21 22 23 24 25 26 18 19 20 21 22 23 24 23 24 25 26 27 28 29 27 28 29 30 25 26 27 28 29 30 31 30 31
  • 8. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 7 date date +% _ : Shows date, with specified formats $date Wed Jul 20 02:26:01 IST 2011 $ date +%H <-- Hours (Time Capital) 02 $ date +%M <-- Minutes 26 $ date +%S <-- Seconds 19 $ date Wed Jul 20 02:26:31 IST 2011 $ date +%d <-- Day (Date LowerCase) 20 $ date +%m <-- Month 07 $ date +%y <-- Year (two digits) 11 $ date +%Y <-- Year (all four digits) 2011 $date +%T <-- Time 02:27:14 touch touch <filename> : Creates files without data cat cat > (existing/new filename) : Write data to file (also creates) cat < (existing filename) : Read data from file $ touch FOLM1 FOLM2 FOLM3 $ cat > FOLM2 Yosh. $ cat > FOLM1 DOOM DOT. $ cat < FOLM2 Yosh. $ cat < FOLM1 DOOM DOT.
  • 9. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 8 mv mv <filename1> <filename2> : Renames file from 1 to 2 cp cp <filename1> <filename2> : Copies from one to another rm rm <filename1> : deletes file $ touch Olaf $ cat > Olaf Boom Box Reloaded. $ cat < Olaf Boom Box Reloaded. $ mv Olaf Heimer <-- Renamed $ cat < Olaf <-- Therefore Olaf no longer exists Olaf: cannot open $ cat < Heimer Boom Box Reloaded. $ rm Heimer <-- Deleted $ cat < Heimer Heimer: cannot open $ touch dwarf $ cat > dwarf Ain't I small? $ cat <dwarf Ain't I small? $ cp dwarf Elf <-- Copy $ cat <Elf Ain't I small? -i <command> -i <files> : With Permission $ rm -i mini miniME remove mini ? y remove miniME ? n
  • 10. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 9 wc wc <filename> : Word Count ( lines, words, characters) -l : only lines -w : only words -c : only characters -wl : words & lines -wc : words & characters -lc : lines & characters $ cat < PUMA2 Jump & move it. Jump & move it.. Jump & move it... Yo! $ wc PUMA2 4 13 55 PUMA2 $ wc -w PUMA2 13 PUMA2 $ wc -c PUMA2 55 PUMA2 $ wc -l PUMA2 4 PUMA2 Head head -n <filename> : displays the first n lines of a file Tail tail -n <filename> : displays the last n lines of a file $ cat < PUMA2 Jump & move it. Jump & move it.. Jump & move it... Yo! $ head -1 PUMA2 Jump & move it. $ tail -2 PUMA2 Jump & move it... Yo!
  • 11. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 10 Sort sort <filename> : Sorts files taking each line as separate entity sort -r <filename> : reverse order (descending) sort -o<to_filename> <from_filename> : save sorted file sort <filename> <filename2> : Combines both and sorts it all. sort -o<TO_file> <FROM_file1> <FROM_file2> : Saves the combined and sorted. -m : treats each file as an entity instead of the lines within it -u : avoids repetition when common entities from 2 files repeat $ cat > JLA Clark Kent Bruce Wayne Diana Barry Allen Hal Jordan Arthur Curry J'onn J'onzz $ sort JLA Arthur Curry Barry Allen Bruce Wayne Clark Kent Diana Hal Jordan J'onn J'onzz
  • 12. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 11
  • 13. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 12 VI EDITOR Vi editor, is a widely-used and popular UNIX-based text editor. Like most UNIX system interfaces and other text editors, it lets you control the system by using the keyboard rather than a combination of mouse selections and keystrokes. The succinctness of the interface makes it highly useful for people who work at a computer all day, especially programmers entering or manipulating language statements. There are two modes in the Vi Editor. 1. Command Mode 2. Insertion Mode The editor begins in command mode, where the cursor movement and text deletion and pasting occur. Insertion mode begins upon entering an insertion or change command. [ESC] returns the editor to command mode. Most commands execute as soon as you type them except for "colon" commands which execute when you press the return key. ENTERING THE INSERT MODE a append text, after the cursor; i insert text, before the cursor; R enter Overtype Mode; A append text, after end of line; I insert text, before first non-whitespace character; o open new line below cursor in Insert Mode; O open new line above cursor in Insert Mode; EXITING THE INSERT MODE ESC Exit insertion mode and return to command mode
  • 14. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 13 SHELL SCRIPTING A shell script is a text file that contains a sequence of commands for a UNIX-based operating system. It's called a shell script because it combines into a single file (script) a sequence of commands that would otherwise have to be presented to the system from a keyboard one at a time. A shell script is usually created for command sequences for which a user has a repeated need. You initiate the sequence of commands in the shell script by simply entering the name of the shell script on a command line. Often, writing a shell script is much quicker than writing the equivalent code in other programming languages. The many advantages include easy program or file selection, quick start, and interactive debugging. A shell script can be used to provide a sequencing and decision-making linkage around existing programs, and for moderately-sized scripts the absence of a compilation step is an advantage. On the other hand, shell scripting is prone to costly errors. Inadvertent typing errors such as rm -rf * / are folklore in the Unix community; a single extra space converts the command from one that deletes everything in the sub- directories to one which deletes everything - and also tries to delete everything in the root directory. Similar problems can transform cp and mv into dangerous weapons, and misuse of the > redirect can delete the contents of a file. This is made more problematic by the fact that many UNIX commands differ in name by only one letter: cp, cd, dd, df, etc. Another significant disadvantage is the slow execution speed and the need to launch a new process for almost every shell command executed. When a script's job can be accomplished by setting up a pipeline in which efficient filter commands perform most of the work, the slowdown is mitigated, but a complex script is typically several orders of magnitude slower than a conventional compiled program that performs an equivalent task.
  • 15. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 14 LOOPING SYNTAX FOR LOOP Syntax: for { <variable_name> } in { <list of variable> } do <commands> done WHILE LOOP Syntax: while [ <condition> ] do <command1> <command2> done UNTIL LOOP Syntax: until cond do Statement(s) to be executed until command is true done
  • 16. NEIL MATHEW – A2324710002 – 3CS4 – Y3305 15 DECISION MAKING SYNTAX SWITCH CASE It is a control statement used for decision making. Syntax: case $<variable> in <option1>) <statement> ;; <option2>) <statement> ;; esac IF CONDITION It is a control statement used for decision making. Syntax: if [ $<variable> <logical operator> $<variable> then <statement> fi ( IF - ELSE IF ) if [ $<variable> <logical operator> $<variable> ] then <statement> elif [$<variable> <logical operator> $<variable> ] then <statement> else <statement> fi
  • 17. INDEX SHELL PROGRAMMING 3/8/2011 1. FIND SUM OF 5 NATURAL NUMBERS P2 10/8/2011 2. FIND THE AREA OF CIRCLE P3 10/8/2011 3. CALCULATE THE SIMPLE INTEREST P4 17/8/2011 4. SWAP TWO NUMBERS P5 24/8/2011 5. FIND THE LARGEST NUMBER P6 24/8/2011 6. CHECK IF THE YEAR IS LEAP YEAR OR NOT P7 31/8/2011 7. MAKE A CALCULATOR USING SWITCH CASE P8 7/9/2011 8. INPUT STUDENT RESULT MARKS AND CATEGORIZE WHETHER IN FAIL, 1ST OR 2ND DIVISION P9 14/9/2011 9. FIND FACTORIAL OF A NUMBER P10 21/9/2011 10.FIND FIBONACCI SERIES P11 21/9/2011 11.FIND REVERSE OF A NUMBER P12 28/9/2011 12.ENTER A FIVE DIGIT NUMBER AND CALCULATE THE SUM OF ITS DIGITS P13 5/10/2011 13.CHECK IF NUMBER IS A PRIME NO P14
  • 18. P2 SHELL PROGRAMMING > Q1. FIND SUM OF 5 NATURAL NUMBERS metalwihen@metalwihen:~$ vi Question1 echo "Enter 5 numbers: " read a read b read c read d read e sum=` expr $a + $b + $c + $d + $e ` echo "Sum of 5 numbers = $sum" "Question1" 12L, 109C written metalwihen@metalwihen:~$ sh Question1 Enter 5 numbers: 10 12 14 16 18 The Sum is: 70
  • 19. P3 SHELL PROGRAMMING > Q2. FIND THE AREA OF CIRCLE metalwihen@metalwihen:~$ vi Question2 echo "Enter the radius of the Circle: " read r area=` expr 22 / 7 * $r * $r` echo "Ans is $area" "Question2" 7L, 104C written metalwihen@metalwihen:~$ sh Question2 Enter the radius of the Circle: 2 Ans is 12
  • 20. P4 SHELL PROGRAMMING > Q3. CALCULATE THE SIMPLE INTEREST metalwihen@metalwihen:~$ vi Question3 echo "Enter the Principal: " read P echo "Enter the Rate per year: " read R echo "Enter the Time in years: " read T SI=`expr $P * $R * $T / 100` echo "The Simple Interest is " $SI "Question3" 14L, 179C written metalwihen@metalwihen:~$ sh Question3 Enter the Principal: 1000 Enter the Rate per year: 2 Enter the Time in years: 3 The Simple Interest is 60
  • 21. P5 SHELL PROGRAMMING > Q4. SWAP TWO NUMBERS metalwihen@metalwihen:~$ vi Question4 echo "Enter the First Number: " read a echo "Enter the Second Number: " read b temp=$a a=$b b=$temp echo "First Number is now: $a" echo "Second Number is now: $b" "Question4" 13L, 167C written metalwihen@metalwihen:~$ sh Question4 Enter the First Number: 7 Enter the Second Number: 3 First Number is now: 3 Second Number is now: 7
  • 22. P6 SHELL PROGRAMMING > Q5. FIND THE LARGEST NUMBER metalwihen@metalwihen:~$ vi Question5 echo "Enter the First Number: " read a echo "Enter the Second Number: " read b echo "Enter the Third Number: " read c if [ $a -gt $b ] && [ $a -gt $c ] then echo "$a is the greatest!" elif [ $b -gt $a ] && [ $b -gt $c ]; then echo "$b is the greatest!" else echo "$c is the greatest!" fi "Question5" 18L, 294C written metalwihen@metalwihen:~$ sh Question5 Enter the First Number: 0 Enter the Second Number: 9 Enter the Third Number: 5 9 is the greatest!
  • 23. P7 SHELL PROGRAMMING > Q6. CHECK IF THE YEAR IS A LEAP YEAR OR NOT metalwihen@metalwihen:~$ vi Question6 echo "Enter the Year: " read y rem=`expr $y % 4` if [ $rem -eq 0 ] then echo "$y is a leap year!" else echo "$y is NOT a leap year!" fi "Question6" 12L, 139C written metalwihen@metalwihen:~$ sh Question6 Enter the Year: 2008 2008 is a leap year!
  • 24. P8 SHELL PROGRAMMING > Q7. MAKE A CALCULATOR USING SWITCH CASE metalwihen@metalwihen:~$ vi Question7 echo "Enter the First Number:" read a echo "Enter the Second Number:" read b echo echo "Options:" echo "To Add, Enter +" echo "To Subtract, Enter -" echo "To Multiply, Enter *" echo "To Divide, Enter /" echo -n "Your Choice: " read ch case $ch in +) res=`expr $a + $b` echo "Sum is: $res" ;; -) res=`expr $a - $b` echo "Remainder is: $res" ;; *) res=`expr $a * $b` echo "Product is: $res" ;; /) res=`expr $a / $b` echo "Quotient is: $res" ;; esac "Question7" 40L, 458C written metalwihen@metalwihen:~$ sh Question7 Enter the First Number: 4 Enter the Second Number: 6 Options: To Add, Enter + To Subtract, Enter - To Multiply, Enter * To Divide, Enter / Your Choice: * Product is: 24
  • 25. P9 SHELL PROGRAMMING > Q8.INPUT STUDENT RESULT MARKS AND CATEGORIZE WHETHER IN FAIL, 1ST DIVISION OR 2ND DIVISION metalwihen@metalwihen:~$ vi Question8 echo "Enter Final Marks: " read res if [ $res -ge 85 ]; then echo "You are in First Division!" elif [ $res -ge 70 ]; then echo "You are in Second Division!" elif [ $res -lt 40 ]; then echo "You have FAILED!" else echo "No Division. AVERAGE" fi "Question8" 14L, 247C written metalwihen@metalwihen:~$ sh Question8 Enter Final Marks: 84 You are in Second Division! metalwihen@metalwihen:~$ sh Question8 Enter Final Marks: 56 No Division. AVERAGE
  • 26. P10 SHELL PROGRAMMING > Q9. FIND FACTORIAL OF A NUMBER metalwihen@metalwihen:~$ vi Question9 echo "Enter Number:" read n f=1 while [ $n -gt 0 ] do f=`expr $f * $n` n=`expr $n - 1` done echo "Factorial is: $f" "Question9" 16L, 124C written metalwihen@metalwihen:~$ sh Question9 Enter Number: 5 Factorial is: 120
  • 27. P11 SHELL PROGRAMMING > Q10. FIND FIBONACCI SERIES metalwihen@metalwihen:~$ vi Question10 echo "Enter limiting number:" read n num1=0 num2=1 echo -n "Fibonacci Series:" echo -n " $num1" while [ $n -gt 1 ] do temp=$num2 num2=`expr $num2 + $num1` num1=$temp echo -n " + $num2" n=`expr $n - 1` done echo "Question10" 23L, 220C written metalwihen@metalwihen:~$ sh Question10 Enter limiting number: 6 Fibonacci Series: 0 + 1 + 2 + 3 + 5 + 8
  • 28. P12 SHELL PROGRAMMING > Q11. FIND REVERSE OF A NUMBER metalwihen@metalwihen:~$ vi Question11 echo "Enter the number:" read n num=$n rev=0 while [ $num -gt 0 ] do digit=`expr $num % 10` rev=`expr $rev * 10 + $digit` num=`expr $num / 10` done echo "Reverse of $n is $rev" "Question11" 17L, 184C written metalwihen@metalwihen:~$ sh Question11 Enter the number: 345 Reverse of 345 is 543
  • 29. P13 SHELL PROGRAMMING > Q12. ENTER A FIVE DIGIT NUMBER AND CALCULATE THE SUM OF ITS DIGITS metalwihen@metalwihen:~$ vi Question12 echo "Enter the Number:" read num sum=0 while [ $num -gt 0 ] do digit=`expr $num % 10` sum=`expr $sum + $digit` num=`expr $num / 10` done echo "Sum of digits: $sum" "Question12" [New] 16L, 171C written metalwihen@metalwihen:~$ sh Question12 Enter the Number: 12345 Sum of digits: 15
  • 30. P14 SHELL PROGRAMMING > Q13. CHECK IF NUMBER IS A PRIME NO metalwihen@metalwihen:~$ vi Question12 echo "Enter the number:" read n flag=1 i=2 while [ $i -lt $n ] do rem=`expr $n % $i` if [ $rem -eq 0 ] then flag=0 fi i=`expr $i + 1` done if [ $flag -eq 0 ] then echo "Number is NOT Prime." else echo "Number is Prime." fi "Question13" 30L, 236C written metalwihen@metalwihen:~$ sh Question13 Enter the number: 5 Number is Prime. metalwihen@metalwihen:~$ sh Question13 Enter the number: 6 Number is NOT Prime.