0% found this document useful (0 votes)
17 views54 pages

Linux Practical Edited

Uploaded by

smritisingh9180
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views54 pages

Linux Practical Edited

Uploaded by

smritisingh9180
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

2022-23

BCA-2

ASSIGNMENT-1
AIM 1:- Change the wallpaper, screensaver in Gnome, KDE.
Sol:- Gnome:
You can't get better than that: Switch to your desktop, find an empty place,
right- click and there you go: "change desktop background". Select this and
now you are in a dialog where you can select your wallpaper.

Couldn't see it on the list? Why don't you click "Add", which takes you to a
file browser where you can select your favorite image?

KDE:
KDE is also simple. Right-clicking your desktop brings the following menu,
where you choose "Desktop Settings." to proceed.

Don't fear this option because you will be taken to a compact dialog, which
you can adjust virtually all settings for your desktop.

1|Page
2022-23
BCA-2

On the "Wallpaper" section there is a small floppy disk icon which will take
you to a file browser, where you will be able to select your desktop
background. Or, you can proceed
with the "New Wallpaper" option if you want to experiment a little bit with
the dialogs.

Changing the screensaver using Gnome

To change your screensaver:


1. Go to System, then select Preferences, and choose Screen Saver.

2. You can choose which screensaver you desire from the Screensaver
theme list on the left-hand side of the screen..

3. You can then preview the screensaver by clicking Preview .

4. Next, set the time you want the screensaver to appear by using the
Regard the computer as idle after: bar.

5. Choose whether or not you want your screensaver to start when your
computer goes idle and/or if you want your computer to lock when your
screensaver goes active..

6. Finally, click Close.

2|Page
2022-23
BCA-2

Changing the screen saver using KDE

To change the screen saver:


1. Go to K Menu, then under Actions go to Settings,
Select Appearance and Themes, And click Screen Saver.

2. Under Screen Saver, select the desired screen saver from the list. Select
Setup...To setup the screen saver, and click Test to preview your screen
saver.

3. Check Start automatically if you want the screen saver to start on its
own after a time you designate using the drop-down menu.

4. Check Require password to stop if you want your screen to lock after the screen
saver has activated, and then select the time from the drop-down menu you want the
password lock to start after.

3|Page
2022-23
BCA-2

5. Click Apply.

4|Page
2022-23
BCA-2

ASSIGNMENT-2

AIM2:- Install Linux with following


specification username, password, partitions
for various directories such as/etc/home, etc.

Sol:- We install linux in 2 steps:-


1) Preparation of linux installation.
2) Installation of linux.

1) Preparation of Linux installation:


a) Hardware Requiremnts

 Pentium IV Processor
 256 MB RAM
 8GB Free Hard Disk Space
 DVD ROM
 MM Keyboard
 Mouse
 Sound Card
b) Linux Bootable DVD
It is necessary to have linux bootable DVD
recommended RED HAT Linux.
c) Create free space for installation of linux.
In order to install RED HAT Linux you must make disk space
available for it. This disk space needs to be separated from the disk space
used by other operating systems which you may have installed on your
computer such as windows. This is done by dedicating one or more partition
to RED HAT Linux.
If RED HAT Linux will share your system with another OS you will
need to make sure you have enough disk space on your hard disk for this dual
boot installation.
First you format one hard disk from your first OS It is very important
that drive which is to be formatted should be larger than 8GB.
In other words your computer units have enough unpartitioned disk
space for the installation of RED HAT Linux. You must have one or more
partition that may be deleted them by filling up enough disk space to install
RED HAT Linux. After formatting your hard drive do the following steps :-
5|Page
2022-23
BCA-2

2) Installation of Linux:
This assignment explains how to perform a RED HAT Enterprise
Linux installation from DVD ROM using graphical mouse based installation
program the following topics are discussed
a) Configuration of your computer BIOS.
b) Booting the installation program from DVD ROM.
c) Selection of Boot option.
d) Checking DVD for error.
e) Welcome screen.
f) Language selection screen.
g) Keyboard configuration screen.
h) Installation type.
i) Disk partition setup.

 Configuration of computer BIOSource


