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

OS Lab Manual Final

Lab manual for operating system

Uploaded by

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

OS Lab Manual Final

Lab manual for operating system

Uploaded by

Muluneh Debebe
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Operating System Laboratory Manual

Laboratory 1:
Basics of Operating Systems

Identify the following basics of computer system

 Operating system installed on your computer

 OS edition and architecture 32 or 64 bit

 Speed of the processor

 Size of memory

 Size of hard disk

 Examples of operating system (Windows 7, Ubuntu…

Different editions of windows 7

1. Windows 7 Starter

This is the bare-bones, 32-bit only version of Windows 7 intended for users in developing
countries, to serve the most basic computing needs.

Starter is designed for lightweight, portable netbooks, though Microsoft claims any of its
versions will be able to run on netbooks.

2. Windows 7 Home Basic

Home Basic sits somewhere between Starter and Home Premium. It has all the features of
Windows 7 Starter and will also only be available through OEM partners in developing
countries.

3. Windows 7 Home Premium

Windows 7 Home Premium has all the features of Starter and Home Basic and then some.
This is the mainstream retail version that nearly all consumers will be using. Windows 7
Home Premium will be available worldwide to Microsoft OEMs and sold in retail stores
loaded on new PCs.

4. Windows 7 Professional

Also available worldwide, to OEMs and in retail, Windows 7 Professional has the features of
Home Premium, but with added networking and data protection features for small businesses
and those who frequently work at home.

5. Windows 7 Enterprise

Windows 7 Enterprise is only available to businesses through volume licensing. It includes


all the features of Windows 7 Professional plus more security and networking features.

1
Operating System Laboratory Manual

Windows 7 Enterprise is designed for the corporate world and will only be used by
large businesses.
6. Windows 7 Ultimate

Ultimate, the supersize version of Windows, includes all the features of all the other versions.
Think of it as Windows 7 Enterprise for consumers. Ultimate will be the most expensive
version, so it's doubtful that many people will use it other than the occasional super-user who
wants every possible feature. Microsoft is not likely to heavily promote Windows 7 Ultimate.
Most regular users do not need all the security and networking features and there doesn't
appear to be much in Ultimate for businesses that isn't already in Windows 7 Enterprise.

Basic summery of windows editions

2
Operating System Laboratory Manual

3
Operating System Laboratory Manual

For more comparison information please refer http://winsupersite.com/windows-7/windows-


7-product-editions-comparison

4
Operating System Laboratory Manual

Laboratory 2:
Operating Systems Installation

Linux Windows Dual Boot and More: Multi-booting Up to Five OS


A. Creating a Bootable Removable Media for Linux Windows Dual Boot

- to make bootable perform the following using command prompt


diskpart yes
list disk
select disk 1
clean
create partition primary
format fs=ntfs quick
assign
active

2. using sotfwares
Eg. Universal USB installer
B. Changing Boot Menu Settings for Linux Windows Dual Boot
- Interrupt the normal boot by pressing the appropriate key.

DELL – F2 or F12
VAIO – Assist Button
ACER – F2
LENOVO – F12
SAMSUNG – F12
HP – F9 Esc
- I recommend you to change the boot option to legacy from UEFI.
C. Installing the new OS
Windows
Ubuntu

5
Operating System Laboratory Manual

How to Install Windows 7


Part 1 Installing Using a Windows installation DVD .

1. Enter your computer's BIOS. Turn off the computer that you want to install
Windows on then turn it back on. When the BIOS screen appears or you are
prompted to do so, press Del, Esc, F2, F10, or F9 (depending on your computer’s
motherboard) to enter the system BIOS. The key to enter the BIOS is usually
shown on the screen.

2. Find your BIOS's boot options menu. The boot options menu of your BIOS may
vary in location or name from the illustration, but you may eventually find it if you
search around.
a.i. If you can't find the boot options menu, search the name of your BIOS
(most likely located in the BIOS menu) online for help.

3. Select the CD-ROM drive as the first boot device of your computer.

a.i. Although this method may vary among computers, the boot options
menu is typically a menu of movable device names where you should

6
Operating System Laboratory Manual

set your CD-ROM drive as the first boot device. It can also be a list of
devices that you can set the order of their boot on. Consult a manual or
the internet for help if you're stuck.

4. Save the changes of the settings. Press the button indicated on the screen or select
the save option from the BIOS menu to save your configuration.

5. Shut off your computer. Either turn off the computer by choosing the shut-down
option in your current operating system, or hold the power button until the computer
powers off.

6. Power on the PC and the insert the Windows 7 disc into your CD/DVD drive.

7. Start your computer from the disc. After you have placed the disc into the disc
drive, start your computer. When the computer starts, press a key if you are asked if you
would like to boot from the disc by pressing any key. After you choose to start from the disc,
Windows Setup will begin loading.
a.i. If you are not asked to boot from the disc, you may have done
something wrong. Retry the previous steps to solve the problem.

8. Choose your Windows Setup options. Once Windows Setup loads, you'll be
presented with a window. Select your preferred language, keyboard type, and time/currency
format, then click Next.

9. Click the Install Now button.

10. Accept the License Terms. Read over the Microsoft Software License Terms, check I
accept the license terms, and click Next.

11. Select the Custom installation.

12. Decide on which hard drive and partition you want to install Windows on. A hard
drive is a physical part of your computer that stores data, and partitions "divide" hard drives
into separate parts.
a.i. If the hard drive has data on it, delete the data off of it, or format it.
Select the hard drive from the list of hard drives.
Click Drive options (advanced).
Click Format from Drive options.
a.ii. If your computer doesn't have any partitions yet, create one to install
Windows on it.
Select the hard drive from the list of hard drives.
Click Drive options (advanced).

7
Operating System Laboratory Manual

Select New from Drive options.


Select the size, and click OK.

1.
13. Install Windows on your preferred hard drive and partition. Once you've decided
on where to install Windows, select it and click Next. Windows will begin installing.

Upgrade
An Upgrade installation upgrades an older version of Windows on your computer
(E.G. Windows Vista to Windows 7.)

1. Start your computer normally into your current operating system.

2. Check to see if your computer is compatible with Windows 7. The Windows 7


Upgrade Advisor scans your computer to see if you can upgrade it to Windows 7.
Download Windows 7 here.

3. Prepare your computer to install Windows.

.1. Scan your computer for malware. Malware can prevent Windows from
installing correctly.
.2. Disable or uninstall any antivirus software because they may interfere
with the Windows installation.
.3. Uninstall some unnecessary programs to speed up the upgrade. You
can install them after Windows 7 has finished.
.4. Update Windows with Windows Update.
.5. Delete some unnecessary files to speed up the upgrade.
.6. Back up your hard drive in case the installation fails and you lose your
files. (optional).

2. Insert your Windows 7 installation disc into the computer at this point.

3. Start Windows Setup. After the disc has loaded, click Start →Computer, double
click the disc drive that Windows 7 Setup was placed in, and double-
click setup.exe on the disc. Allow Setup to start.

8
Operating System Laboratory Manual

4. Click Install Now.

5. Decide whether to install updates for Windows Setup. The updates are intended to
fix known problems with Windows Setup and installing updates makes your
installation smoother and more stable. To get updates, click Go Online to get the latest
updates for installation (recommended). To skip updates, click Do not get the latest
updates for installation.

6. Accept the License Terms. Read over the Microsoft Software License Terms,
check I accept the license terms, and click Next.

7. Select the Upgrade installation.

Part 2 Installing Using a Flash Drive or External Drive .

Installing Windows Setup to the Flash Drive or External Drive


You will need to extract the Windows Setup files to a drive before continuing any farther.

1. Plug a drive with a minimum of 4 gigabytes of memory into a computer.

2. Move any personal files off of the drive.

3. Download the Windows 7 Setup ISO. An ISO file is a disc image. Note: This
download may take a while, depending on your internet speed.

.1. A list of download links is available here.


.2. If the link to the website does not work, click here to download a list of
the links.

4. Download and install the Windows 7 USB/DVD Download Tool from this link.

5. Once the ISO has finished downloading, open the Windows 7 USB/DVD
Download Tool.

9
Operating System Laboratory Manual

6. Select the ISO. On the Step 1 of 4: Choose ISO file screen of the Windows 7
USB/DVD Download Tool, select the downloaded ISO file by clicking Browse,
then click Next to continue.

7. On the Step 2 of 4: Choose media type screen, choose USB device.

8. On the Step 3 of 4: Insert USB device screen, choose the drive you want to
extract the Setup files to, then click Begin copying.

.1. If you receive an error that says Not Enough Free Space, click
the Erase USB Device button, which will erase all of the files on the
drive.

9. Once Windows 7 USB/DVD Download Tool has finished extracting the ISO to the
flash drive, your drive is ready to install Windows.

 You may delete the ISO file now, as it is no longer required.


Clean Installation
A clean install is intended for users who want to freshly install Windows on their computer
(by deleting all of the data on the hard disk and then installing Windows) or computers that
do not have an operating system yet. (Note: Older computers may not be able to perform a
clean installation with the drive.)

1. Make sure the drive that Windows 7 Setup was extracted onto is plugged into the
computer.

2. Enter your computer's BIOS. Turn off the computer that you want to install
Windows on then turn it back on. When the BIOS screen appears or you are
prompted to do so, press Del, Esc, F2, F10, or F9 (depending on your computer’s
motherboard) to enter the system BIOS. The key to enter the BIOS is usually
shown on the screen.

10
Operating System Laboratory Manual

3. Find your BIOS's boot options menu. The boot options menu of your BIOS may
vary in location or name from the illustration, but you may eventually find it if
you search around.

o If you can't find the boot options menu, search the name of your BIOS (most
likely located in the BIOS menu) online for help.

