You are on page 1of 17

LAB ASSESSMENT: -1

Name: SHALNI PANDEY Course Code:CSE2005


Registration No: 19BCE2631 Slot: L23-24

1.Create a Virtual Machine (VM) 


 Firstly, We have to go to virtualbox.org to download the latest installer
for windows hosts. As I have downloaded latest version of Virtualbox6.0
to run VMs with software virtualization.
 Running the installer and following the prompts to complete the
installation by clicking the NEXT button on the three screens.
 At the fourth screen of the installation wizard, you will get a warning
that your network connection will be reset and that shall temporarily be
disconnected from the network. Ensure we are not in the middle of a
large download that cannot be resumed, and click the YES button.
 On the next screen, click on the INSTALL button. If we get the prompt to
allow the installer make changes to your device, select YES.
 When the installation wizard is done, uncheck the “Start Oracle
VM  VirtualBox 6.0.10 after installation” checkbox, and then click on
the FINISH button.

For Creating Ubuntu Virtual Box:


 If we do not have the ISO file for Ubuntu, go to
www.ubuntu.com/download/desktop and download the latest LTS
release (Ubuntu 20.04 LTS). Note that it may take a while because it is
about 1.9GB.
 From our Start menu or using the Oracle VM VirtualBox icon on your
desktop, launch VirtualBox. Then click on New.
 On the “Create Virtual Machine” dialog box, choose a Name for the
virtual machine e.g. Ubuntu OS. VitualBox will try to predict the Type
and Version based on the name you entered. Otherwise, select the
following: Type = Linux and Version = Ubuntu (64-bit)
 Next, you need to specify the amount of RAM memory to allocate to the
virtual machine. Accept the default value and click Next.
 On the Hard disk screen, select Create a virtual hard disk now and click
Create.
 On the Hard disk file type screen, accept the default option VDI
(VirtualBox Disk Image) and click Next.
 The next screen is for Storage on physical hard disk. The two options are
well expalined but we shall go for the default, which is, Dynamically
allocated so that VirtualBox will allocate space for the hard disk as it
contains more and more files; this storage space is only limited by the
hard disk size we shall specify in the next step. Click Next.
 For the File location and storage screen, enter a name (say, Ubuntu OS)
and a size (10GB) for the hard disk. Click Create.
 Next, we need to specify the amount of RAM memory to allocate to the
virtual machine. Accept the default value and click Next.
 On the Hard disk screen, select Create a virtual hard disk now and click
Create.
 On the Hard disk file type screen, accept the default option VDI
(VirtualBox Disk Image) and click Next.
 The next screen is for Storage on physical hard disk. The two options are
well expalined but we shall go for the default, which is, Dynamically
allocated so that VirtualBox will allocate space for the hard disk as it
contains more and more files; this storage space is only limited by the
hard disk size we shall specify in the next step. Click Next.
 For the File location and storage screen, enter a name (say, Ubuntu OS)
and a size (10GB) for the hard disk. Click Create.
Configure Settings for the Virtual Machine
 Back to the main VirtualBox window, we shall now configure the settings
for the virtual machine we have just created.
 On the left side of the window, select the virtual machine (i.e. Ubuntu
OS) then click on the Settings button.
 On the left pane of the Settings dialog, select General then click on the
Advanced tab then choose Bidirectional for both the Shared Clipboard
dropdown and the Drag ‘n’ Drop dropdown.
 Next, on the left pane of the Settings dialog, select Storage, then in the
right pane under Controller: IDE select the CD icon with the word Empty
beside it.
 Then still on the right pane, to the extreme right under Attributes, click
the CD icon and from the menu that appears, select Choose Virtual
Optical Disk File…
 Browse to the downloaded file ubuntu-20.04-desktop-amd64.iso, select
it, and click Open.
 Click OK to close the Settings dialog window. The virtual machine is now
ready to start.

Install Ubuntu on the Virtual Machine


 Back to the main VirtualBox window, the VM for Ubuntu OS should be
showing as Powered Off, and the optical drive (IDE Secondary Master)
pointing to the Ubuntu ISO file.
 With the Ubuntu OS virtual machine selected, click Start.
 VirtualBox launches a new window with the VM and boots from the ISO
file. After the few minutes it takes Ubuntu to load, you should see the
screen below. Click Install Ubuntu.
 Select your keyboard layout (or accept the defaults) and click Continue.
 Use the default options Normal installation then with the Download
updates while installing Ubuntu checkbox checked, click Continue.
 Accept the default option Erase disk and install Ubuntu, then click Install
Now
 We will be prompted with a warning that the changes will be written to
disk. Click Continue.
 Select your timezone (e.g.Calcuta) and click Continue.
 Enter a your name, computer name, username and password, then click
Continue.
 The Ubuntu installation will take several minutes to complete, so you
will have to wait a bit.
 After the installation is finished you will be prompted to restart the VM.
Click Restart Now.

Practice of Basic Unix commands


1. ls: Lists all files and directories in the present working directory

2. ls –R:Lists files in sub-directories as well

3. ls –a :Lists hidden files as well

4. ls –al:Lists files and directories with detailed information like