First restart your computer.
To change your BIOS settings match the instructions provided on your
display when your computer first boots you will see a line of text telling you
to press [F] key to enter the BIOS setting.
Once you have entered your BIOS setup program, find the section where
you can change your boot sequence. There is often C,A or A,C (depending
on whether you boot from your hard disk[C] or a diskette drive [X] change
the sequence so that the CDROM is first in you boot default) is second. This
instructs the computer to first look at CDROM drive for bootable media on
CDROM drive. It will then check your hard drive or diskette drive.
Save your changes before exiting the BIOS for more information program
from the DVDROM (refers to the documentation that comes with your
system).

 Booting the installation program from DVD or


CDROM

To boot from RED HAT Linux DVD Follow these


steps:-
1) Resume all media : CD or DVD from DVDROM.
2) Insert the RED HAT Linux DVD in your DVDROM.
3) Restart your computer.

 Selection of boot options


After restarting computer, the computer automatically identifies your
DVDROM drive.
If found continue to next stage of installation process.
6|Page
2022-23
BCA-2

The Linux boot screen will appear on the screen. In Linux boot screen,
there are 2 options for installations.
1. Graphical Mode
2. Text Mode
To install in text mode type — Linux text 

To install in GUI mode press 


If you have used a GUI before you are already familiar with the process, use
your mouse to navigate the screen. Click button or enter.

 Checking DVD for error


This process only for formatting the two messages you see on screen.
To begin testing the CD media before installation choose skip media test and
start installation.
If your DVD is fresh and without any scratches, you can skip those test
otherwise you test DVD media before installation.

 Welcome Screen
After testing media test, the RED HAT Linux welcome screen will appear
on your screen.
The welcome screen does not prompt you for any input, please read over
the help text in the left panel for additional instruction and information on
where to register your RED HAT Linux.

Please notice the hide help button at the left corner of the screen. The
help screen is open by default. If you do not want to view the help information, click
on hide help to minimize the help portion of screen.
Click on next button to continue.

 Language selection screen


Selecting the application language also helps to get you time zone
configuration tab in the installation.
The installation program tries to define the application time zone
configuration based on what you specify on the screen.
Once you select the appropriate language click next to continue.

 Keyboard configuration
Using your mouse, select the current layout type (ex- English for
keyboard you would to prefer to use for installation as a system default)
Once you have made your selection click next to continue.

 Installation type
7|Page
2022-23
BCA-2

Choose the type you would like to perform RED HAT Linux allow you to
choose the installation type that fills your need.

1) Personal desktop.
2) Workstation.
3) Server.
4) Custom.

Select the personal desktop button and click next.

 Disk partitioning setup


On this screen you can choose to perform automatic partition or normal
partition using disk drive.
Automatic partitioning allows you to perform an installation without
having to partition your drive yourself. If you do feel comfortable with
partitioning your system it is recommended that you not choose to partition
manually and instead let the installation program partition for you.
To partition manually choose the disk drive partitioning tool.
The disk drive will appear on your computer screen. Disk drive offers a
graphical representation of your hard drives.
By using your mouse, click once to highlight a particular field in
graphical display.
Double click to edit an existing partition or to check a partition act of
existing free space.
Above the display you will see the drive name, the end nodes of hard
drive as detected by installation program.

New is used to execute a new partition.


Edit is used to modify attributes of the partition currently selected in the
partition section.
Delete is used to remove partition.
Reset is used to restore disk drive to original state.
Raid is used provide redundancy of any or all partition.
Wm allow you to create an
lvm (logical volume)
 Partition fields
Mount point/Raid/Volume
A mount point is like location within the directory hierarchy at which a
volume executes. The volume is “mounted” at location this field indicate
where the partition will be.

8|Page
2022-23
BCA-2

 Adding Partitions