4. Select the drive as the first boot device of your computer.

o If your drive doesn't show up as a boot device, then your computer doesn't
support it.
o Although this method may vary among computers, the boot options menu is
typically a menu of movable device names where you should set your drive as
the first boot device. It can also be a list of devices that you can set the order of
their boot on individually. Consult a manual or the internet for help if you're
stuck.

5. Save the changes of the settings. Press the button indicated on the screen or select
the save option from the BIOS menu to save your configuration.

6. Shut off your computer. Either turn off the computer by choosing the shut-down
option in your current operating system, or hold the power button until the
computer powers off.

7. Turn your computer back on. Your computer should enter Windows Setup.

o If your computer asks you if you want to boot from a CD by pressing any key,
boot from it. Windows Setup will load.
o Important Information: If you receive a CD/DVD device driver missing error
during Setup at any point, simply click Cancel on the error message which
will return you to the Welcome screen. Once you reach the Welcome screen,
un-plug the USB drive and plug in into another USB port on your computer,
then continue with the installation.

11
Operating System Laboratory Manual

8. Choose your Windows Setup options. Once Windows Setup loads, you'll be
presented with a window. Select your preferred language, keyboard type, and
time/currency format, then click Next.

9. Click the Install Now button.

10. Accept the License Terms. Read over the Microsoft Software License Terms,
check I accept the license terms, and click Next.

11. Select the Custom installation.

12. Decide on which hard drive and partition you want to install Windows on. A
hard drive is a physical part of your computer that stores data, and partitions
"divide" hard drives into separate parts.

o If the hard drive has data on it, delete the data off of it, or format it.
 Select the hard drive from the list of hard drives.
 Click Drive options (advanced).
 Click Format from Drive options.
o If your computer doesn't have any partitions yet, create one to install Windows
on it.
 Select the hard drive from the list of hard drives.
 Click Drive options (advanced).
 Select New from Drive options.
 Select the size, and click OK.

13. Install Windows on your preferred hard drive and partition. Once you've
decided on where to install Windows, select it and click Next. Windows will begin
installing.

12
Operating System Laboratory Manual

Upgrade
An Upgrade installation upgrades an older version of Windows on your computer (E.G.
Windows Vista) to Windows 7.

1. Check to see if your computer is compatible with Windows 7. The Windows 7


