0% found this document useful (0 votes)
90 views

Operating System Practical

Linus Torvalds began developing the Linux kernel in 1991 as a hobby. He announced it on Usenet and asked for feedback. Linux is now a widely adopted open source operating system kernel that continues to grow through contributions from developers around the world. The vi editor is a commonly used text editor in Linux that has two modes - command mode for entering commands and insert mode for inserting text. Basic commands like :w save files and :q quits vi.

Uploaded by

Poonam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Operating System Practical

Linus Torvalds began developing the Linux kernel in 1991 as a hobby. He announced it on Usenet and asked for feedback. Linux is now a widely adopted open source operating system kernel that continues to grow through contributions from developers around the world. The vi editor is a commonly used text editor in Linux that has two modes - command mode for entering commands and insert mode for inserting text. Basic commands like :w save files and :q quits vi.

Uploaded by

Poonam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

GJUS&T

Operating System Lab


Practical File
Submitted by: Poonam Submitted to: Rekha
Ma’am
Roll No: 200010140041

Aim:- To Study About LINUX Operating System.

Theory:-
The History of Linux began in 1991 with the commencement of a personal project
by a Finnish student, Linus Torvalds, to create a new free operating system kernel.
Since then, the resulting Linux kernel has been marked by constant growth
throughout its history. Since the initial release of its source code in 1991, it has
grown from a small number of C files under a license prohibiting commercial
distribution to its state in 2009 of over 370 megabytes of source under the GNU
General Public License.

The Unix operating system was conceived and implemented by Ken Thompson and
Dennis Ritchie (both of AT&T Bell Laboratories) in 1969 and first released in 1970.
Its availability and portability caused it to be widely adopted, copied and modified
by academic institutions and businesses. Its design became influential to authors
of other systems.

In 1983, Richard Stallman started the GNU project with the goal of creating a
free UNIX-like operating system.[2] As part of this work, he wrote the GNU
General Public License (GPL). By the early 1990s there was almost enough available
software to create a full operating system. However, the GNU kernel, called Hurd,
failed to attract enough attention from developers leaving GNU incomplete.

Another free operating system project, initially released in 1977, was the Berkeley
Software Distribution (BSD). This was developed by UC Berkeley from the 6th
edition of Unix from AT&T. Since BSD contained Unix code that AT&T owned,
AT&T filed a lawsuit (USL v. BSDi) in the early 1990s against the University of
California. This strongly limited the development and adoption of BSD.

In 1985, Intel released the 80386, the first x86 microprocessor with 32-bit
instruction set and MMU with paging.

In 1986, Maurice J. Bach, of AT&T Bell Labs, published The Design of the UNIX
Operating System. This definitive description principally covered the System V
Release 2 kernel, with some new features from Release 3 and BSD.

MINIX, a Unix-like system intended for academic use, was released by Andrew S.
Tanenbaum in 1987. While source code for the system was available, modification
and redistribution were restricted. In addition, MINIX's 16-bit design was not
well adapted to the 32-bit features of the increasingly cheap and popular Intel
386 architecture for personal computers. In the early nineties a commercial UNIX
operating system for Intel 386 PCs was too expensive for private users.

These factors and the lack of a widely adopted, free kernel provided the impetus
for Torvalds's starting his project. He has stated that if either the GNU or
386BSD kernels were available at the time, he likely would not have written his
own.

The creation of Linux:-

Linus Torvalds in 2002

In 1991, in Helsinki, Linus Torvalds began a project that later became the Linux
kernel. It was initially a terminal emulator, which Torvalds used to access the large
UNIX servers of the university. He wrote the program specifically for the
hardware he was using and independent of an operating system because he wanted
to use the functions of his new PC with an 80386 processor. Development was done
on MINIX using the GNU C compiler, which is still the main choice for compiling
Linux today (although the code can be built with other compilers, such as the Intel
C Compiler).

As Torvalds wrote in his book Just for Fun, he eventually realized that he had
written an operating system kernel. On 25 August 1991, he announced this system
in a Usenet posting to the newsgroup "comp.os.minix.":

Hello everybody out there using minix -

I'm doing a (free) operating system (just a hobby, won't be big and professional
like gnu) for 386(486) AT clones. This has been brewing since april, and is starting
to get ready. I'd like any feedback on things people like/dislike in minix, as my OS
resembles it somewhat (same physical layout of the file-system (due to practical
reasons) among other things).

I've currently ported bash(1.08) and gcc(1.40), and things seem to work. This
implies that I'll get something practical within a few months, and I'd like to know
what features most people would want. Any suggestions are welcome, but I won't
promise I'll implement them :-)