First select your formatted hard disk drive. Delete partition by clicking on
delete button. Now you can see free hard drive partition with no file systems.
Select this drive. Click on new button to add. A dialogue box appears. First
we create boots partition which is denoted by C (boot). The minimum space
for boot is 100MB but we create 300MB for boot partition.
In mount point -- /boot
File system – ext 3
Allowable drive size – 300MB
1) Click on OK button, the root partition is created.
2) Select your free space in disk and click new. Second we create swap
partition which is allocated by (swap). Space for swap is twice of your RAM.
Mount point file system – swap
Available drive size – 700MB
Click on OK button.
3) Select free space on your disk and click new button. Third we create root
partition. It is denoted by (I). The space for root is more than 3GB.
Mount point -- /
File system – ext 3
Available drive size – 700MB
Click on OK button.
Now the three main partitions has created. Click on NEXT
button.

 Network configuration.
If you do not have network device (physical LAN card or virtual LAN)
simply select automatically UHPC option where set host name and click
NEXT.

 Language support selection.


You can install and support multiple languages for use on your system.
You must select a language to use as the default language selection and click
next button.

 Set root password


Setting up a root password is one of the important steps during
installation. Your root is similar to administrator used on window NT
machines. Type your password more than 6 characters and click on NEXT
button.

 Package group selection


9|Page
2022-23
BCA-2

Now that you have made most of the choice for your installation, you
already confirmed the default installation packages selection or customize
packages for your system.

Select customize the set of packages to be installed option from the


screen. Clicking NEXT button takes you to the package group selection
screen.

The package screen will wish to install select executing (at the end of
component list) install all packages included RED HAT Enterprise Linux.

Click on NEXT button to complete installation procedure.

Now installation will be started. After installation, computer restart


automatically and linux screen will appear which asks for username and
password. After giving both, Linux Window appears.

The RED HAT Linux is ready for use.

10 | P a g e
2022-23
BCA-2

ASSIGNMENT-3
AIM3:- Add a user and password, change the
password.
Sol:-

To add a user:

To Create a new user account under any Linux Distribution use


command called useradd.

The system administrator is responsible for creating account.


Login as root user .

Syntax: useradd [option] {username} Few common options:

i) –ccomment: Adda comment for the user ii)–


dhome- directory: Createnewhome-directory
iii) –e yyyy-mm-dd: Date for the account to be disabled

Example: useradd GDRCST

To change password:

You must login as root user, type the command to change

password for user GDRCST

$ passwd <username>
Enter old password: <old password>
Enter new password: <new password>
Retype new password: <new password>
passwd: password updated successfully

11 | P a g e
2022-23
BCA-2

ASSIGNMENT-4

AIM 4:- Add and remove a group.


Sol:-

Use groupadd command to create a new group.

For example, add a new group called BCA:

Code:

groupadd BCA

To delete a group use groupdel command.

For example delete a group called oldbca

Code:

groupdel oldbca

12 | P a g e
2022-23
BCA-2

ASSIGNMENT-5
AIM5:- Create partition on your disk.
Sol:-
After you backup your system, make the necessary boot and for supplemental
disk you must prepare your system’s hard disk for Linux.

RED HAT provides a program called disk dwid to partition your hard
disk.

For CALDERA and DEBIAN you use a program called tdisk.

You should plan your disk partition and also plan how much disk space
yowant to allocate to each partition because this partition of installation
provides the greatest source of problems especially if you run out of disk
space. The following partition and size are good starting point.

swap 64MB
boot 16MB
usr 600 + MB
var 256MB
home all available space

USING VI EDITOR DO THE FOLLOWING


EXERCISE
13 | P a g e
2022-23
BCA-2

ASSIGNMENT-6
AIM 6:
In a file
a) Replace the word ‘has’ with ‘has not’.
b) Locate nth character.
c) Sort lines 21 to 40.

Sol:-
a) Syntax is a %s/old-string/new-string/

Let us say you would like to find a word called "has" and replace with "has not".

 First hit [Esc] key

 Type : (colon) followed by %s/has/has not/ and hit


[Enter] key.

 :%s/has/has not/
Above command will replace first occurrence of word ‘has’ with ‘has not’ on all lines.
The % is shorthand for all lines.

To replace all occurrences of word ‘has’ with ‘has not’ on all lines, use the g option
(which indicates all occurrences on a line).

 :%s/has/has not/g