Upgrade Advisor scans your computer to see if you can upgrade it to Windows 7.
Download it here.

2. Prepare your computer to install Windows.

o Scan your computer for malware. Malware can prevent Windows from
installing correctly.
o Disable or uninstall any antivirus software because they may interfere with the
Windows installation.
o Uninstall some unnecessary programs to speed up the upgrade. You can install
them after Windows 7 has finished.
o Update Windows with Windows Update.
o Delete some unnecessary files to speed up the upgrade.
o Back up your hard drive in case the installation fails and you lose your files.
(optional).

3. Make sure the drive that Windows Setup was extracted onto is plugged into your
computer.

4. Start Windows Setup. Click Start →Computer, double click the USB drive that
Windows 7 Setup was extracted to, and double-click setup.exe on the disc. Allow
Setup to start.

5. Click Install Now.

6. Decide whether to install updates for Windows Setup. The updates are intended to
fix known problems with Windows Setup and installing updates makes your
installation smoother and more stable. To get updates, click Go Online to get the

13
Operating System Laboratory Manual

latest updates for installation (recommended). To skip updates, click Do not get the
latest updates for installation.

7. Accept the License Terms. Read over the Microsoft Software License Terms,
check I accept the license terms, and click Next.

8. Select the Upgrade installation.

Part 3 Post-Installation .

These steps carry off after you have finished installing Windows and your computer has
started in Windows 7.

1. Type your username and computer's name and click Next.

2. Type your password and click Next. If you don't want a password, leave the text
boxes blank and then click Next.

3. Enter your product key then click Next. Your product key is located on the case
of your Windows 7 disc if you purchased the disc. To skip entering your product
key, just click Next, but Windows will run on a 30-day trial, and you'll have to
enter a key once the 30 day trial time is up.

4. Choose your Windows Update settings.

o Use recommended settings automatically sets update and security settings


recommended by Microsoft.
o Install important updates only configures your computer only to install necessary
updates.
o Ask me later disables your security until you have made a decision.

14
Operating System Laboratory Manual

5. Set your time and time zone.

6. Set your network type.

.1.If the computer is connected to your own personal network, choose Home network.
.2.If you are connected to the network at your workplace, choose Work network.
.3.If you're connected to a public network from places such as restaurants and shops,
choose Public network.

7. Your computer is now set up!

8. Once your computer is ready, format your USB drive back to its default settings
(if you chose the Installing Using a Flash Drive or External Drive method). You
can format your USB drive back to its default settings and place your files back
onto it by right clicking your USB drive in Start→Computer, clicking Format,
clicking Restore Device Defaults in Format, then clicking Start, which
permanently deletes any data off of the drive. After the drive has formatted, you
can move your files back onto it.

9. Be sure to reinstall any software you uninstalled, install any device drivers, and
re-enable your security software. Also, to improve your security, run Windows
Update to install the latest security updates.

How to Install Ubuntu Linux


Ubuntu is one of the most popular forms of the Linux operating
system. It is available for free, and will run on almost any computer.
This guide will show you how to install Ubuntu by booting from a CD
or within Windows itself.
.1. CD/DVD Installation

15
Operating System Laboratory Manual

1. Download the Ubuntu ISO file. You can get the ISO file from the Ubuntu website.
An ISO file is a CD image file that will need to be burned before you can use it. There
are two options available from the Ubuntu website (you can also buy official Ubuntu
CDs, which come in packs of 10):

o 16.04 LTS has continuous updates and provides technical


support. It is scheduled to be supported until April 2021.
This option will give you the most compatibility with your
existing hardware.

o Ubuntu builds (not yet released) 16.10, 17.04, and 17.10 will
come with limited support. They will have the newest
features, though they may not work with all hardware.
These releases are geared more towards experienced Linux
users.

o If you have a Windows 8 PC or a PC with UEFI firmware,


download the 64-bit version of Ubuntu. Most older machines
should download the 32-bit version.

2. Burn the ISO file. Open up your burning program of choice. There are free and
paid programs available that can burn an ISO to a CD or DVD.

o Windows 7, 8, and Mac OS X can all burn ISO files to a


disc without having to download a separate program.

3. Boot from the disc. Once you have finished burning the disc, restart your
computer and choose to boot from the disc. You may have to change your boot

16
Operating System Laboratory Manual

preferences by hitting the Setup key while your computer is restarting. This is
typically F12, F2, or Del.

4. Try Ubuntu before installing. Once you boot from the disc, you
will be given the option to try Ubuntu without installing it. The
operating system will run from the disc, and you will have a
chance to explore the layout of the operating system.

o Open the Examples folder to see how Ubuntu handles files and
exploring the operating system.

o Once you are done exploring, open the Install file on the
desktop.

5. Install Ubuntu. Your computer will need at least 4.5 GB of free


space. You will want more than this if you want to install
programs and create files. If you are installing on a laptop,
make sure that it is connected to a power source, as installing
can drain the battery faster than normal.

o Check the “Download updates automatically” box, as well as


the “Install this third-party software” box. The third-party software
will allow you to play MP3 files as well as watch Flash video (such
as YouTube).

6. Set up the wireless connection. If your computer is not


connected to the internet via Ethernet, you can configure your
wireless connection in the next step.

o If you didn’t have an internet connection in the previous step,


hit the Back button after setting up the wireless connection so that
you can enable automatic updates.

17
Operating System Laboratory Manual

7. Choose what to do with your existing operating system. If you


have Windows installed on your system, you will be given a
couple options on how you’d like to install Ubuntu. You can
either install it alongside your previous Windows installation,
or you can replace your Windows installation with Ubuntu.

o If you install it alongside your old version of Windows, you will


be given the option to choose your operating system each time you
reboot your computer. Your Windows files and programs will remain
untouched.

o If you replace your installation of Windows with Ubuntu all of


your Windows files, documents, and programs will be deleted.

8. Set your partition size. If you are installing Ubuntu alongside


Windows, you can use the slider to adjust how much space you
would like to designate for Ubuntu. Remember that Ubuntu will
take up about 4.5 GB when it is installed, so be sure to leave
some extra space for programs and files.

