Osy Solved Manual Diploma World
Osy Solved Manual Diploma World
Osy Solved Manual Diploma World
LIST OF PRACTICALS
Sr. Title of the practical Page Date Date of Assessme Dated Remar
No No. of submiss nt Marks sign. of k s (if
perfo ion (50) teacher any)
r
manc
e
1. Install and configure
Linux (or alike) operating
system.
2. Execute general purpose
commands date, time, cal,
clear, banner, tty, script,
man.
3. Work with multiple linux
terminals and basic
commands : who, who am
I, login, passwd, su, pwd.
4. a) Use Operating services
(Editor, GUI, File
handling)
b) Run commands to start,
stop, and restart the
specified services in
Linux.
5. Execute process
commands 3 ps, wait,
sleep, exit, kill.
6. Execute file and directory
manipulation commands 3
ls, rm, mv, cp, join, split,
cat (file saving and
reduction operator), head,
tail, touch.
PRACTICAL SIGNIFICANCE :
Linux is the base of many of open source operating system designed to replace Windows and
Mac OS .It is free to download and install on any computer because it is open source. There are a
variety of different versions or distributions or available developed by different by different
groups. To prevent hacking attempts, Many organizations keep their LINUX operating system
private, many others make their variations of Linux available publicly So the whole can benefit
and large.
PROGRAM CODE :
1) Install and configure Linux (or similar) operating system on your computer. Write down
the steps for the same.
Ans.
Steps :
RESULT :
We successfully installed Linux Operating System (Ubuntu).
Ans.
Debian
Gentoo
Ubuntu
Linux Mint
Red Hat Enterprise Linux
CentOS
Fedora
Kali Linux
Windows NT
Windows 2000
Windows XP
Windows Vista
Mac OS X
Linux
FreeBSD
NetBSD
Advantages :
4) If you use your computer for work, then you can also use it for separate work and
leisure.
EXERCISE :
1) Differentiate between Command Line OS and GUI OS by giving example.
Ans.
CLI GUI
CLI is difficult to use. GUI is easy to use.
It consumes more memory. It consumes less memory.
High precision is obtained. Low precision is obtained.
Faster than GUI. Slower than CLI.
Needs only keyboard. Needs keyboard as well as mouse.
Input is entered only on command prompt. Input can be entered anywhere on the
screen.
No menus provided. Menus are provided.
No use of graphics. Uses Graphics.
Does not use any pointing devices. It uses pointing devices for selecting or
choosing options.
Examples: Microsoft Windows, DOS Examples: Microsoft Windows, macOS,
Shell, Mouse Systems PowerPanel Ubuntu Unity, Android, Apple's iOS,
BlackBerry OS, Windows 10 Mobile, Palm
OS-WebOS, and
Firefox OS for smartphones.
Ans. Sharing the processor, when two or more programs reside in memory at the same time,
is referred as multiprogramming. Multiprogramming assumes a single shared processor.
Multiprogramming increases CPU utilization by organizing jobs so that the CPU always has
one to execute.
3) Which are the extra facilities provided by Unix other than windows OS?
Ans.
Unix is more flexible and can be installed on many different types of machines,
including main-frame computers, supercomputers and micro-computers.
Unix is more stable and does not go down as often as Windows does, therefore
requires less administration and maintenance.
Unix has greater built-in security and permissions features than Windows.
Unix possesses much greater processing power than Windows.
Ans.
a) Windows 98
1. Integrated Microsoft Internet Explorer in Windows Explorer and Help System.
2. Quick Launch tool bar.
3. Windows 98 came up with a tool called System File Checker that scans and
restore corrupt or missing system files.
4. Extended support for the connection to networks.
b) Windows 2000
1. Support for FAT16, FAT32, and NTFS.
2. Increased uptime of the system and significantly fewer OS reboot scenarios.
3. Windows Installer tracks applications and recognizes and replaces missing
components.
4. Protects memory of individual apps and processes to avoid a single app bringing
the system down.
c) Windows XP
1. Reliability [Home and Professional] Configured on the reliability-proven kernel
of Windows 2000.
2. Faster response even in processing multi-tasks [Home and Professional].
3. Retention of data security and protection of user privacy.
4. Multi-task [Home and Professional] Operate multiple applications at the same
time.
PRACTICAL SIGNIFICANCE :
General purpose commands are inbuilt programs that can be invoked in multiple ways. These
commands work interactively from a terminal. A terminal that provides a command line interface
using shell program.
PROGRAM CODE :
1) Execute general purpose commands date, time, cal, clear, banner , tty, script, man.
Ans.
1) date
2) time
3) cal
4) clear
5) banner
6) tty
7) script
8) man
2) Write down different options for cal commands. (use $man cal)
Ans.
-J : Display Julian Calendar, if combined with the 3o option, display date of Orthodox
Easter according to the Julian Calendar.
-p : Print the country codes and switching days from Julian to Gregorian Calendar as they
are assumed by ncal. The country code as determined from the local environment is marked
with an asterisk.
-s country_code : Assume the switch from Julian to Gregorian Calendar at the date
associated with the country_code. If not specified, ncal tries to guess the switch date from
the local environment or falls back to September 2, 1752. This was when Great Britain and
her colonies switched to the Gregorian Calendar.
-y : Display a calendar for the specified year. This option is implied when a year but no
month are specified on the command line.
-A number : Months to add after. The specified number of months is added to the end of the
display. This is in addition to any date range selected by the -y, -3, or -1 options. For
example, 5cal -y -B2 -A26 shows everything from November of the previous year to
February of the following year. Negative numbers are allowed, in which case the specified
number of months is sub‐tracted. For example, 5cal -y -B-66 shows July to December. And
5cal -A116 simply shows the next 12 months.
-B : Months to add before. The specified number of months is added to the beginning of the
display. See -A for examples.
-C : Completely switch to cal mode. For cal like output only, use -b instead.
-d yyyy-mm : Use yyyy-mm as the current date (for debugging of date selection).
Ans.
--debug : annotate the parsed date, and warn about questionable usage to stderr
-R, --rfc-email : output date and time in RFC 5322 format. Example: Mon, 14 Aug 2006
02:34:56 -0600
--rfc-3339=FMT : output date/time in RFC 3339 format. FMT='date', 'seconds', or 'ns' for
date and time to the indicated precision. Example: 2006-08-14 02:34:5606:00
Ans. Script command is used to record all the terminal activities. By default all the
information is saved in file typescript. And to stop the typescript exit command is used.
Syntax: script [options] [file]
Ans.
While the cal/ncal commands display the current month by default, you can use the -
m command-line option in order to have a specific month displayed.
This option requires a numeric value (1-12) that represents the month you want the
command to display.
To display the month of January of current year: cal -m1
To display calendar of specific month and year: cal [ [month] year].
3) Give a single command to display the calendar of pervious, current and next month.
Ans. cal -3 command is used to display the calendar of pervious, current and next month.
4) Give the command to display full week day (eg. Sunday) using date command.
EXERCISE :
1) What is the output of the following commands?
Ans
a) $cal 04 2019
d) $cal -3
e) $cal -5
f) $cal -2000
2) Give the syntax of commands for displaying the output. (use date)
Ans.
a) This is ………. Month of the year ………. (Abbreviation for the month and 4-digit
year)
PRACTICAL SIGNIFICANCE :
Work with terminal environment to know about users and set their security. It includes current
status of all the users like details about all the users who accesses the terminal for particular
duration and path of directory.
PROGRAM CODE :
List down with all options for who commands and write its description. Note: Write terminal's
output in Result Section.
RESULT :
Ans. pwd
Ans. who
Ans.
EXERCISE :
1) Acquire the status of super user.
Ans.
Ans.
i)
ii)
PRACTICAL SIGNIFICANCE :
The purpose of computer systems is to allow the user to excute programs. So the Operating
system provides an environment where the user can conveniently run programs. The user does
not have to worry about the memory allocation or multitasking or anything. These things are
taken care of by the operating systems.
Editor : There are many ways to edit files in Unix. Vi Editor works in Unix. This editor enables
you to edit lines in context with other lines in the file. You can also use this editor to just read a
text file. An improved version of the vi editor which is called the VIM has also been made
available now. Here, VIM stands for Vi Improved.
GUI : Linux system provides both the interface that is GUI and CLI.As per the requirement
you can decide when you should use the Linux command line interface (CLI) and when you
should use a graphical user interface (GUI).
PROGRAM CODE :
Check all permissions started on your system. Stop the services which are not required for
long time.
RESULT :
cd
pwd
Ans. Menu may be defined as the commands and operations in a list which is presented to the
user in a computer system or communication system in terms of computing and
telecommunication.
Pop up menu
Menu bar
There are more menus but these are the most required and observed menu on the system.
Ans. Default installation of Ubuntu contains a wide range of software that includes
LibreOffice, Firefox, Thunderbird, Transmission, and several lightweight games such as
Sudoku and chess. Many additional software packages are accessible from the built in
Ubuntu Software (previously Ubuntu Software Center) as well as any other APTbased
package management tools. Many additional software packages that are no longer installed
by default, such as Evolution, GIMP, Pidgin, and Synaptic, are still accessible in the
repositories and installable by the main tool or by any other APT-based package management
tool. Cross-distribution snap packages and flatpaks are also available, that both allow
installing software, such as some of Microsoft's software, in most of the major Linux
operating systems (such as any currently supported Ubuntu version and in Fedora). The
default file manager is GNOME Files, formerly called Nautilus. All of the application
software installed by default is free software. In addition, Ubuntu redistributes some
hardware drivers that are available only in binary format, but such packages are clearly
marked in the restricted component.
Ans.
EXERCISE :
1) What are system calls provided by file management?
These system calls are responsible for file manipulation such as creating a file, reading a file,
writing into a file etc.
createFile()
readFile()
writeFile()
closeHandle()
open()
read()
write()
close()
Ans.
1) Program execution
2) I/O operations
3) File System manipulation
4) Communication
5) Error Detection
6) Resource Allocation
7) Protection
1. Program execution : Operating systems handle many kinds of activities from user
programs to system programs like printer spooler, name servers, file server, etc. Each of
these activities is encapsulated as a process. A process includes the complete execution
context (code to execute, data to manipulate, registers, OS resources in use).
2. I/O Operation : An I/O subsystem comprises of I/O devices and their corresponding
driver software. Drivers hide the peculiarities of specific hardware devices from the user.
3. File system manipulation : A file represents a collection of related information.
Computers can store files on the disk (secondary storage), for long-term storage purpose.
Examples of storage media include magnetic tape, magnetic disk and optical disk drives
like CD, DVD. Each of these media has its own properties like speed, capacity, data
transfer rate and data access methods.
4. Error handling : Errors can occur anytime and anywhere. An error may occur in CPU, in
I/O devices or in the memory hardware.
5. Resource Management : In case of multi-user or multi-tasking environment, resources
such as main memory, CPU cycles and files storage are to be allocated to each user or
job.
6. Protection : Considering a computer system having multiple users and concurrent
execution of multiple processes, the various processes must be protected from each
other's activities.
Ans.
File Management.
Process Management.
I/O Device Management.
Network Management.
Main Memory management.
Secondary-Storage Management.
Security Management.
PRACTICAL SIGNIFICANCE :
Process is program in execution.ps commands is used to manage and to see the active processes
on Unix operating system. Ps basically means 7Process Status8 which is used to display currently
running processes in Unix operating system.
The ps command is not easy to use as it presents number of parameters that makes
it complicated.
2) wait
The wait is one of the built-in commands of Linux. It waits for the completion of
any running process.
Waits until all background processes are completed and then exits.
3) sleep
Sleep command is used to introduce delay for a specific time.This command helps
to pause a process for a given time.
Suffixes can be used with command to specify exact time. 5s6 can be used for
seconds. 5m6 can be used for minutes, 5h6 can be used for hours and 5d6 can be
used for days.
4) exit
Generally shell script will exit with the last command8s exit status.
Used to quite the shell.
5) kill
Kill command is used to kill the process. User has to specify process ID for
killing the process.
Kill command sends TERMINATE signal to all the process IDs that are listed on
command line.
It may be difficult to use kill command as it uses process ID instead of its
command name.
For killing the process user should be the owner of process or must have logged in
from root user.
PROGRAM CODE :
$ ps
$ sleep 10
$ kill
$ wait
$ exit
Ans.
2. $kill pid : To show how to use a PID with the kill command.
Syntax : $kill pid
Ans.
Option Description
Ans. exit command in linux is used to exit the shell where it is currently running. It takes one
more parameter as [N] and exits the shell with a return of status N. If n is not provided, then
it simply returns the status of last command that is executed.
EXERCISE :
1) Observe the output of following commands
$sleep 30; date
$echo $$
Ans.
Ans.
Ans.
Ans.
Ans.
1. ps - If you run ps command without any arguments, it displays processes for the current
shell.
2. Wait -When wait command is executed with $process_id then the next command will
wait for completing the task of the first echo command. The second wait command is
used with '$! ' and this indicate the process id of the last running process.
3. Sleep - command is used to delay for a fixed amount of time during the execution of any
script.
4. Kill -kill command in Linux (located in /bin/kill), is a built-in command which is used to
terminate processes manually.
5. Exit- used to quite the shell.
CONCLUSION : In this practical we successfully install virtual box, Ubuntu on our laptop.
And successfully Run the basic process commands on Ubuntu.
PRACTICAL SIGNIFICANCE :
Basically the operations performed in unix or linux are done on a prompt or terminal which is
not stored anywhere. but most of the commands are return to store the information. One way is
to store the information in file. Various operation that can be performed on a file are create ,
open, read ,write ,move,close and rename.
Syntax: $ls
Options Meanings
Example:
$ls ??? list the names of the files with exact three character in it name
$ls d*s list of file names starts with d and ends with s
Example:
$ls
$ls
Options:
1. -i(interactive) : the mv command with -I option asks for confirmation $mv -I abc.txt
aab.txt
• Cp command: it I used to copy a file to destination file. If the command contains two file
names, then it is copies the contains of first file to the second file. If the 2nd file doesn8t exists
then first it creates one and content is copied to it. But if it existed then it is simply overwritten
without any warning.
Example:
$ls
xyz.txt
Check it now
• Join command: It is used for joning lines of two files on the basis of common field in each file
called as a key.
-t field separator
Example :
$cat stud1
Ajay 1990
Vijay 1992
Sujit 1991
$cat stud2
Ajay 50
Vijay 62
Sujit 70
Ajay 1990:50
Vijay 1992:62
Sujit 1991:70
• Split command: It is used to split the large file into smaller files. Default size is 1000 lines/file.
-tag name by default the split builds the o/p files named xaa , xab , xac …….
Example :
Check it now
-ls
• Cat command : It is used to create the file and displaying the contents of file/files.
<Cntrl d>
$cat sample
Where Cat is a command and sample is a argument. this Is sample file in UNIX. User can
display contents of more than one file and called as concatenation.
• Head command: it is used to read the first 10 lines of file.(10 lines by default) the no.of lines
to be displayed maybe specified in the head command.
Example :
• Tail command: it is used to print last few numbers of lines(10 by default) of a certain file, then
terminates.
Syntax: $tail{[+/-]n[lbc]}filename
Options meaning
L indicates line
B indicates blocks
C indicate character
Example :
Displays all lines starting from 20th lines of the student file.
Example :
$touch aaa
File saving and redirection operator : Generally UNIX commands are entered at the keyboard
and output resulting from these commands are displayed on the computer screen. The standard
input and standard output are actually taken or saved to files.
Example :
Output of 1st command is taken as input for 2nd command. In this example output of ls
command is saved into a file out.txt
In this example contents of file list1.txt and list2.txt is saved to todo.txt file.
Now check it
$ls list2.txt
PROGRAM CODE :
1) Create three files a1,a2,a3.
Ans.
Ans.
1) ls
2) mv
3) cp
4) rm
5) join
6) split
7) cat
8) head
9) tail
10) touch
Ans.
Answer: ls is a Linux shell command that lists directory contents of files and directories.
Examples:
Ans.
Code:
$ ls
$ mv a.txt geek.txt
$ ls
Code:
$ ls
$ cat geek.txt
India
$ cat b.txt
geeksforgeeks
$ mv geek.txt b.txt
$ ls
$ cat b.txt
India
Ans. Split command in Linux is used to split large files into smaller files. It splits the files
into 1000 lines per file(by default) and even allows users to change the number of lines as per
requirement.
Ans. join command is used to join the two files based on a key field present in both the files.
EXERCISE :
1) Write output of following commands :
i. Display all files names which starts with 7a8 and ends with 7y8.
ii. Enlist all the files beginning with 7m8 and ending with any range of 1 to 5.
iii. Show the contents of files whose file names contains exactly two characters.
iv. Create a file ABCD.txt, create a copy with XXX.txt. Rename the original file with
AACD.txt. Delete the file XXX.txt.
v. Display the inodes of any two files at the same time.
Ans.
i. Display all files names which starts with 7a8 and ends with 7y8.
ii. Enlist all the files beginning with 7m8 and ending with any range of 1 to 5.
iii. Show the contents of files whose file names contains exactly two characters.
iv. Create a file ABCD.txt, create a copy with XXX.txt. Rename the original file with
AACD.txt. Delete the file XXX.txt.
Ans.
a) awk
b) grep
c) head
d) tail
e) sort
f) uniq
g) less
h) more
i) tr
j) pr
k) fmt
l) Sed
3) How many lines will be displayed with head command if number is not specified.
Ans. 10 lines
4) Create two files chapter1 and chapter2 by asking the user before overwrite.
i. Copy contents of chapter1 and chapter2 by asking the user before overwrite.
ii. Display inodes of two files.
iii. Rename the file 7chapter18 to 7Lessson18
Ans.
i. Copy contents of chapter1 and chapter2 by asking the user before overwrite.
Ans.
i. $ls a*n
ii. $ls s?
PRACTICAL SIGNIFICANCE :
Data and programs are stored in Files. These are organized in directories. In a simple way, a
directory is just a file that contains other files(or directories).
a. mdkir
b. cd
c. rmdir
d. pwd
1) mkdir Command
It is used to create a new directory in a current directory .
$ mkdir <directory Name>
Example : $ mkdir CM5I
User can create more than one directory in a single command .
$mkdir subject1 subject2
If user wants to create directory on the specific path them syntax is:
Syntax:
$mkdir path/ directory name
2) cd Command
The Cd command is used to change directory. You can use it to change to any directory
by specifying a valid absolute or relative path.
Syntax:
$cd <directory Name>
Example:
$cd Directory Name
$cd CM5I
$cd To come out from current working directory.
Example :
$cd..
$cd/ It changes to root directory.
Example:
$cd/
3) rmdir Command
It is used to Delete/ remove directory. If the parent directory having subdirectories then
first all subdirectories will be deleted then the parent directory is deleted.
Syntax: $rmdir
4) pwd Command
Pwd stands for present working directory. This is most used linux command to see the
specific Unix directory on which the user is working on.
Syntax: $pwd
diff command
This command is used to show difference between two text files . It also tells which line
in one has to be changed to make the two files identical .
Syntax:
$diff filename1 filename2
The operations of the result should be like this –
a - Added the text to file
c - changes are made in the file
d - deletion operation is performed
< - lines from the first file
> - lines from the second file
$cat file1.txt
I need to go to the shop
I need to buy some mangoes
When I get home , I8ll wash the cat
$cat file12.txt
I need to go to the shop
I need to buy some mangoes
Oh yeah , I also need to by cheese
When I get home, I8ll wash the cat
Use the diff command to compare both files.
$diff file1.txt file2.txt
The above command should give the result as shown below-
2a3
>oh yeah, I also need to by cheese
From the output 2a3 means 5After line 2 in the first file, a line to be added: line 3 from
the second file 5.
Comm command
This command compare two sorted files. It compares each line of first file with its
corresponding line in the second file and generates 3 column output.
The first column lists the lines only in first file.
The second column lists the lines only in second file.
The third column lists the lines in both files.
Syntax:
$comm filename1filename2
Example:
$Cat student1 $cat student2
Harsh Harsh
Sujay Niket
Smith Ashutosh
$comm student1 student2
Sujay Niket Harsh
Smith Ashutosh
Pr command
dir command
It is used to list all files and directories
chmod command
It is used to change or set permissions ( read, write and execute ) for all the three
categories of users .
Types of users are 3 user , group and other
Syntax:
$Chmod<category ><operation > < permissions> < filename>
Example:
1) Assign the execute permission for user/owner,group and others.
$chmod ugo+x abc
2) Assign all permissions for group
$chmod g+rwx abc
3) Assign execute permission for the owner and remove read permission of group
and others.
$chmod u+x, go-r abc
4) Assign read the permission to all three users and remove all remaining
permissions.
$chmod ugo=r abc
This method uses a number to specify each set of permissions for the file . It assign
permission in three digits . First digit assign permission for owner, second digit for
group and third for others . Digits range is 0 to 7.
Syntax:
$chmod<three digit octal number><filename>
$chmod [u g o] file name
List of octal numbers:
Example: $chmod 750 abc
It assign all permissions for user , read and execute for group and no permissions for
other for file abc.
cmp command
This command is used to compare files when used without options . It uses two
filename as an argument and display the difference on the terminals.
$cmp filename1 filename 2
$cat student1 $cat student2
Harsh Harsh
Sujay sujay
Smith smith
$cmp filename1 filename2
Student1 student2 diff : char 6 line 1
PROGRAM CODE :
1) Execute File and Directory Manipulation commands.
1. mkdir
2. cd
3. rmdir
4. pwd
5. diff command
6. comm command
7. ls 3l
8. pr command
9. chmod command
a. Symbolic
b. Octal
Ans. Default permission for a directory is 0777, for files the permissions are 0666 from
which the default umask value 0022 is deducted to get the newly created files or directory
permission.
4) Assign all the permissions to your directory for all users using symbolic & octal methods.
Ans.
Ans.
Diff Command :
This command is used to show difference between two text files. It also tells which line in
one has to be changed to make the two files identical.
Syntax:
Comm command :
This command compares two sorted files. It compares each line of first file with its
corresponding line in the second file and generates 3 column output.
Syntax:
$comm filename1filename2
EXERCISE :
1. Write the commands for performing the following tasks sequentially
d. Remove the write permission for the owner for 8sample9 using symbolic method
2. What are the permissions assigned to file/files after execution of following commands?
Ans.
4. Assign read and write permission for the owner, write permission for the group and execute
permission for others using octal method for file mfile.
Ans.
5. Write commands to assign following permissions to file OSY using octal method
a. _ _ _ _ _ _ _ _ _ _
b. _rw_r_xr_ _
c. _r_xr_xr_x
Ans.
6. Write commands to assign following permissions to file OSY using symbolic method
a. _rwxr_xr_ _
b. _rwxrwxrwx
Ans.
b. $chmod ugo+rwx
PRACTICAL SIGNIFICANCE :
There are many text processing commands. A filter is commands that takes flow of data from the
standard input, process or filters it and sends the result to standard output. cut, wc, tr, sort or grep
are all simple filters.
PROGRAM CODE :
Execute text processing commands tr, cut, paste, wc, spell ,sort, grep, more
1) tr
2) cut
3) paste
4) wc
5) spell
6) sort
7) grep
8) more
Ans. Paste command is one of the useful commands in Unix or Linux operating system. It is
used to join files horizontally (parallel merging) by outputting lines consisting of lines from
each file specified, separated by tab as delimiter, to the standard output.
Ans. Ctrl+E or End command can be used moves the cursor to the end of the line.
Ans.
1. -l: This option prints the number of lines present in a file. With this option wc
command displays two-columnar output, 1st column shows number of lines present in a
file and 2nd itself represent the file name.
2. -w: This option prints the number of words present in a file. With this option wc
command displays two-columnar output, 1st column shows number of words present in a
file and 2nd is the file name.
3. -c: This option displays count of bytes present in a file. With this option it display
two-columnar output, 1st column shows number of bytes present in a file and 2nd is the
file name.
4. -m: Using -m option 7wc8 command displays count of characters from a file
5. -L: The 7wc8 command allow an argument -L, it can be used to print out the length of
longest (number of characters) line in a file. So, we have the longest character line
Arunachal Pradesh in a file state.txt and Hyderabad in the file capital.txt. But with this
option if more than one file name is specified then the last row i.e. the extra row, doesn8t
display total but it display the maximum of all values displaying in the first column of
individual files
6. –version: This option is used to display the version of wc which is currently running
on your system.
Ans.
sort : Sorts the lines alphabetically by default but there are many options
available to modify the sorting mechanism. Be sure to check out the man page to
see everything it can do
uniq : Removes duplicate lines. uniq has a limitation that it can only remove
continuous duplicate lines(although this can be fixed by the use of piping).
Assuming we have the following data.
wc : wc command gives the number of lines, words and characters in the data
Ans. Cat displays file contents. If the file is large the contents scroll off the screen before
we view it. So command 'more' is like a pager which displays the contents page by page.
EXERCISE :
1) Write the significance of following
First and second file is separated by '|' and second and third is separated by ','.After that
list is exhausted and reused.
III. -s(serials) ,combination of 3d and 3s ,-versions (write its syntax and example)
1) - s (serial):
Syntax :
Example
1 2 3 4 5
Arunachal Pradesh Assam Andhra Pradesh Bihar Chhattisgrah
Itanagar Dispur Hyderabad Patna Raipur
2) Combination of -d and 3s
Syntax :
Example
1:2:3:4:5
Arunachal Pradesh:Assam:Andhra Pradesh:Bihar:Chhattisgrah
Itanagar:Dispur:Hyderabad:Patna:Raipu
3) 3version
Syntax :
$ paste 3version
Example
1. Create a new file and practice executing shell commands from within the editor.
Capture the results of some shell commands into file
Example
2) Try the commands and write the outputs with its meaning
Output:
Meaning:
Output:
Meaning:
To squeeze repeat occurrences of characters specified in a set use the -s option. This
removes repeated instances of a character.
Output :
Meaning:
To delete specific characters use the -d option. This option deletes characters in the first
set specified. In that f character deleted from it.
PRACTICAL SIGNIFICANCE :
There are many ways to edit files in Unix. Editing files using the screen oriented text editor vi in
one of the best ways. This editor enables you to edit lines in context with other lines in the file.
Vi is intended as a plain text editor (similar to Notepad on Windows, or Textedit on Mac) as
opposed to word processing suite such as Word or pages. It does, however have a lot more power
compared to Notepad or Textedit.
Command Action
Command Action
:34 r file Import a file into the current file after line 34
Command Action
PROGRAM CODE :
File is created
Ans:
Sr No o O
1 Creates a new line for text Creates a new line for text entry
2 Command =o Command =O
Ans:
b. Press : (colon). The cursor should reappear at the lower left corner of the
screen beside a colon prompt.
3. What is effect of (type these at colon mode and observe the change in your fine)
Ans.
a. set nu
b. set ic
c. set nonu
Hide line numbers
d. set noai
1. Command mode: in this mode, you can open or create files, specify cursor
position and editing command, save or quit your work. Press Esc key to return
to Command mode.
2. Insert mode: In this mode, you can enter text into the display on your screen
to edit the file. To enter the Entry mode, you need to specify an input
command first. The input commands are: I for insert, o for overwrite, a for
append.
i. at colon mode
:abbr MSBTE Maharashtra State Board of Technical Education
Now in the beginning of your find type MSBTE and press space bar write
down the output
ii. Go to beginning of your file press 4YY then move to end of your files and
press P write the purpose of the command.
Ans: 4yy is used to copy four lines and p is used to paste those lines
EXERCISE :
1. Write the significance of following
Ans.
i. $ vi temp.txt
vi will create the file 5temp. txt6 for you. Save the file that you are in.
Create a file using vi editor and editing
In visual block mode, you can press I to insert text at the same position in
multiple lines, and you can press A to append text to each line in a block. As
well as inserting or appending text that you type, you can insert or append text
from registers, for example, the clipboard.
2. Create a new file and practice executing shell command from which thing the
editor capture the result of some shell commands into the file
CONCLUSION : So this practical was all about Vi editor. We have learned to create a new
file or open an existing one. we have also learned to insert, delete or remove the words from a
text file. In this practical, we run all the commands related to vi editor.
PRACTICAL SIGNIFICANCE :
If is a statement that allows the programmer to make a decision in the program based on
conditions he specified. If the condition is met, the program will execute other task the
programmer specified.
Operator Meaning
-eq Equal to
-ne Not equal to
-gt Greater than
-ge Greater than or equal to
-lt Less than
-le Less than or equal to
General Syntax:
1. Single Decision :-
Syntax:-
if [ condition ]
then
### series of code goes here
fi
2. Double Decision: -
Syntax:-
if [ condition ]
then
Statements if the condition is satisfied
else
Statements of code if the condition is not satisfied
fi
3. Multiple if Condition :-
Syntax:-
if [ condition1 ]
then
Statement for condition1
elif [ condition2 ]
then
Statements for condition2
else
Statements if the condition is not satisfied
fi
4. Double –Bracket :-
Syntax:-
if ((condition))
then
Statements goes here
fi
To type any program in Linux you need the compiler. vi editor is used for creating
file in Linux.
Write a shell script to display Welcome message with today8s date in it. In vi editor
wright a program code and save and quit with filename8sample.sh8.
$vi sample.sh
(Now press escape and i to change the input mode and type following program)
#sample.sh
#use of if-then statement
if whoami; then
varl=8whoami8
echo 5 Welcome $varl6
fi
if date; then
echo 5It display todays date
fi
echo 5This is end of script6
To run the script
$.sample.sh
Save this program press escape+shift+(colon) and type wq (:wq )
6Welcome Userl6
Mon Feb 25 22:29:29 PST 2019
5It displays todays date6
5This is end of script6
PROGRAM CODE :
Execute shell script by considering example to find passing grades of students using if
statement :
1. Single Decision
read grade
then
fi
then
fi
then
fi
then
fi
if [ $grade -lt 35 ]
then
echo "FAIL"
fi
Output :
2. Double Decision
read grade
if [ $grade -gt 40 ]
then
echo "Pass"
else
echo "Fail"
fi
Output :
3. Multiple if statements
read grade
if [ $grade -ge 90 ]
then
then
then
then
then
else
fi
Output :
Ans.
if [ "$username" == "abc" ]
then
if [ "$password" == "pwd" ]
then
else
fi
else
fi
Output :
Ans.
If[condition] If((condition))
The single brackets […] is the command . The double parentheses ((…)) is the format
for bash arithmetic expansion.
It is used to create commands in statements. It is used to test an arithmetic operations.
Syntax :- Syntax:-
if [ condition ] if((condition))
then then
### series of code goes here Statements goes here
Fi fi
Example :- Example:-
if [ 5$X6-lt606 ] if [[ $num -eq 42 ]]
then then # if/then branch
echo 6X is less then zero6 echo 'num is actually equal to 42'
fi else # else branch
echo 'num is not 42'
fi
3) Write script for finding greatest number among given three number.
Ans.
read n1
read n2
read n3
then
then
else
fi
Output :
EXERCISE :
1) Correct the following script and write its output.
Ans.
Error :
Program code:
read l
if [ ! -r $l ]
then
fi
O
u
t
p
u
t
if
Ans.
Error :
Program code:
read x
if [ $x -nt "/etc/passwd" ]
then
fi
Output :
PRACTICAL SIGNIFICANCE :
The for loops iterate through a set of values until the list is exhausted. In simple terms the for
loop operates on lists of items. It repeats a set of commands for every item in a list.
do
command1
command2
…. …
command
done
Example:
For var in 0 1 2 3 4 5 6 7 8 9
do
echo $var
done
So far you have looked at creating loops and working with loops to accomplish different tasks.
Sometimes you need to stop a loop or skip iterations of the loop. Following two statements that
are used to control shell loops.
This type of for loop can also be used similar to the C programming language. It is having by a
threeparameter loop control expression; consisting of an initializer (EXP1), a loop-test or
condition (EXP2), and a counting expression(EXP3).
#!/bin/bash
For((c=1;c<=5;c++)
do
done
1. The break statements: The break statement is used to terminate the execution of the entire
loop, after completing the execution of all of the lines of code up to the break statement using
break keyword .
2. The continue statement: The continue statement is similar to the break command, except that
is causes the current iteration of the loop to exit, rather than the entire loop.
3. Exit:
exit N
The exit statement is used to exit from the shell script with a status of N.
In vi editor write a program code and save and quit with filename ‗fact.sh7.
$vi fact.sh
(Now press escape and i to change the input mode and type following program)
While statement
Syntax:
While[[condition]
do
Done
Example:
a=1
while[$a-le 5]
do
a=7expr$a+17
done
case..esac statement;
Syntax:
Case value in
pattern 1)commands;;
pattern 2)commands;;
pattern 3)commands;;
..
*)Default
Example:
#!/bin/bash
NOW=$(date+‖%a‖)
case $NOW in
Mon)
Tue|Wed|Thu|Fri)
Sat|Sun)
*);;
esac
$cat fast.sh
read num
fact=1
while[$num-gt 1]
do
fact=$((fact*num))
num=$((num-1))
done
PROGRAM CODE :
1) Execute shell script by considering example like printing table of given number by FOR
loop
Ans.
do
done
Output :
******
****
**
Ans.
for (( i=1;i<8;i=i+2 ))
do
for (( j=1;j<7;j++ ))
do
if [ $i -le $j ]
then
else
if [ $i -eq 7 -a $j -eq 5 ]
then
echo "*"
fi
fi
done
echo ""
done
Output :
NUMBERS="1 2 3 4 5 6 7"
for NUM in $NUMS
do
Q='expr $NUM % 2
if [ SQ -eq 0 ]
then
echo "Number is an even number!!"
continue
fi
echo "Found odd number"
done
Ans.
no="1 2 3 4 5 6 7"
for n in $no
do
q=$(( $n % 2 ))
if test $q -eq 0
then
echo "even"
continue
fi
echo "odd"
done
Output :
b. #!/bin/sh
a=0
while [ $a -lt 10 |
do
echo $a
if [ $a -eq 5 ]
then
break
fi
a=$(( $a + 1 ))
done
Output :
Ans.
Ans.
x=0
y=1
no1=$no
do
z=$(( x + y ))
#echo $z
x=$y
y=$z
no=$(( no - 1 ))
done
Output :
Ans.
5) Write a shell script to accept five digit number and to perform addition of all the digits.
Ans.
sum1=0
do
i=$(( no % 10 ))
sum1=$(( sum1 + i ))
no=$(( no / 10 ))
done
Output :
EXERCISE :
Execute the script for the following
Ans.
do
echo $i
done
Output :
Ans.
i=1
j=1
do
do
if [ $i -le $j ]
then
fi
j=$(( j + 1 ))
done
j=1
i=$(( i + 1 ))
echo ""
done
Output :
Ans.
case $ch in
esac
Output :
CONCLUSION : We are able to do different programs using shell script and vi editor.
And also we successfully implemented Shell Scripts.
PRACTICAL SIGNIFICANCE :
In UNIX data and programs are stored in file. These are organized in directories. In a simple
way, a directory is just a file that contains other files (or directories). It can be done to find out if
a file exists or not on the file system with the help of BASH shell and IF command.
used which allows us to make decisions based on the success or failure of a command.
Following is the list of the same flags which we can use in file list operators.
-s file True if file exists and has a size greater than zero.
Example:
#! /bin/bash
read file_name
if [-f file_name]
then
else
fi
Ordinary Files - An ordinary file is a file on the system that contains data text or
program instructions. In this tutorial, you look at working with ordinary file.
Directories - directories store both special and ordinary files. For users familiar with
Special File - Some special files provide access to hardware such a hard driver, CD
ROM driver, modems and Ethernet adapters. Other special files are similar to aliases or
shortcuts and enable you to access a single file using different names.
PROGRAM CODE :
Write a shell script which accepts input as a file or directory and displays message whether
it is file or directory.
read file
if [ -f "$file" ]
then
else
if [ -d "$file" ]
then
fi
fi
Output :
Ans.
EXERCISE :
1) Write a shell script to copy source file into the destination file.
Ans.
read f1
read f2
if [ -f $f1 ]
then
cp $f1 $f2
else
fi
Output :
2) Write a shell script which displays list of all directories in your home directory.
Ans.
cd
ls -l |grep ^d
Output :
3) Write a shell script which displays list of all files in your home directory.
Ans.
read dir
if [ -d $dir ]
then
cd $dir
ls
else
fi
Output :
4) Write a file handling program. First check whether it is file or directory, then if it is file
the program shall ask user for choices of copying, removing and remaining files. Use
case statement.
Ans.
read file
if [ -d "$file" ]
then
else
echo "3.remove"
read ch
case "$ch" in
read cpfile
cp $file $cpfile
;;
read newname
mv $file $newname
;;
"3") rm $file
;;
esac
fi
Output :
CONCLUSION : We have successfully completed shell script to find out whether given file
exists. In this practical we have studied checking if a file exists, the most commonly used FILE
operators are -e and 3f
PRACTICAL SIGNIFICANCE :
In Unix files come with permissions, a way to decide who can read, write or execute a file. These
permissions are divided into three parts: those for the owner (user) of the file, those for the group
to which the owner belongs and then permissions for all the other users from the point of view of
what is allowed to do in a file or directory, permissions are for reading, writing and executing.
Test Commands
Test Returns true if
-r file True if file exists and is readable.
-s file True if file exists and has a size greater than zero.
-w file True if file exists and is writable.
-x file True if file exists and is executable.
PROGRAM CODE :
Write a shell script to find out whether - File has read, write and execute permissions.
read line
if [ -r $line ]
then
fi
if [ -x $line ]
then
fi
if [ -w $line ]
then
fi
Output :
Ans. When exception is thrown by main() method, Java Runtime terminates the
program and print the exception message and stack trace in system console.
The throws clause only states that the method throws a checked
FileNotFoundException and the calling method should catch or rethrow it
EXERCISE :
1) Write a shell script which displays the list of all executable files in the current working
directory
Ans.
pwd
ls > f
exec < f
do
if [ -f $line ]
then
if [ -x $line ]
then
echo 5$line6
fi
fi
done
Output :
2) Write a shell script which displays a list of all the files in the current directory to which
user has read, write and execute permission.
Ans.
pwd
ls > f
exec < f
do
if [ -f $line ]
then
then
fi
fi
done
Output :
3) Write a shell script which accepts a filename and assign it all the permissions.
Ans.
Read file
Output :
PRACTICAL SIGNIFICANCE :
In Multiprogramming systems, the Operating system schedules the processes on the CPU to have
the maximum utilization of it and this procedure is called scheduling. The Operating System uses
various scheduling algorithm to schedule the processes. First come first serve (FCFS) scheduling
algorithm simply schedules the jobs according their arrival time.
PROGRAM CODE :
Consider the processes P1, P2, P3, P4 given in the below table, arrives for execution in
the same order, with Arrival Time 0, and given Burst Time, Find using the FCFS
scheduling algorithm.
P2 6
P3 3
P4 2
#include<stdio.h>
#include<conio.h>
int main()
{
int n,bt[20],wt[20],tat[20],avwt=0,avtat=0,i,j;
printf("\nEnter Total Number of Processes(maximum 20):");
scanf("\n%d",&n);
printf("\n enter process burst timen");
for(i=0;i<n;i++)
{
printf("\nP[%d]:",i+1);
scanf("\n%d",&bt[i]);
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
}
printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time:");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
avwt+=wt[i];
avtat+=tat[i];
printf("\nP[%d]\t\t%d\t\t%d\t\t%d",i+1,bt[i],wt[i],tat[i]);
}
avwt/=i;
avtat/=i;
printf("\n\nAverage Waitng Time: %d",avwt);
printf("\nAverageTurnaround Time: %d",avtat);
return 0;
}
Result/Output :
When a process switches from the running state to the waiting state(for example,
I/O request, or invocation of wait for termination of one of the child processes).
When a process switches from running state to the ready state (for example, when
an interrupt occurs).
When a process switches from the waiting state to the ready state (for example,
completion of I/O).
When a process terminates.
EXERCISE :
1. Draw the Gantt chart for above mention example.
Gantt chart:
P1 P2 P3 P4
0 21 27 30 32
2. Calculate average waiting time using RR algorithm for following set of processes
with the length of the CPU burst time given in milliseconds. ( Time quantum 20 ms ).
P1 P2 P3 P4 P2 P3 P4 P2 P3 P4 P3 P4 P4
P1=0
P2=12+(72-32)+(132-92)=92
P3=32+(92-52)+(137-112)+(177-157)=117
P4=52+(112-72)+(157-132)+(195-177)+(215-215)=135
0+92+117+135 ÷4 = 344÷4= 86
1) FCFS
Gantt Chart:
P1 P2 P3 P4
0 10 14 28 36
Waiting time
P1=0
P2=10-1=9
P3=14-2=12
P4=28-3=25
2) Pre-emptive SJF:
Gantt chart:
P1 P2 P4 P1 P3
0 1 5 13 22 36
Waiting Time:
P1=12
P2=1-1=0
P3=22-2=20
P4=5-3=2
PRACTICAL SIGNIFICANCE :
When there is a page fault, the referenced page must be loaded. If there is no available frame in
memory, then one page is selected for replacement. if the selected page has been modified, it
must be copied back to disk (swapped out). A page replacement algorithm is needed to decide
which page needs to be replaced when a new page comes in.
PROGRAM CODE :
#include<stdio.h>
int main()
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
scanf("%d",&no);
for(i=0;i<no;i++)
frame[i]= -1;
j=0;
for(i=1;i<=n;i++)
printf("%d\t\t",a[i]);
Flag =0;
for(k=0;k<no;k++)
if(frame[k]==a[i])
Flag=1;
if (Flag==0)
frame[j]=a[i];
count++;
for(k=0;k<no;k++)
printf("%d\t",frame[k]);
printf("\n");
return 0;
getch();
Result/Output :
PRAC
TICAL
RELA
TED
QUES
TIONS
:
Disadvantages of FIFO:-
1. FIFO method is improper if many lots are purchased during the period at different
prices.
2. The objective of matching current costs with current revenues can not be achieved
under FIFO method.
3. If the prices of materials are rising rapidly, the current production cost may be
understated.
4. FIFO method overstates profit especially in inflation.
EXERCISE :
1) Consider reference string 9,7,6,1,7,6,1,2,7,2 the number of frames in the memory is 3.
Find out number of page faults and page hit respective to
FIFO LRU
FIFO I First in First Out LRU is Least Recently Used
Number of page fault is more than LRU Number of page fault is less than FIFO
Suffer from belady8s anomaly Does not suffer from belady8s anomaly
Simple to implement Considered to be good