Note that the g can be replaced with a number 1,2,...N to change only the n'th
occurrence on each line.

b) To locate ‘a’ character in a file.

:/a

c) To locate ‘apple’ string in a file.

:/apple

d) To sort lines from 21 to 40.

:21,40: sort

14 | P a g e
2022-23
BCA-2

ASSIGNMENT-7

AIM7:- In a file copy/cut and paste the following text


a) At ith line, n lines to jth line.
b) Yank a few words.
c) Cut and paste n words to ith in lth line.

Sol:-
a
)  To copy one line use

yy command

 To copy n lines use <number of lines> + yy

Ex- 6yy

 To delete or cut one line use

dd command

 To delete or cut n lines use <number of lines> + dd

Ex- 6dd

 To paste a line use

p command

b)
 To copy or yank a word use

yw command

 To copy or yank n words use <number of words> +yw

Ex- 7yw

c)
 To delete line use

dw command

 To paste words use

p command

15 | P a g e
2022-23
BCA-2

ASSIGNMENT-8
AIM8:-
Open two files ‘txtfiles’ and ‘newfile’ and copy/cut 5 lines txtfile and paste them
newfile using vi editor.

Sol:-
vi txtfile . newfile

5yy
:n
p

The above procedure will first edit 2 files namely ‘txtfile’ and ‘newfile’ then 5 lines
will be yanked. n is used for editing next file and p does the task of pasting last
yanked line to filename ‘newfile’.

16 | P a g e
2022-23
BCA-2

WRITE COMMANDS

ASSIGNMENT-_9
AIM9:
a) -List all files that match a class.
Sol:- ls command is used to list the files

ls -l *.txt

It shows all the ‘.txt’ files.

ls -l *.c

It shows all ‘.c’ files.

b) List all files that do not match a class.


Sol:- ls -l !*.txt

It displays all the files which are not ‘.txt’

c) Change the file permissions.

Sol:-

chmod command is used to set the permission of one or more files for all 3
categories (user, group and other). It can be run only by the user (os user) and
super user. The command can be used in two ways:

 In a relative manner by specifying the changes to current


permission.

 In a absolute manner by specifying the final permission.

Relative Permission

chmod takes as its arguments as expression computing some letters and


symbols that completely describe user category and type of permission being
assigned or removed. The expression contains 3 components.

1. User category (user, group, other)


17 | P a g e
2022-23
BCA-2

2. The operation to be performed (assigner or remove a


permission)
3. The type of permission (read, write, execute)

For ex:-

 chmod u + x <filename>

Grant permission only for user to execute.

 chmod ugo + x <filename>

This command applies to all category.

 chmod go –r <filename>

To remove read permission from both group and other.

 chmod a –x, go + r <filename>

To remove execute permission from all (a –x) and assign read permission to
group and others (go +r).

Abbreviation used by chmod:

u user
g group
o others
a all
r read permission
w write permissio
x execute permission
+ assign permission
- remove permission
= assign absolute permission

c) Display the lines in a file that contain a particular word.


Sol:- grep command is used to display or search lines in a file that contain a
particular word
For Ex:-
grep [pattern][filename]

grep ‘harsh’ file

18 | P a g e
2022-23
BCA-2

This show all lines which contain the word ‘harsh’

d) Append the contents of two files in a file JABC.

Sol:- cat command is used to create and append the file.

For ex:- cat > file 1


Hello world
^d

Cat > file 2


Good morning
^d

cat file1 file2 > file JABC

cat file JABC

Hello world Good morning

e) Count number of files in a directory

Sol:-

ls command is used to see a list of files and directory.

wc command is used to count word or lines.

‘|’ is used to use 2 commands at one time.

19 | P a g e
2022-23
BCA-2

WRITE SHELL PROGRAMMING

ASSIGNMENT-10

AIM10:- Display all the users currently logged


in details with column header.
Sol:-
Step1:- open a vi-editor file –vi column header

Step2:-write the following code.

Coding-
echo “currently logged in detail with column header”

who-H

wq!

Step-3:-change the file permission in executable mode.