o Once you are satisfied with your settings, click Install Now.

9. Choose your location. If you are connected to the internet,


this should be done automatically. Verify that the timezone
displayed is correct, and then click the Continue button.

10. Set your keyboard layout. You can choose from a list of
options, or click the Detect Keyboard Layout button to have
Ubuntu automatically pick the correct option.

18
Operating System Laboratory Manual

11. Enter your login information. Enter your name, the name of the
computer (which will be displayed on the network), choose a
username, and come up with a password. You can choose to
have Ubuntu automatically log you in, or require your
username and password when it starts.

12. Wait for the installation process to complete. Once you


choose your login info, the installation will begin. During setup,
various tips for using Ubuntu will be displayed on the screen.
Once it is finished, you will be prompted to restart the
computer and Ubuntu will load.

2. Using Installer

1. Download the installer from the Ubuntu website. If your


browser prompts you, select Run, Save, or Open. The Windows
installer is not compatible with Windows 8. You must use the
method in the previous section.

o The Windows installer will install Ubuntu alongside Windows.


Your files and programs will not be affected. When you reboot your
computer, you will be able to choose which operating system you
would like to load.

2. Choose your username and password. Once you run the


installer, you will be presented with the configuration menu.
Choose your new Ubuntu username and password.

o You can also change the size of the Ubuntu installation. A


larger installation will give your Linux operating system more space
to install programs and add files, but this will take away from the
free space that Windows has access to.

19
Operating System Laboratory Manual

o You can choose your Desktop environment. The three most


common are:
 Ubuntu (the most popular) has Unity, a unique and intuitive
desktop environment.
 Kubuntu has KDE which resembles Windows
 Xubuntu uses Xface, which is faster and good for PCs that are
2-3 years old.
 Lubuntu uses LXDE, and can be used with very old PCs or
netbooks with as little as 512MB of RAM.

3. Click Install to start. The installer will begin downloading the


files necessary to install Ubuntu on your computer. Installation
will happen automatically.

o Downloading the files can take a significant amount of time


depending on your internet connection. You can use your computer
while the files download in the background.

4. Restart your computer. Once the installation is complete, you


will be given the option to reboot now or later. When you
reboot, you will see a new menu before Windows starts that
allows you to choose between Windows and Ubuntu.

Laboratory 3:
Introduction to UNIX terminal

Objective:
This Lab is an introduction and review of the UNIX operating system. We are going to use
the operating system for the rest of the course so it is advisable that you follow the steps and
carry out the examples and exercises. The followings are the primary objectives of this lab
session:
 Understanding UNIX File System.
 Be able to execute commands using the UNIX shell.
 Create and manipulate directories.
 Create, edit and manipulate files.
 Be familiar with command line text editors provided by UNIX.

20
Operating System Laboratory Manual

 Be able to use the UNIX reference manual to understand more about


commands and getting help.

Introduction:
In Unix, all file systems (Hard Disks, CD-ROMs, Floppy Disks, ZIP drives, network
mounts, etc …) are “mounted” onto one logical tree. The top of the hierarchy is
traditionally called root which is represented by a / (slash).

Absolute and Relative Names


You can specify a file or directory by its path name. There are two ways of expressing the path
name: Full (absolute) path name or relative path name. The full path name starts with the
root. /, and follows the branches of the file system, each separated by /, until you reach the
desired file. However, a relative path name specifies the path relative to your current working
directory. Relative path name are more convenient because they are shorter, but must be used
with care. They never begin with / (slash). Now, we have to introduce two special directory
entries:
. The current directory
.. The parent directory

Examples: Use the above diagram and assume that your current working directory
(your current position in the file system) is ugics:
1. A file named “test.txt” is placed inside the directory “st111111”.
The absolute (full) path is: /home/ugis/st111111/test.txt
The relative path is: st111111/test.txt OR ./st111111/test.txt
2. A file named “csh” is placed inside the directory “bin”.
The absolute (full) path is: /bin/csh
The relative path is: ../../bin/csh
3. A directory named “st123456” is placed inside the directory “ugics”.
The absolute (full) path is: /home/ugics/st123456
The relative path is: st123456 OR ./st123456

Working with UNIX Shell


When you first login to any UNIX machine, your current working directory is your HOME
directory. Your home directory has the same name as your username (i.e. Ubuntu). (in the
above case ugics is a home directory)
eg - bdu@BDU-PC:~$ ~ symbol stands for the current working directory is a
home directory, i.e bdu.

Procedures: Open the shell (terminal) and follow the following procedures
To open the terminal use the following options and appears as shown in the above

ctrl + alt + T
or on the dash home type ‘terminal'
or go to Applications – Accessories - terminal

21
Operating System Laboratory Manual

Practical 1: Working with directories


1. Create a new directory in the home directory which is called lab1.
 In order to make a new directory inside another directory, we use the
command mkdir.
mkdir lab1
 This will create a new directory called lab1 inside the current working
directory.
 Please note that creating a subdirectory will not change your current position
in the file system tree. Thus, after creating lab1, your current directory stills
remain you HOME directory.
2. List the contents of the current directory
 To find out the file contents of the current working directory we use the ls
command at the prompt.
ls list the files and folders in your current directory
 Files beginning with a dot (.) are known as hidden files and usually contain
important program configuration information. The ls command does not list this
files because they contain important data that needs not to be modified, if we are
interested to list all files in the current directory including those whose names
begin with a dot, we type:
ls -a
 Additional command options for ls command include:
ls -a (include hidden files)
ls -l (display extra information)
ls -r (recurs through directories)
3. Changing the working directory to the directory you just created:
 The command cd means change the current working directory to any directory
you want. The current working directory may be thought of as the directory you
are in, i.e. your current position in the file-system tree. To change to the directory
you have just made, type :
cd lab1
 If we want to change to a directory that is found in another location we can just
simply give the absolute or relative path of the directory.
cd path_of_directory
3.1. The directories . and ..
 In all directories there are two special directories called (.) and (..). In UNIX,