permissions, size, owner, etc.
5. cat >filename:Creates a new file

6. cat filename :Displays the file content

7. cat file1 file2 > file3:Joins two files (file1, file2) and stores the output in a
new file (file3)

8. sort <filename>: sorts the contex of the file line-by line

9. head<filename>: show first few lines of a file(s)

10.tail <filename>: show last fewlines of a file; or reverse line order


11.more <filename>: views the text file

12.rm: removes the file

13.man:Gives help information on a command

14.mkdirdirectoryname:Creates a new directory in the present working


directory or a at the specified path

15.rmdir: Deletes a directory

16.Date : shows date and time

17.Cal 2016: shows calender of a particular year


18.vi <file name>: full-featured screen editor for modifying text
19.echo<text> : echo arguments to the standard output

20.who-option’’s: displays the user that are currently kogged into your
unix computer system.

21.uptime <filename> show one line summary of system status

22.process command: provides the information about the currently


running processes, including their process identification numbers
(PIDS)
23.date -d+L : if L is specified, the timing summary is printed in a portabe
POSIX

24.uname command: print system information.

SHELL PROGRAMMING -1
1) Write Script to see current date, time, username, and current directory.

2) How to write shell script that will add two numbers, which are supplied as
command line argument, and if this two numbers are not given show error and
its usage.

if [ $# -ne 2 ]
then
echo "Usage - $0 x y"
echo " Where x and y are two nos for which I will print sum"
exit 1
fi
echo "Sum of $1 and $2 is `expr $1 + $2`"

3)Write Script to find out biggest number from given three nos. Numbers are
supplied as command line argument. Print error if sufficient arguments are not
supplied.

CODE:read a b c

if [[ $a == 0 || $b == 0 || $c == 0 ]]; then
echo "command line arguments are missing"
elif [[ $a == $b && $b == $c ]]; then
echo "All the three numbers are equal"
elif [[ $a == $b && $b > $c || $b == $c && $c > $a || $a == $c && $a > $b ]]; then
echo "I cannot figure out which number is biggest"
else
if [[ $a > $b && $a > $c ]]; then
echo "$a is Biggest number"
elif [[ $b > $a && $b > $c ]]; then
echo "$b is Biggest number"
else
echo "$c is Biggest number"
fi
fi
4. Write script to print the following numbers as 5,4,3,2,1 using while loop.

i=5
while test $i != 0
do
echo "$i
"
i=`expr $i - 1`
done

5.Write Script, using case statement to perform basic math operation as


follows: + addition, - subtraction, x multiplication, / division
clear

echo -----------------------------------------------------

echo '\tEvaluation of Arithmetic expression'

echo -----------------------------------------------------

echo Enter the a value

read a

echo Enter the b value

read b

echo 1.Addition

echo 2.Subtraction

echo 3.Multiplication

echo 4.Division

echo 5.Modules
echo Enter your choice

read choice

case $choice in

1)echo Addition : $(expr $a + $b);;

2)echo Suubtraction : $(expr $a - $b);;

3)echo Multiplication : $(expr $a \* $b);;

4)echo Division : $(expr $a / $b);;

5)echo Modules : $(expr $a % $b);;

*)echo This is not a choice

esac

6. Write script to print given number in reverse order, for eg. If no is 123 it
must print as 321

CODE:
echo "enter the number "
read num
while [ $num != 0 ]
do
d=$(($num % 10 ))
num=$(($num/ 10 ))
rev=$( echo ${rev}${d} )
done
echo $rev is in reverse

7. Write script to print given numbers sum of all digit, For eg. If no is 123 it's
sum of all digit will be 1+2+3 = 6.
CODE:

echo "Enter a number"


read num
sum=0
while [ $num -gt0 ]
do
mod=`expr $num % 10` #It will split each digits
sum=`expr $sum + $mod` #Add each digit to sum
num=`expr $num / 10` #divide num by 10.
Done
echo $sum :Sum

8. Write script to determine whether given file exist or not, file name is supplied as
command line argument, also check for sufficient number of command line argument.
if [ $# -ne 1 ]
then
echo "Usage - $0 file-name"
exit 1
fi
if [ -f $1 ]
then
echo "$1 file exist"
else
echo "Sorry, $1 file does not exist"
fi

9. Write a shell script takes the name a path (eg:


/afs/andrew/course/15/123/handin), and counts all the sub directories
(recursively).
CODE:
#! /bin/sh
ls –R $1 | wc –l
10.Write a shell script that takes a name of a folder as a command line
argument, and produce a file that contains the names of all sub folders with
size 0 (that is empty sub folders) .

CODE:
ls $1 |
while read folder
do
if [ -d $1/$folder ]
then
files=`ls $1/$folder | wc –l`
if [ $files –eq0 ]
then
echo $folder >> output.txt
fi
fi
done

11.Write a shell script that takes a name of a folder, and delete all sub folders
of size 0.
ls $1 |
while read folder
do
files=`ls $folder | wc –l`
if [ files –eq 0 ]
then
rmdir $folder
fi
done
12. write a shell script that will take an input file and remove identical lines (or
duplicate lines from the file)

You might also like