Linux Practical Edited
Linux Practical Edited
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.
2. You can choose which screensaver you desire from the Screensaver
theme list on the left-hand side of the screen..
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..
2|Page
2022-23
BCA-2
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
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.
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
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.
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.
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.
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.
The package screen will wish to install select executing (at the end of
component list) install all packages included RED HAT Enterprise Linux.
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 change password:
$ 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
Code:
groupadd BCA
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.
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
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".
:%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.
:/a
:/apple
:21,40: sort
14 | P a g e
2022-23
BCA-2
ASSIGNMENT-7
Sol:-
a
) To copy one line use
yy command
Ex- 6yy
dd command
Ex- 6dd
p command
b)
To copy or yank a word use
yw command
Ex- 7yw
c)
To delete line use
dw command
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
ls -l *.c
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:
Relative Permission
For ex:-
chmod u + x <filename>
chmod go –r <filename>
To remove execute permission from all (a –x) and assign read permission to
group and others (go +r).
u user
g group
o others
a all
r read permission
w write permissio
x execute permission
+ assign permission
- remove permission
= assign absolute permission
18 | P a g e
2022-23
BCA-2
Sol:-
19 | P a g e
2022-23
BCA-2
ASSIGNMENT-10
Coding-
echo “currently logged in detail with column header”
who-H
wq!
Output:-
Rungta@Rungta:~$ ./column header
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
Coding:-
tput clear
echo
echo
ls> abc
cat abc
sort abc
cat abc
wq!
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
Sol:-
Step:-1 open a vi editor file -vi sort.sh
Coding:-
tput clear
echo
cat abc
cat oabc
wq!
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
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
Coding:-
read num
if [ $num –lt 0 ];
then
else
zero.” Fi
wq:!
27 | P a g e
2022-23
BCA-2
28 | P a g e
2022-23
BCA-2
ASSIGNMENT-14
Coding:-
for f in ‘ls’
do
if [ -d $f ];
then
echo $f
done
fi
wq:!
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
Sol:-
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:!
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
Coding:-
tput clear
echo $a
echo $b
do
let c=a+b
echo $c
let a=b
let b=c
done
wq:!
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
Coding:-
time + t2
echo $ time
wq:!
Output:-
Rungta@Rungta-h61h2-mv:-$ ./log
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
Coding:-
date >a1
ls >a2
ls file? >a3
ls file* > a4
cat a1 a2 a3 a4 a5 a6 >NPFL
NPFL: “
cat NPFL
wq:!
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
coding:-
1)
2)
3)
4)
5)
7)
38 | P a g e
2022-23
BCA-2
esac
echo
wq!
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
Coding:-
echo
echo
tput clear
echo
echo
3)
4)
6)
echo “ It is weekened”;;
40 | P a g e
2022-23
BCA-2
esac
echo
echo
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
Coding:-
read a
read b
read c
echo “a = “$a
echo “b = “$b
echo “c = “$c
if [ $a -gt $b ];
then
if [ $a -gt $c ];
then
fi
else
if [ $b -gt sc ];
then
42 | P a g e
2022-23
BCA-2
fi
wq:!
Chmod u+ x greatest.sh
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
Coding:-
echo”--------------------------------------------“
read a
read b
echo “ a=$a”
echo “b=$b”
t=$a
a=$b
b=$t
echo “a=$a”
echo “b=$b”
wq:!
44 | P a g e
2022-23
BCA-2
45 | P a g e
2022-23
BCA-2
ASSIGNMENT-23
Coding:-
read n
a=1
if [ $n –eq 0 ];
then
fi
a=$((a*i ) )
echo “factorial of $n is : “ $a
46 | P a g e
2022-23
BCA-2
OUTPUT
Rungta@Rungta-H61H2-MV:~$ ./facto.sh
47 | P a g e
2022-23
BCA-2
ASSIGNMENT-24
Sol:-
Step:-1 open a vi editor file -vi prime.sh
Coding:-
read n
for((i=2;i<=n/2;i++))
do
ans=$(( n%i ))
if [ $ans –eq 0 ]
then
exit 0
fi
done
Wq!
48 | P a g e
2022-23
BCA-2
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:-
Sol:-
Step1:-open a vi-editor file-vi XYZ.sh
Coding:-
Divya
Vedika
Ritesh
Komal
Rashmi
Abhilash
50 | P a g e
2022-23
BCA-2
OUTPUT
51 | P a g e
2022-23
BCA-2
ASSIGNMENT-26
AIM26:-
Coding:-
tput clear
tead n
let ans=1;
tput clear
do
let ans=i*n
done
w q
52 | P a g e
2022-23
BCA-2
53 | P a g e
2022-23
BCA-2
OUTPUT
Rungta@Rungta-H61H2-MV:~$ ./table.sh Enter a number for table:
3
54 | P a g e