(.) means the current directory, so typing
cd .
With the space between cd and the dot means stay where you are (current
directory). Using (.) as the name of the current directory will save a lot of typing,
when we wish to refer to the current directory.
 (..) means the parent of the current directory, so typing
cd ..
will take you one directory up the hierarchy (back to your home directory).
Note: typing cd with no argument always returns you to your home directory. This
is very useful if you are lost in the file system.

22
Operating System Laboratory Manual

3.2. Printing the pathnames


 Pathnames enable you to work out where you are in relation to the whole file-
system. The pathname of a given location can be found by using the command
pwd in that directory. For example, to find out the absolute pathname of the
current directory, type
pwd
 The full pathname of the current directory will be displayed

3.3. ~ (your home directory)


 Home directories can also be referred to by the tilde ~ character. It can be used
to specify paths starting at your home directory. So typing
ls ~/lab1
Will list the contents of the directory called lab1 which is found in your home
directory, no matter where you currently are in the file system.
3.4. To move to root directory
 to move from your current directory to the root directory, type cd /
 With the space between cd and the slash (/)
3.5 To move to the home directory
 to move from your current directory to the home directory, type cd or cd ~
 With the space between cd and the ~
3.6 To move to the previous directory
 to move from your current directory to the previous directory you visited before, type
cd -
 With the space between cd and the -
3.7 To navigate to multiple paths
 Exercise
◦ Move your current to Desktop
◦ cd then cd Desktop
◦ cd /home/bdu/Desktop
◦ cd ~/Desktop
4. Removing a directory (deleting a directory)
 In order to delete or remove a directory from the file system, we use the
command rmdir. But first before we remove a directory we have to change the
current working directory to the parent directory which contains the directory we
want to remove.
rmdir lab1
Exercises
1 Change the directory to the home directory and create a new directory with your
name. Create two directories inside the newly created directory and delete one of them
from the file system.
2 List or display the contents of the root directory (/) directly from you current working
directory without changing the directory.
3 Try putting the l command option in question 2 with the list command, what is the
output? What is the change?
4 Verify on your system that the directories dot (.) and dot-dot(..) are not the same,
except in the root directory.
5 Make a directory inside lab1 directory which you just created in the previous
examples which is called ‘sysprog’.
a. Make ‘sysprog’ your current working directory.

23
Operating System Laboratory Manual

b. Now execute the following command twice:


cd ..
c. List the contents of that directory
d. In which directory you are located now? And how can you determine where you are?

Laboratory 4:
Working with files

1. Removing a directory (deleting a directory)


 In order to delete or remove a directory from the file system, we use the
command rmdir. But first before we remove a directory we have to change the
current working directory to the parent directory which contains the directory we
want to remove.
rmdir lab1
 This command will remove the directory called lab1 which is located in the
current working directory.
 This command will remove the directory only if it is empty, otherwise it will
give us an error message.
rm -r used to delete a directory and all of its contents recursively
 In order to remove files from a given directory, we use the command rm
(remove files). This command can also be used to delete directories and other
additional deleting facilities by providing different options.
Usage: rm [options] <file>
Example: rm text.txt
 We can supply the following command options to perform different types of
file deletion.
-i : Will remove the given file in an interactive manner. The shell will

24
Operating System Laboratory Manual

display a confirmation text whether we want to delete the file or not.


Based on the answer the file will be deleted or not. (yes or no)
Example: rm -i text.txt
-r : Will recursively delete a given folder and all of its contents.
Example: m -r directory_name
-f: Will forcefully delete the given file.
Example: rm -f file_name

2. Create a new file in the directory which is called lab1.


 Create the directory lab1 in your home directory.
mkdir lab1
 Change the working directory to the lab1.
cd lab1
 In order to create a blank or empty file use the command touch
touch text.txt
This will create a new file called text.txt in the directory lab1 which is empty.
Exercise
1. Demonstrate the difference between rmdir and rm –r commands. What
is their difference?

3. Editing a file using a command line editor


- While using UNIX you will often want to create a text file and then change its
content in some way. A text editor is a program that has been designed especially
for creating and editing text files. The easiest of all editors is the pico editor.
- Creating a new file named hello.txt
1. At your UNIX shell prompt, type pico filename, replacing filename with the name of
the file you want to create or edit. For example, to create a file and name it hello.txt, type:
pico hello.txt
Pico displays a menu bar of commonly-used commands at the bottom of the
screen.
2. Type the following lines on the editor:
Hello world,
This is Pico text editor
Lab 1.
Computer science
o To exit Pico, press [Ctrl] +[x].
 If you have made some changes, Pico will ask whether you want to save the changes.
Type y (yes) or n (no). If you type y, Pico displays the filename. (To save the edited file
under a different name, delete the filename and type a new one.) then Press [Enter].
o To save the file, press [Ctrl] +O.
o To open another file, press [Ctrl] +R.
Exercise: Modify the contents of your file hello.txt and save it with the same name.
4. Displaying the contents of a file on the screen
- Before you start the next section, you may like to clear the terminal window of the
previous commands so the output of the following commands can be clearly understood. In
order to clear the terminal window, we use the command clear. At the prompt, type:
clear

25
Operating System Laboratory Manual

- This will clear all text and leave you with the $ prompt at the top of the window.
cat (concatenate)
- The command cat can be used to display the contents of a file on the screen.
Example: To verify your wok in previous section, you can view the content of
hello.txt by typing:
cat hello.txt
- The cat command is useful for displaying short files of a few lines. To display longer
files use less or more commands.
5. Copying Files
cp (copy)
- The cp command allows you to copy a file from one location to another location. There
are different syntaxes to use cp command as shown below:
Syntax 1: ( copy a file to another file)
cp file1 file2
- Where file1 is the name of an existing file and file2 is the name for the new copy of that
file. The original file will remain unchanged and a copy will be placed in file2. If file1 and file2
are not in current directory, then you have to specify their pathname.
Syntax 2: (copy a file to another directory)
cp file directory e.g cp A ~Desktop
- Where file is the name of an existing file and directory is the name for the destination
directory. The original file will remain unchanged and a copy will be placed in that directory.
Exercise:
2. Create a directory called backup inside the current directory. Create a backup
of your hello.txt file into another file called backup.txt which is inside backup
directory and verify the file being copied by using the list command ls.
3. What does the following command does?
cp hello.txt ..
4. Copy the file named “hello.txt” to your home directory? Verify
your work.