Linus ([email protected])

PS. Yes – it's free of any minix code, and it has a multi-threaded fs. It is NOT
portable (uses 386 task switching etc), and it probably never will support anything
other than AT-harddisks, as that's all I have :-(.
—Linus Torvalds

Features of LINUX:-
Following are some of the important features of Linux Operating System.
● Portable - Portability means softwares can works on different types of
hardwares in same way.Linux kernel and application programs supports their
installation on any kind of hardware platform.
● Open Source - Linux source code is freely available and it is community based
development project. Multiple teams works in collaboration to enhance the
capability of Linux operating system and it is continuously evolving.
● Multi-User - Linux is a multiuser system means multiple users can access
system resources like memory/ ram/ application programs at same time.
● Multiprogramming - Linux is a multiprogramming system means multiple
applications can run at same time.
● Hierarchical File System - Linux provides a standard file structure in which
system files/ user files are arranged.
● Shell - Linux provides a special interpreter program which can be used to
execute commands of the operating system. It can be used to do various
types of operations, call application programs etc.
● Security - Linux provides user security using authentication features like
password protection/ controlled access to specific files/ encryption of data.

Structure of LINUX:-

Linux System Architecture is consists of following layers


● Hardware layer - Hardware consists of all peripheral devices (RAM/ HDD/
CPU etc).
● Kernel - Core component of Operating System, interacts directly with
hardware, provides low level services to upper layer components.
● Shell - An interface to kernel, hiding complexity of kernel's functions from
users. Takes commands from user and executes kernel's functions.
● Utilities - Utility programs giving user most of the functionalities of an
operating systems.

Practical-2

AIM:- To Study About Vi Editor.

Introduction:-

The VI editor is a screen-based editor used by many Unix users. The VI


editor has powerful features to aid programmers, but many beginning users avoid
using VI because the different features overwhelm them. This tutorial is written
to help beginning users get
accustomed to using the VI editor, but also contains sections relevant to regular
users of VI as well. Examples are provided, and the best way to learn is to try
these examples, and think of your own examples as well... There's no better way
than to experience things yourself.

Starting the VI editor:-


The VI editor lets a user create new files or edit existing files. The
command to start the VI editor is vi, followed by the filename.
For example to edit a file called example1, you would type vi example1 and then hit
return key. You can start VI without a filename, but when you want to save your
work, you will have to tell VI which filename to save it into later. When you start
VI for the first time, you will see a screen filled with tildes (A tilde looks like this:
~) on the left side of the screen.

Any blank lines beyond the end of the file are shown this way. At the bottom of
your screen, the filename should be shown, if you specified an existing file, and the
size of the file will be shown as well, like this:
"filename" 21 lines, 385 characters

If you started VI without a filename, the bottom line of the screen will just be
blank when VI starts.

To create or edit a file: vi [filename]


$ vi test

vi opens the file you specify in filename unless it does not exist. If the file does
not exist, vi opens a new file which
will be called filename. You should see something like
The column of "~" characters indicates that your are at the end of the file.

VI Editor Modes:-
The first thing most users learn about the VI editor is that it has two modes:

Command and insert. The command mode allows the entry of commands to
manipulate text. These commands are usually one or two characters long, and can
be entered with few key strokes. The insert mode puts anything typed on the
keyboard into the current file. VI starts out in command mode. There are several
commands that put the VI editor into insert mode. The most commonly used
commands to get into insert mode are a and i.
For example, hit i key and type "This is EASY.", then hit the escape key. Once you
are in insert mode, you get out of it by hitting the escape key. You can hit escape
two times in a row and VI would definitely be in command mode. Hitting escape
while you are already in command mode doesn't take the editor out of command
mode. It may beep to tell you that you are already in that mode.

Saving and Quitting a file:-

The command to quit out of VI is :q. Once in command mode, type colon, and 'q',
followed by return. If your file has been modified in any way, the editor will warn
you of this, and not let you quit. To ignore this message, the command to quit out
of VI without saving is :q!. This lets you exit VI without saving any of the changes.
Of course, normally in an editor, you would want to save the changes you have
made.The command to save the contents of the editor is :w. You can combine the
above command with the quit command, or :wq. You can specify a different file
name to save to by specifying the name after the :w.
For example, if you wanted to save the file you were working as another filename
called

example2, you would type :w example2 and hit return. At the bottom of your
screen, the filename and the size of the file will be shown like this:

"example2" [New file] 1 line, 14 characters

Basic Text and Command Modes:-

In this section, we will learn and practice the basic text and command modes in
order to be able to use VI editor more efficiently and effectively.