Chmod u+x column header

Step:-4-running the shell script program-./column header

Output:-
Rungta@Rungta:~$ ./column header

currently logged in detail with column header

NAME LINE TIME COMMENT

Rungta tty7 2021-11-15 16:57 (:0)

Rungta pts/0 2021-11-15 16:57 (:0)

Rungta@Rungta:~$

20 | P a g e
2022-23
BCA-2

ASSIGNMENT-11
AIM11:-
List all files in current directory and save the list in a file
ABC. Also save the contents of the files in ABC and
display the contents in ABC in sorted order.
Sol:-
Step:-1 open a vi editor file -vi abc.sh

Step2:- write the following code:-vi abc.sh

Coding:-

tput clear

echo

echo

ls> abc

cat abc

sort abc

cat abc

wq!

Step:-3 change the file permission ion executable mode.

Chmod u+x vi abc.sh

Step:-4 running the shell script program-./abc.sh

Output:-

Rungta@Rungta:~$ ./abc.sh a3
a4 a5 a6 abc

21 | P a g e
2022-23
BCA-2

addttion.sh add.sh cmdline.sh column day.sh desktop dir.sh division.sh documents downlo
examples.desktop exam.sh
f f2
fact.sh fibo.sh file file# file

22 | P a g e
2022-23
BCA-2

ASSIGNMENT-12

AIM12:-Sort the contents of a file ABC and save it


in OABC.

Sol:-
Step:-1 open a vi editor file -vi sort.sh

Step2:- write the following code:-vi sort.sh

Coding:-
tput clear

echo

echo “BEFORE SORTING abc: “

cat abc

sort abc | cat > oabc

echo “AFTER SORTING oabc :”

cat oabc

wq!

Step:-3 change the file permission ion executable mode.

Chmod u+x vi sort.sh

Step:-4 running the shell script program-./sort.sh

Output:- Rungta@Rungta-H61H2-MV:~$ ./sort.sh BEFORE SORTING abc:-


a1 a2 a3 a4

23 | P a g e
2022-23
BCA-2

a5

a6

abc

addition.sh

add.sh

cmdline.sh

column

day.sh

desktop

dir.sh

division.sh

documents

downloads

even
_no

example.desktop

exam.sh

while_loop.sh

AFTER SORTING oabc

a1

a2

a3

a4

a5

a6
24 | P a g e
2022-23
BCA-2

abc

addition.sh

add.sh

cmdline.sh

column

day.sh

desktop

dir.sh

division.sh

documents

downloads

even_no

example.desktop

25 | P a g e
2022-23
BCA-2

26 | P a g e
2022-23
BCA-2

ASSIGNMENT-13
AIM:13-To input a number and test whether it
is +ve, -ve or zero.

Sol:-
Step1:- open a vi-editor file- vi pos_neg

Step2:-write the following code. vi pos_neg

Coding:-

echo ”enter a number:”

read num

if [ $num –lt 0 ];
then

echo “the number is negative”

elif [ $num –gt 0]; then

echo ”the numbe is positive”

else

echo “the number is”

zero.” Fi

wq:!

Step3:- change the file permission in executable mode.

Chmod u+x pos_neg

Step4:-running shell script program-./pos_neg

27 | P a g e
2022-23
BCA-2

Output:- Rungta@Rungta-H61H2-MV:~$ ./ pos_neg Enter a number :


-5
The number is negative Rungta@Rungta-H61H2-MV:~$

28 | P a g e
2022-23
BCA-2

ASSIGNMENT-14

AIM14:-To list only directories in current path.


Sol:-
Step1:-open a vi-editor file-vi dir.sh

Step2:-write the following code. Vi dir.sh

Coding:-

echo “the directories in current path are:”

for f in ‘ls’

do

if [ -d $f ];

then

echo $f
done
fi
wq:!

Step3:-change the file permission in executable mode.

Chmod u+x dir.sh

Step4:-Running the shell script program -./dir.sh

29 | P a g e
2022-23
BCA-2