6. Moving Files
mv (move)
- To move a file from one place to another, use the mv command. This has the effect of
moving rather than copying the file, so you end up with only one file rather than two. It can
also be used to rename a file, by moving the file to the same directory, but giving it a different
name. (mv hello.txt ~/helloo.txt)
Example: We are going to move the file “hello.txt” to the backup directory, type
mv hello.txt backup
Exercises
1. Rename the file hello.txt to goodbye.txt by using only the mv command.

7. Getting Help
In order to get information about commands, how they can be used, their options and
arguments, we can use different options.
man

26
Operating System Laboratory Manual

The UNIX man pages (man is short for manual) cover every command available. To
search for a man page, enter man followed by the name of the command you want to
find, UNIX will provide the manual or reference provided for that command.
man command_name
Info
The info command is similar to man, but is often more in-depth.
info command_name
This will provide the info page for the given command. If you need to know the
details of a given command you can use either info or man commands.
whatis
Displays short descriptions of commands. This is especially helpful if you just want to see the
basic structure and description of a given command.
whatis command_name
--help
It displays usage summary and argument list of a given command. It gives more
detailed description and argument list than whatis command but it doesn’t provide as
detailed information as man and info commands.
command_name --help
Exercises
1. Use the helps described above and understand the use and
function of the following commands, more, less, grep, wc, ps, id.

Laboratory 5:
More on UNIX and shell commands
Objective:
This Lab is a continuation of review of the UNIX system. We are going to see more basic
commands that are used in UNIX shell. The followings are the primary objectives of this lab
session:
 Be able to use more additional commands used for processing files in UNIX
shell and execute them.
 Be able to perform simple searches on files using shell commands
 Understand and implement input and output redirection.
 Understand file protection in UNIX and changing file permissions using the
shell commands.
 Creating and executing shell scripts.

Procedures: Open the shell (terminal) and follow the following procedures
Practical 1: Working with additional commands on files.
Create a file called hello.txt on your current directory and follow the following procedures.
Make sure that you have written more than 10 lines of text on the file.
1 Displaying the contents of files.
cat is short for concatenate. This command is used to create, view and concatenate
files.
cat /etc/passwd

27
Operating System Laboratory Manual

This command displays the "/etc/passwd" file on your screen. Notice that
some of the contents of this file may scroll off of your screen.
less The command less writes the contents of a file onto the screen a page at a
time. Type
less hello.txt
Press the [space-bar] if you want to see another page, type [q] if you want to quit
reading. As you can see, less is used in preference to cat for long files.
head: The head command writes the first ten lines of a file to the screen. First
clear the screen then type
head hello.txt
tail: The tail command writes the last ten lines of a file to the screen. Clear the
screen and type
tail hello.txt
1 Concatenating two or more files
cat command can also be used to concatenate two or more files into a single file.
First create a file called goodbye.txt and write some text on it. Then type the
following command.
$ cat hello.txt goodbye.txt > combined.txt
This command combines the contents of the first two files into the third file. We
can also give more than two files to be concatenated.
wc (word count) : A handy little utility is the wc command, short for word count.
To do a word count on hello.txt, type
wc hello.txt
This will display three values, the number of new lines, the number of words
and the number of bytes in the given file. To get only the word count, type:
wc -w hello.txt
To find out how many lines the file has, type:
wc -l hello.txt
1 Simple searching on files
1 Using less to search on files
 Using less, you can search though a text file for a keyword (pattern).