Editing with o option:- Hit o key to enter insert mode in a new line below
the current cursor position and type "This is very very easy." and get out of the
text mode by hitting the escape key. The letter O inserts mode in a new line above
the current cursor position.

Yanking and pasting multiple lines:-


Before we yank and paste multiple lines,
let's move the cursor to the beginning of the first line. Hitting k key k will move
the cursor up one line, thus, please hit the k key twice, which will bring the cursor
to the first line since the
cursor was on the third line of the example4 file. Other basic cursor movement
commands are :
h moves the cursor to the left one character position.
j moves the cursor down one line.
k moves the cursor up one line.
l moves the cursor to the right one character position.
w moves the cursor forward one word. If the cursor is in the middle of a word,
move the cursor to the first character of the next word.
To yank three lines from current cursor position downwards, hit the keys 3yy, then
hit p key to paste the 3 lines below the line of the current cursor position and save
the file as example5 via executing :w example5 command. However, since we
wanted to yank the
three lines, to the bottom of the file, hit u key to undo the pasting then hit G key
to move the cursor to the last line of the file if no line number specified before
executing the command, i.e. 4G will move the cursor to the forth line of the file,
and paste the yanked 3 lines by hitting p key and save the file as example6.
Example6 file should be as shown.
below;
This is EASY.
This is very very easy.Now, we are going to try to yank and paste this line.
This is very very easy.Now, we are going to try to yank and paste this line.
This is EASY.
This is very very easy.Now, we are going to try to yank and paste this line.

Replacing strings of text:-


A word that occurs in a file more than several times
can be replaced by using the command :1,$ s/word/word to replace/g. For example,
executing :1,$ s/EASY/easy/g will replace words EASY to easy from 1st till the
end of the line, which can be changed to any line number by changing "1" and/or "$"
right after the
colon. Then, please save the file as example7 and quit the VI editor by executing
:wq example7.
If you want to edit a read-only copy of a file, you can use the command view. For
example, type view example7 and hit enter key. You will view the example7 file with
a "read only" notification at the bottom of your screen '"example8" [Read only] 6
lines, 336 characters'. The view invocation is the same as VI except that the
readonly flag is set. For
more information about the vi and view editors, you can execute man vi or view
from the unix prompt to enter the VI editor manual.

Replacing Text:-

C: Change to the end of the line from the current cursor position.
R: Replace characters on the screen with a set of characters entered, ending with
the Escape key.
S: Change an entire line.
C: Change until . "cc" changes the current line. A count changes that many lines.
R: Replace one character under the cursor. Specify a count to replace a number of
characters.

EX Commands:-

The VI editor is built upon another editor, called EX. The EX editor only edits by
line.
From the VI editor you use the : command to start entering an EX command. This
list
given here is not complete, but the commands given are the more commonly used.

:w
Write out the current file.
:w filename

Write the buffer to the filename specified.


:w >> filename

Append the contents of the buffer to the filename.

:wq
Write the buffer and quit.
Operating System
Commands:
1. Mkdir – This command is used for making new directory.
Syntax – mkdir directory_name
2. Ls – This command is used for showing all the existing file.
Syntax – ls
3. Touch – This command is used for making a new file.
Syntax – touch file_name.extension
4. Cat – This command is used for showing content of a file.
Syntax – cat filename.extension
5. Cat>filename.extension – This command is used for entering contents in file.
6. Ctrl+d – This command is used for saving a file.
7. Cat file_name1.extension file_name2.extension> file_name.extension – This command is used
for merging the contents of file 1 and file 2 into a empty file.
8. Ls *.extension – This command is used for showing the file of a particular extension.
9. Pwd – this command is used for showing the present working directory.
Syntax – pwd
10. Rm – This command is used for deleting the file.
Syntax – rm file_name.extension
11. Rmdir – This command is used for deleting a directory.
Syntax – rmdir directory_name
Note: the directory should be empty for using this command
12. Mv – This command is used for moving file to directory.
Syntax – mv file_name directory_name
13. Head – This command is used for showing the first 10 lines of a file.
Syntax – head file_name.extension
14. Tail – This command is used for showing the last 10 lines of a file.
Syntax – tail file_name.extension
15. More – This command is used for showing the large content.
Syntax – more file_name.extension
16. Clear – This command is used for clearing the terminal window.
Syntax – clear
17. Tac – This command is used to reverse the order of file content.
Syntax – tac file_name.extension
18. Ping – this command is used for checking if the file is connected to the server or not.
Syntax – ping file_name.extension
19. Wc – word count tells how many words, letter, line, and characters are present in file.
Syntax – wc file_name.extension
20. Nl – shows the number of lines in a file.
Syntax – nl file_name.extension
21. History – This command shows all the commands used in terminal.
Syntax – history
22. Hostname – Tells the system name
Syntax – hostname
23. Id – this command is used to tell the system details.
Syntax – id
24. Chmod u=r – Gives the permission to only read the content of file.
Syntax – chmod u=r file_name.extension
25. Chmod u=w – Gives the permission to only write in the file.
Syntax – chmod u=w file_name.extension
26. Chmod u=rw – gives the permission to read and write in the file.
Syntax – chmod u=rw file_name.extension