Output:-
Rungta@Rungta-H61H2-MV:~$
./dir.sh
The directories in current path are: Desktop
Documents Downloads File1 Music Pictures Public Templates Video
Rungta@Rungta-H61H2-MV:~$

30 | P a g e
2022-23
BCA-2

ASSIGNMENT-15

AIM15:-To print greatest of three numbers.

Sol:-

Step1:-open a vi-editor file-vi greatest.sh Step2:-write

the following code. Vi .greatest.sh Coding:-

echo ”enter first number:” read

echo ”enter second number:” read

echo ”enter third number:” read

echo “a=”$a

echo “b=”$b

echo “c=”$c

if [ $a –gt $b ]

then

if [ $a –gt $c ]

then

echo “ $a is greatest “ fi

else

if [ $b –gt $c ]

then

echo “ $b is greatest”

else

31 | P a g e
2022-23
BCA-2

echo “ $c is greatest”

fi

fi

wq:!

Step3:-change the file permission in executable mode.

Chmod u+x greatest.sh

Step4:-Running the shell script program -./greatest.sh

Output:-
Rungta@Rungta-H61H2-MV:~$./great Enter first number:
5
Enter second number:
8
Enter third number:
2
8 is greatest
Rungta@Rungta-H61H2-MV:~$

32 | P a g e
2022-23
BCA-2

ASSIGNMENT-16
AIM16:-To print 12 terms of Fibonacci series.
Sol:-
Step1:-Open a vi-editor file- vi fibo.sh

Step2:-write the following code.vi fibo.sh

Coding:-

tput clear

echo ” the Fibonacci series is as follows: ”

let a=0 b=1

echo $a

echo $b

for ((n=3; n<=12; n=n+1))

do

let c=a+b

echo $c

let a=b

let b=c

done

wq:!

Step 3:- change the file permission in executable mode.

Chmod u+x fibo.sh

Step4:-running the shell script program-./fibo.sh

33 | P a g e
2022-23
BCA-2

Output:-
The Fibonacci series is as follows: 0
1
1
2
3
5
8
13
21
34
55
89
Rungta@Rungta-h61h2-mv: -$

34 | P a g e
2022-23
BCA-2

ASSIGNMENT-17
AIM17:-To display all users currently logged
in & also check a particular user every 30
seconds until he logs in.

Sol:-
Step1: open a vi-editor file-vi logged.sh

Step2:- write the following code-vi logged.sh

Coding:-

Who # display all user

Who am I # display particular user

time + t2

echo $ time

echo “ have a nice program

wq:!

Step 3:- change the file permissition in executable mode.

Chmod u+x logged .sh

Step4: running the shell script program-./logged.sh

Output:-
Rungta@Rungta-h61h2-mv:-$ ./log

Rungta tty7 2013-12-16 19:05 (:0)

User 01 pts/1 2013-12-16 19:19 (:0)

Rungta pts/1 2013-12-16 19:19


(:0)

35 | P a g e
2022-23
BCA-2

ASSIGNMENT-18
AIM18:-To save current date & time, number of
files in the current directory and contents of all the
files matching a pattern to a single file NPFL.
Sol:-
Step1: open a vi-editor file-vi NPFL.sh

Step2:write the following code.vi NPFL.sh

Coding:-

date >a1

ls >a2

ls file? >a3

ls file* > a4

ls file [12345] >a5

ls file [1-5] >a6

cat a1 a2 a3 a4 a5 a6 >NPFL

echo “the content of file a1 to a6 is in file

NPFL: “

cat NPFL

wq:!

Step3: change the file permission in executable mode.

Chmod u+x NPFL.sh

Step4: running the shell script program-./NPFL.sh

36 | P a g e
2022-23
BCA-2

Output:-
Rungta@Rungta-h61h2-mv:-$ ./ques-11.sh The contents of file a1 to a6 is in
A2 A3 A4 A5 A6
Abc Addition.sh Add.sh Cmdline.sh Column Day .sh Desktop Dir.sh Divisio

37 | P a g e
2022-23
BCA-2

ASSIGNMENT-19
AIM19:- To display particular message depending
on the weekday.