For example, to search through hello.txt for the word 'science', type
less hello.txt
 then, still in less (i.e. don't press [q] to quit), type a forward
slash [/] followed by the word to search
/science
 As you can see, less finds and highlights the keyword. Type [n] to
search for the next occurrence of the word.
1 Using grep to search on files.
 grep is one of many standard UNIX utilities. It searches files for
specified words or patterns. First clear the screen, then type
grep science hello.txt
 As you can see, grep has printed out each line containing the word
science. Try typing
grep Science hello.txt
 The grep command is case sensitive; it distinguishes between Science
and science. To ignore upper/lower case distinctions, use the -i option, i.e.
type

28
Operating System Laboratory Manual

grep -i science hello.txt


 To search for a phrase or pattern, you must enclose it in single quotes
(the apostrophe symbol). For example to search for spinning top, type
grep -i 'science test' hello.txt
 Some of the other options of grep are:
-v displays those lines that do NOT match
-n precede each matching line with the line number
-c prints only the total count of matched lines
 Try some of them and see the different results. Don't forget, you can
use more than one option at a time, for example, the number of lines without
the words science or Science is
grep -ivc science science.txt
1 Wildcards
The characters * and ? are referred as wildcards.
*
 The character * (asterix) will match against none or more character(s)
in a file (or directory) name. For example, type
ls list*
 This will list all files in the current directory starting with list....
 Try typing
ls *list
 This will list all files in the current directory ending with ....list

?
 The character ? will match exactly one character. It will be used to
match only a single character in a file or directory. So typing:
ls ?ouse
will match files like house and mouse, but not grouse.
ls ?list
Will match every word with five letters and ending with list.

Exercise:
1 Type the following on the shell
head -5 hello.txt
What difference did the -5 do to the head command?
1 How can you view the last 15 lines of the file? Use the help provided by UNIX
to answer the question.
2 List all .txt files that are found on the current directory.
3 Create and save a text file called text.txt, write the following text inside the
file.
This is the second laboratory for systems programming.
Last time we saw some basic file and directory commands.
Today we are adding more commands that are used for manipulating,
displaying and searching files.
Once you finished editing and saved the file perform the following operations.
1.1. Display the number of words and lines in the above file.
1.2. Search for a single word from the file.
1.3. Search a phrase of two or more words from the file.
1.4. Search for all words that end with the phrase is.

29
Operating System Laboratory Manual

1.5. Search for all words that end with t and have a minimum length
of four letters.

Practical 2: Input and Output redirection


1 Output redirection
If you run the cat command without specifying a file to read, it reads the standard
input (the keyboard), and on receiving the 'end of file' (Ctrl+D), copies it to the
standard output (the screen).
In UNIX, we can redirect both the input and the output of commands. Type the cat
command and then type some other things, and see what happens:
cat
 We use the > symbol to redirect the output of a command. For example, to
create a file called fruits.txt containing a list of fruit, type
cat > fruits.txt
 Then type in the names of some fruit. Pear, banana, apple, orange then
Press [Enter] after each one.
 What happens is the cat command reads the standard input (the keyboard) and
then > redirects the output, which normally goes to the screen, into a file
called fruits.txt
 To read the contents of the file and see that the input of cat command is
redirected to the file fruits.txt, type:
cat fruits.txt
 Similarly you can redirect the output of one command to any given file.

Appending redirection: If you want to append the output of a command into a


file which already contains some data you will use >> instead of >.
 If you want to append more fruit names from the input(keyboard) to the file
fruits.txt, you can type:
cat >> fruits.txt

1 Input redirection
We use the < symbol to redirect the input of a command. The
command sort alphabetically or numerically sorts a list. Type
sort
 Then type in the names of some fruits. Banana, apple, orange, pear and then
Press [Enter] after each one.
 The output will be searched and displayed as follows:
 apple
 banana
 Orange
 pear
 Using < you can redirect the input to come from a file rather than the
keyboard. For example, to sort the list of fruit in the file, type:
sort < fruits.txt
 And the sorted list will be output to the screen. To output the sorted list to a
file, type:
sort < fruits.txt > sorted_fruits.txt
 Use cat to read the contents of the file in sorted_fruits.txt and see if the fruits
are sorted. Similarly any command's input can be redirected from any given file.

30
Operating System Laboratory Manual

1 Pipes
 To see who is on the system with you or see other users who are currently
logged into the system, type:
who
 One method to get a sorted list of names is to type,
who > names.txt
sort < names.txt
 This is a bit slow and you have to remember to remove the temporary file
called names when you have finished. What you really want to do is connect the
output of the who command directly to the input of the sort command. This is
exactly what pipes do. The symbol for a pipe is the vertical bar |
 For example, typing
who | sort
 Will give the same result as above, but quicker and cleaner.
 To find out how many users are logged on, type
who | wc -l
Exercise:
1. Create a backup of the file called text.txt which you have created in the previous
exercise inside a directory called backup using output redirection.
2. Use the cat command to create a file containing the following data which will be
obtained from the keyboard. Call the file mytable, use tabs to separate the fields
1425 Solmon 15.65
4320 Addis 26.27
6830 Selam 36.15
1450 Mamo 21.86

A. Use the cat command to display the file, mytable.


B. Use an editor to add two values to the file.
C. Use the sort command to sort the file my table according to the first field and store
the result in another file.

Practical 3: File system security and permissions.


Use the following command for long listing of files and directories:
ls -l
You will see that you now get lots of details about the contents of your directory, similar to
the example below.

Each file (and directory) has associated access rights, which may be found by typing ls
-l. Also, ls -lg gives additional information as to which group owns the file.
-rwxrw-r-- 1 ee51ab beng95 2450 Sept29 11:52 file1
In the left-hand column is a 10 symbol string consisting of the symbols d, r, w, x, -,
and, occasionally, s or S. If d is present, it will be at the left hand end of the string, and
indicates a directory: otherwise - will be the starting symbol of the string.

The 9 remaining symbols indicate the permissions, or access rights, and are taken as
three groups of 3.
 The left group of 3 gives the file permissions for the user that owns the
file (or directory) (ee51ab in the above example);

31
Operating System Laboratory Manual

 The middle group gives the permissions for the group of people to
whom the file (or directory) belongs (eebeng95 in the above example);
 The rightmost group gives the permissions for all others.
The symbols r, w, etc., have slightly different meanings depending on whether they
refer to a simple file or to a directory.
Access rights on files.
 r (or -), indicates read permission (or otherwise), that is, the presence or
absence of permission to read and copy the file
 w (or -), indicates write permission (or otherwise), that is, the
permission (or otherwise) to change a file
 x (or -), indicates execution permission (or otherwise), that is, the
permission to execute a file, where appropriate

Access rights on directories.


 r allows users to list files in the directory;
 w means that users may delete files from the directory or move files
into it;
 x means the right to access files in the directory. This implies that you
may read files in the directory provided you have read permission on the
individual files.
So, in order to read a file, you must have execute permission on the directory containing that
file, and hence on any directory containing that directory as a subdirectory, and so on, up the
tree. Some examples

-rwxrwxrwx A file that everyone can read, write and execute (and delete).
-rw------- A file that only the owner can read and write - no-one else
can read or write and no-one has execution.

Changing Access rights


chmod (changing a file mode)
Only the owner of a file can use chmod to change the permissions of a file. The options
of chmod are as follows

Symbol Meaning
u User
g Group
o Other
a All
r Read
w write (and delete)
x execute (and access directory)
+ add permission
- take away permission

32
Operating System Laboratory Manual

For example, to remove read write and execute permissions on the file fruits for the
group and others, type
$ chmod go-rwx fruits.txt
This will leave the other permissions unaffected. To give read and write permissions on
the file fruits to all,
$ chmod a+rw fruits.txt
Use ls -l to check that the permissions have changed.

Practical 4: Working with shell scripts.


Besides being a command line interface, the shell is also a command language interpreter.
This means that you can glue together commands using simple programming language
constructs and work on variables. You can create text files containing list of commands for
the shell to process (as if you typed them in). Such files are called shell scripts, and they are
very useful as they allow you to quickly automate things.
There are two ways you can execute your shell scripts. Once you have created a script file.
Method 1
Pass the file as an argument to the shell that you want to interpret your script.
Step 1: create the script using an editor like pico or nano and save it by giving it a
name. In our example we are using the name show for the file.
For example: the script file shown has the following lines. Echo command simply
displays what is written next to it, while date command displays the current time and
date.
echo Here is the date and time
date
Step 2: To run the script, pass the filename as an argument to the shell which is
referred as sh
$ sh show
Here is the date and time
Sat jun 03 13:40:15 PST 2006
Method 2:
Make your script executable using the chmod command. When we create a file, by default it
is created with read and write permission turned on and execute permission turned off. A file
can be made executable using chmod.

Step 1: create the script using an editor like pico or nano.


For example: the script file shown below has the following lines, write and save the
file.
echo Here is the date and time
date
Step 2: Make the file executable
$ chmod u+x show
Step 3: To run the script, just type the filename
$ show
Here is the date and time
Sat jun 03 13:40:15 PST 2006
file system and disk usage commands
df displays filesystem disk space usage for all mounted partitions.
du The du command displays the disk usage for a directory.

33
Operating System Laboratory Manual

 Installing applications in ubuntu

Laboratory 6:
Editing, compiling and running C programs in UNIX

Objective:
In this lab we are going to start working on C programming under the UNIX operating
system. We will demonstrate how we can edit, compile and execute C programs using the
UNIX operating system. The followings are the primary objectives of this lab session:
 Be able edit C programs using command line text editors in UNIX.
 Using shell commands to compile and execute C programs under UNIX OS.
 Use the gcc compiler driver to interact with different C facilities.
 Use command options to manipulate the compilation and execution of C
programs.

Procedures: How to use C programming in UNIX operating system.


Step 1: Use an editor, such as pico, vi, ex, or ed to write the program. The name of the file
containing the program should end in .c.
For example, the file hello.c contains the following lines:
main()
{
printf(“ Hello Universe “);
}
Step 2: Submit the file to GCC (the GNU C Compiler)
$ gcc –o hello hello.c
If the program is okay, the compiled version is placed in a file called hello.out
Step 3: To run the program, type show.out
$ hello.out or ./hello

34
Operating System Laboratory Manual

Hello Universe
Practical 1: Write a simple C program and execute it.
 Write the following C program and save it in a file called hello.c.
#include<stdio.h>
void main()
{
printf(“ Hello Universe “);
}
 Compile the file using the gcc compiler driver in the shell
$ gcc –o hello hello.c
 Execute the executable file and see the output
$. /hello or $ hello

Practical 2: Understanding the role and function of pre-processor, compiler, assembler


and linker.
1. Write the following C header file and save it using the name head.h.
extern int x = 25;
2. Write the following C program and save it using the name test.c.
#include "head.h"
#define MAX 256
#define double(x) (x+x)
int add(int x, int y);
void main(){
int x = 25;
int y = 35;
int result = add(x,y);
int x2 = double(x);
int y2 = double(y);
int z = MAX + 5;
}
int add(int x, int y){
int result = x + y;
return result;
}
3. Use the gcc compiler driver and pre-process test.c file and see the output of the
pre-processor.
$ gcc –E test.c –o test.i
Exercise: What do you understand from the generated file from the pre-processor?
What do you think is the function of the pre-processor? What type of file is generated
from the pre-processor?
4. Use the gcc compiler driver and compile test.i file and see the output of the
compiler.
$ gcc –S test.i –o test.s
Exercise: What do you understand from the generated file from the compiler? What
do you think is the function of the compiler? What type of file is generated from
the compiler?
5. Use the gcc compiler driver and assemble the test.s file and see the output of
the assembler.
$ gcc –c test.s –o test.o

35
Operating System Laboratory Manual

Exercise: What do you understand from the generated file from the assembler? What
do you think is the function of the assembler? What type of file is generated by the
assembler?
6. Use the gcc compiler driver and link test.o file and see the output of the linker.
$ gcc test.o –o test

Exercise: What do you understand from the generated file from the linker? What do you
think is the function of the linker? What type of file is generated from the linker?

Laboratory 7:
More on C programs in UNIX

Practical 1: working and linking with more than one C programs.


1. Write the following C header file and save it using the name head.h.
Extern int array[];
2. Write the following C header file and save it using the name main.h.
#include<stdio.h>
#include"head.h"

void swap();
void display();
int array[2] = {25,50};
void main(){
printf("\nBefore Swap\n");
display();

36
Operating System Laboratory Manual

swap();
printf("\nAfter Swap\n");
display();
}
3. Write the following C program and save it using the name swap.c.
#include<stdio.h>
#include"head.h"

void swap(){
int temp = array[0];
array[0] = array[1];
array[1] = temp;
}

void display(){
printf("\nElement O : %d \n",array[0]);
printf("\nElement 1 : %d \n\n",array[1]);
}

4. Try to compile and run the two C programs separately.


$ gcc main.c –o main
$ gcc swap.c –o swap
Exercise:
1. Were you able to run the program? What do you think is the problem?
2. In which phase do you think the problem happened?
3. Try to pre-process, compile and assemble the files separately. Were there
problems?
4. Try to link the output of the assembler for the two programs and try to run the
program?
Did the problem get resolved?
$ gcc main.o swap.o –o output
Exercises: Writing different C programs.
1. Write a C program that accepts two integer numbers from the user and
calculate the sum, difference, multiplication and division of the two numbers and
display the result.
2. Modify the above program to implement the operations using different
functions. So create a function that performs addition, subtraction, multiplication
and division.
3. Write a C program with the following specification:
1. Represents student information using a structure called student, which
contains name, age, department, year and semester.
2. Create a function called FillStudent() that accepts name, age,
department, year and semester from the user, create a student type
structure and return the structure.
3. Create a function called DisplayStudent() that accepts one structure as
an argument and display its contents to the user.

37
Operating System Laboratory Manual

4. In main function create an array of student type structure with size 5.


Use the FillStudent() function to fill the values of the structure and finally
display the contents of the array using the DisplayStudent() function.

Laboratory 8:
Different simulations on C programs in UNIX

38
Operating System Laboratory Manual

39

You might also like