Programs:
1. Arithmetic operators:
echo "enter two numbers"
read a b
echo "a= $a"
echo "b= $b"
sum=$(($a+$b))
echo "sum= $sum"
subtraction=$(($a-$b))
echo "subtraction= $subtraction"
multiplication=$(($a*$b))
echo "multiplication= $multiplication"
division=$(($a/$b))
echo "division= $division"

output:
2. Program to find if the year is leap or not:

echo "enter a year 'yyyy'"


read y
a=$(($y%4))
b=$(($y%100))
c=$(($y%400))
if [ $a -eq 0 -a $b -ne 0 -o $c -eq 0 ]
then
echo "$y is a leap year"
else
echo "$y is not a leap year"
fi

output:

3. Program to find the greatest number among three numbers:

echo "enter three number"


read a b c
if [ $a -gt $b ]
then
if [ $a -gt $c ]
then
echo "$a is greatest"
else
echo "$c is greatest"
fi
else
if [ $b -gt $c ]
then
echo "$b is greatest"
else
echo "$c is greatest"
fi
fi

output:
4. Program to swap number using third variable:

echo "enter two number"


read a b
echo "a=$a"
echo "b=$b"
echo "after swapping"
c=$a
a=$b
b=$c
echo "a=$a"
echo "b=$b"

output:

5. Program to swap number without using third variable:

echo "enter two numbers"


read a b
echo "a=$a"
echo "b=$b"
echo "after swapping"
a=$(($a+$b))
b=$(($a-$b))
a=$(($a-$b))
echo "a=$a"
echo "b=$b"

output:
6. Program of calculator using switch case statement:

echo "enter two number"


read a b
echo "a= $a"
echo "b= $b"
echo "1. addition
2. subtraction
3. multiplication
4. division"
echo "enter the operation"
read ch
case "$ch" in
1)sum=$(($a+$b))
echo "sum= $sum";;
2)sub=$(($a-$b))
echo "subtraction= $sub";;
3)mul=$(($a*$b))
echo "multiplication= $mul";;
4)div=$(($a/$b))
echo "division= $div";;
esac

output:

7. Write an script to search an element using linear search:

echo "enter the number of elements"


read n
echo "enter the elements:"
for ((i=0;i<n;i++))
do
read nos[$i]
echo nos[$i]=${nos[$i]}
done
echo "enter the element to be searched"
read a
for ((i=0;i<n;i++))
do
if [ $a -eq ${nos[$i]} ]
then
s=1
pos=$(($i+1))
fi
done
if [ $s -eq 1 ]
then
echo "element found at: $pos"
else
echo "element does not exist"
fi

output:

8. Write a script to sort an array using slelection sort:

echo "enter the number of element in the array"


read n
echo "enter the elements"
for ((i=0;i<$n;i++))
do
read nos[$i]
done
for ((i=0;i<$n;i++))
do
for((j=0;j<$n;j++))
do
if [ ${nos[$i]} -gt ${nos[$j]} ]
then
t=${nos[$i]}
nos[$i]=${nos[$j]}
nos[$j]=$t
fi
done
done
echo "sorted array :"
for ((i=0;i<$n;i++))
do
echo "${nos[$i]}"
done

output:

9. Write a script to print a * pattern;

a=0
while [ $a -lt 10 ]
do
b=$a
while [ $b -ge 0 ]
do
echo -n " $b "
b=$(($b-1))
done
echo
a=$(($a+1))
done
Output:
10. Write a script to generate a Fibonacci series:

i=1
a=0
b=1
echo "$a"
while [ $i -ne 10 ]
do
b=$(( $a + $b ))
echo "$b"
c=$a
a=$b
b=$c
i=$(($i+1))
done

Output:

11. Write a script to find the factorial of a number:

echo "enter a number"


read num
fact=1
while [ $num -gt 1 ]
do
fact=$((fact * num))
num=$((num - 1))
done
echo "factorial is : $fact"
Output:

You might also like