Sol:-
step1:- open a vi editor file-vi weekday.sh

step:-2 write the following code.vi weekday.sh

coding:-

echo “ Today’s date is $(date +%D)”

echo “ Today’s date is $(date +%A)”

case “ $(date +u% ) “ in

1)

echo “it is my working day”;;

2)

echo “it is my resting day”;;

3)

echo “it is my mid day”;;

4)

echo “it is very expensive time ”;;

5)

echo “it is cool day”;;

6) echo “it is about to weekaned”;;

7)

echo “it is weekend”;;

38 | P a g e
2022-23
BCA-2

esac

echo

wq!

Step:-3 change the file permission ion executable mode.

Chmod u+x vi weekday.sh

Step:-4 runnning the shell script program-./weekday.sh

Output:-
Rungta@Rungta-H61H2-MV:~$ ./weekday.sh Today’s date dateis 12/15/14
Today’s day is Sunday It is weekend
Rungta@Rungta-H61H2-MV:~$

39 | P a g e
2022-23
BCA-2

ASSIGNMENT-20

AIM20:- To display a common message for


following group of days – Monday & Wednesday,
Tuesday & Thursday and Friday & Saturday and
Other day.
Sol:-
Step1:-open a vi-editor file-vi day.sh

Step2:-write the following code. Vi day.sh

Coding:-

echo

echo

tput clear

echo

echo

case “$( date +%u )“ in

3)

echo “ It is my working day”;;

4)

echo “ It is my sports day”;;

6)

echo “ It is my cool day”;;


*)

echo “ It is weekened”;;

40 | P a g e
2022-23
BCA-2

esac

echo

echo

Step3:-change the file permission in executable mode.

Chmod u+x day.sh

Step4:-Running the shell script program -./day.sh

OUTPUT
Rungta@Rungta-H61H2-MV:~$ ./day.sh It is weekened
Rungta@Rungta-H61H2-MV:~$

41 | P a g e
2022-23
BCA-2

ASSIGNMENT-21
AIM21:-Write a shell script to greatest of three numbers.
Sol:-
Step1:- open a vi-editor file –vi greatest.sh

Step2:- write the following code.vi greatest.sh

Coding:-

echo “ enter first number: “

read a

echo “ enter second number: “

read b

echo “ enter third number: “

read c

echo “a = “$a

echo “b = “$b

echo “c = “$c

if [ $a -gt $b ];

then

if [ $a -gt $c ];
then

echo “$a is greatest number :”

fi

else

if [ $b -gt sc ];

then
42 | P a g e
2022-23
BCA-2

echo “ $b is greater number :” fi

fi

wq:!

Step3:- change file permission in executable mode.

Chmod u+ x greatest.sh

Step4:-running the shell script program-./greatest.sh

output:- Rungta@Rungta-h61h2-mv:-$ ./greatest-3 Enter first number :


5
Enter second number : 3
Enter third number :
7
A=5 B=3 C=7
7 is greatest number. Rungta@Rungta-h61h2-mv:-$

43 | P a g e
2022-23
BCA-2

ASSIGNMENT-22
AIM22:-Write a shell script to swap two
numbers using third variable.
Sol:-
Step1:-open a vi-editor file-vi swap.sh

Step2:-write the following code. Vi swap.sh

Coding:-

echo “PROGRAM OF SWAPPING:’

echo”--------------------------------------------“

echo “enter value for a “

read a

echo “ enter value for b :”

read b

echo “ BEFORE SWAPPING:”

echo “ a=$a”

echo “b=$b”

t=$a

a=$b

b=$t

echo “AFTER SWAPPING”

echo “a=$a”

echo “b=$b”

wq:!

Step3:-change the file permission in executable mode.

44 | P a g e
2022-23
BCA-2

Chmod u+x swap.sh

Step4:-Running the shell script program -./swap.sh

Output:- Rungta@Rungta-H61H2-MV:~$./swap.sh PROGRAM OF SWA


- - - - - - - - - - - -- - - - - -- - - - - - -
Enter value for a 10
Enter value for b:
12
BEFORE SWAPPING: a-10
b=12
AFTER SWAPPING: A=12
B=10
Rungta@Rungta-H61H2-MV:~$

45 | P a g e
2022-23
BCA-2

ASSIGNMENT-23

AIM23:- Write a shell script to find the factorial of


a number.
Sol:-
Step:-1 open a vi editor file -vi facto.sh

Step2:- write the following code:-vi facto.sh

Coding:-

echo “ enter any number to get these factorial:”

read n

a=1

if [ $n –eq 0 ];

then

echo “factorial of 0 is1”

fi

for (( i=1;i<=n; i++))

a=$((a*i ) )

echo “factorial of $n is : “ $a

Step:-3 change the file permission ion executable mode.

Chmod u+x vi facto.sh

Step:-4 running the shell script program-./facto.

46 | P a g e
2022-23
BCA-2

OUTPUT

Rungta@Rungta-H61H2-MV:~$ ./facto.sh

Enter any number to get these factorial:

Factorial of 7 is: 5040

47 | P a g e
2022-23
BCA-2

ASSIGNMENT-24

AIM24:- Write a shell script to print prime numbers


between 1 to 20.

Sol:-
Step:-1 open a vi editor file -vi prime.sh

Step2:- write the following code:-vi prime.sh

Coding:-

echo “enter number to check prime:”

read n

for((i=2;i<=n/2;i++))

do

ans=$(( n%i ))

if [ $ans –eq 0 ]

then

echo “$n is not a prime.”

exit 0

fi

done

echo “enter number is pirme“

Wq!

48 | P a g e
2022-23
BCA-2

Step:-3 change the file permission executable mode.

Chmod u+x vi prime.sh

Step:-4 running the shell script program-./prime.sh

Output:-
Rungta@Rungta-H61H2-MV:~$ ./prime.sh Enter number to check prime:
13
Entered number is PRIME Rungta@Rungta-H61H2-MV:~$

49 | P a g e
2022-23
BCA-2

ASSIGNMENT-25

AIM25:-

Write a shell script to sort the contents of a


file XYZ and save it in BCAII.

Sol:-
Step1:-open a vi-editor file-vi XYZ.sh

Step2:-write the following code. Vi XYZ.sh

Coding:-

user@user-desktop:- cat >XYZ

Divya
Vedika
Ritesh
Komal
Rashmi
Abhilash

Step3:-change the file permission in executable mode.

Chmod u+x XYZ.sh

Step4:- create file BCAII.sh in vi editor

Step5:-write a command ‘cat xyz.sh BCAII<bca2’

Step6:-Running the shell script program -./XYZ.sh

50 | P a g e
2022-23
BCA-2

OUTPUT

user@user-desktop:- sort XYZ


Abhilas
h Divya
Komal
Rashmi
Ritesh
Vedika
user@user-desktop:- cat >BCAII
user@user-desktop:- $wc XYZ|

51 | P a g e
2022-23
BCA-2

ASSIGNMENT-26
AIM26:-

Write a shell script to display mathematical table


of any number in the format x :-3*1=3.
Sol-
Step1:-open a vi-editor file-vi table.sh

Step2:-write the following code. Vi table.sh

Coding:-

tput clear

echo “ entre a number for table:”

tead n

let ans=1;

tput clear

echo ” table of “$n” is:”

for (( i=1; i<=10; i++ ))

do

let ans=i*n

echo $n “*” $i “=” $ans

done

w q

Step3:-change the file permission in executable mode.

Chmod u+x table.sh

52 | P a g e
2022-23
BCA-2

Step4:-Running the shell script program -./table.sh

53 | P a g e
2022-23
BCA-2

OUTPUT
Rungta@Rungta-H61H2-MV:~$ ./table.sh Enter a number for table:
3

enter a number for a table: 3


Table of 3 is : 3 * 1 = 3
3*2=6
3*3=9
3 * 4 = 12
3 * 5 = 15
3 * 6 = 18
3 * 7 = 21
3 * 8 = 24
3 * 9 = 27
3 * 10 = 30
Rungta@Rungta-h6hz-mv:~$

54 | P a g e

You might also like