0% found this document useful (0 votes)
42 views111 pages

OS Lab Mannual

Linux is an open-source, Unix-like operating system that can be used for various purposes including home, office, server, and embedded systems. It offers advantages like high performance, stability, low cost, strong networking capabilities, flexibility, and more. Popular Linux distributions include Ubuntu, Slackware, SuSE, Debian, RedHat, and Fedora. The document then provides step-by-step instructions for installing Ubuntu 20.04 alongside Windows 10 in a dual-boot configuration, including preparing the system, downloading Ubuntu, creating installation media, partitioning disks, and completing the installation process.

Uploaded by

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

OS Lab Mannual

Linux is an open-source, Unix-like operating system that can be used for various purposes including home, office, server, and embedded systems. It offers advantages like high performance, stability, low cost, strong networking capabilities, flexibility, and more. Popular Linux distributions include Ubuntu, Slackware, SuSE, Debian, RedHat, and Fedora. The document then provides step-by-step instructions for installing Ubuntu 20.04 alongside Windows 10 in a dual-boot configuration, including preparing the system, downloading Ubuntu, creating installation media, partitioning disks, and completing the installation process.

Uploaded by

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

Chapter One

1. Introduction to Linux Operating Systems


Linux is a freely available, open source, UNIX-like operating system. Written originally for the
PC by Linus Torvalds, with the help of many other developers across the internet, Linux now
runs on multiple hardware platforms. Linux is widely used for both basic home and office uses.
It is the main operating system used for high performance business and in web servers.
Features of Linux Operating System
The following are various features of Linux operating system:
 Performance :-it has ability to handle large numbers of users simultaneously.
 stability :- has high stability compared with other operating systems. There is no need to
reboot the Linux system to maintain performance levels rarely.
 Low cost :- There is no need to spend time and huge amount money to obtain licenses
since you uses Linux.
 Networking :- It can perform tasks like network backup more faster than other
operating systems.
 Flexibility :- Linux is very flexible. Linux can be used for high performance server
applications, desktop applications, and embedded systems.
 Compatibility :- it runs all common Unix software packages and can process all
common file formats.
 Fast and Easy Installation :- Linux distributions come with user-friendly installation.
 Better use of HDD :- Linux uses its resources well enough even when the hard disk is
almost full.
 Multi_tasking :- it can handle many things at the same time.
 Open Source :- you can easily get the source code for Linux and edit it to develop your
personal operating system.
Linux Distributions
some Linux distributions
 Ubuntu
 Slackware
 SuSE
 Debian
 RedHat
 Fedora
 Turbo Linux

figure 1.1 some types Linux distributions

Students I would like to show you how to install Ubuntu Linux operating system the latest
version 20.04 alongside windows 10 Dual Boot and how to write commands or how to use
Ubuntu operating systems.
Ubuntu
Canonical started sending out free compact discs with Ubuntu Linux in 2004 and quickly
became popular for home users (many switching from Microsoft Windows).
Canonical wants Ubuntu to be an easy to use graphical Linux desktop without need to ever see
a command line. Of course they also want to make a profit by selling support for Ubuntu. Go to
the official Ubuntu download page and You can download Ubuntu ISO file from web and you
can choose the versions you want to download and you can choose 32 bit or 64 bit operating
system.
1.1. Linux Operating System Installation

System requirements (recommended)


Here's what Canonical lists as the recommended minimum system requirements for installing
the desktop edition of Ubuntu 20.04 Focal Fossa. Keep in mind that this pertains to physical
installs. Virtualized installs can actually get by with less.
 2 GHz dual core processor
 4 GB RAM (System Memory)
 25 GB of Hard Drive Space(or USB stick, memory card or external drive but see
LiveCD for an alternative approach)
 VGA capable of 1024 * 768 screen resolution
 Either a CD/DVD drive or USB port for the installer media
 internet access is helpful
Step 1: Download Ubuntu 20.04 LTS ISO image
download Ubuntu 20.04 LTS ISO image from the Ubuntu website desktop versions.
https://ubuntu.com/download/desktop
Step 2: Create a Live USB / Write a Boot-able CD Create a Boot-able CD/DVD
Write the downloaded Ubuntu OS image to a DVD using your favorite DVD burner in
Windows. I have used USB drive to install Ubuntu, students you can used what you want CD
or DVD or USB .
Create a boot able USB disk
Use Rufus (BIOS / UEFI compatible) to create a boot able USB disk.
Figure 1.2 booting USB drive

Step 3: Prepare Windows System for Dual-Boot


In most of the cases, Laptop / Desktop vendors ship machines with Windows OS pre-installed
and the whole disk used for the operating system (c: drive). So, machines will not have any free
space (unallocated disk space) left for Ubuntu 20.04 installation.
Ubuntu 20.04 requires 25 GB of disk space for the installation. If you have two or more
partitions on your computer you have select the partition having more free space or the
partition that windows operating systems not installed.
Otherwise, as the first thing, we will create free disk space on the hard drive for Ubuntu 20.04
installation. Go to Windows OS, press win + R to open Run then type “diskmgmt.msc” to open
the disk management utility.
Figure 1.3 Disk Management
Since my machine has only one partition, i.e., C:, I will shrink it for Ubuntu installation.
Consider shrinking the last partition in case your system has more than one partition.
Right-click on C: drive partition and then select Shrink Volume to resize the partition.

Figure 1.4 Shrink C drive

Enter the size in MB and then click Shrink to begin the shrinking operation.
For Example: To get a 100GB free disk space on the 1TB partition, you would need to
enter 102400.

Figure 1.5 Shrink partition


Wait for a few minutes, and you will see an unallocated space of 100GB.

Figure 1.6 Unallocated Space After Shrinking


Step 4: Boot from USB Stick or CD
Insert the DVD or USB stick on the system and then reboot the machine. Change the boot
sequence on BIOS/UEFI to boot a system from DVD/USB by pressing ESC, F2, F9, F10 or
F12 keys (read the vendor manual for more information).

Step 5 : Preparing To Install Ubuntu 20.04 LTS


UEFI System
once the system boots up from DVD/USB drive, the grub boot screen should appear on
your machine. Select Ubuntu from the menu and then press Enter.

Figure 1.7 Install Ubuntu On UEFI System


Legacy BIOS System
Do not interrupt the booting form DVD or USB.
Figure 1.8 Media Booting in Legacy BIOS System
Press Ctrl + C to cancel all file system checks.

Figure 1.9 File system checks


Wait for few minute to let DVD/USB disk loads into memory and bring up the Ubuntu
Live system.

Figure 1.10 Media Booting On UEFI System


click Install Ubuntu on the welcome screen.
Figure 1.11 Welcome screen
Choose the keyboard and then click Continue to proceed further.
Figure 1.12 Keyboard Layout

Step 6: Normal/Minimal Installation


On this screen, you need to select the apps for installation.
Normal Installation – You will get a graphical desktop environment with all regular
software. Minimal Installation – You will get a basic desktop environment with a
browser and core system administration utilities.
You can optionally choose to install system updates and third-party software during OS
installation.
The system requires an active internet connection to download updates and software.
The installation may take a bit more time depends on the downloadable contents.
Figure 1.13 Updates and other software – UEFI System

Step 7 a: Automatic Partitioning


UEFI Systems:
If you choose to install Ubuntu alongside Windows Boot Manager, the installer will
take care of creating partitions for Ubuntu installation and install Ubuntu 20.04 along
with Windows 10. Use this option only if you don’t mind about the partition layout and
its size.
Figure 1.14 Install Ubuntu alongside Windows Boot Manager
click Continue to confirm the automatic partition creation.
Figure 1.15 Confirm the auto partitioning
Legacy BIOS System:
If you choose to Install Ubuntu Alongside Windows 10, the installer will take care of
creating partitions for Ubuntu installation and install Ubuntu 20.04 along with Windows
10. Use this option only if you don’t mind about the partition layout and its size.

Figure 1.16 Install Ubuntu Alongside Windows 10


click Continue to confirm the automatic partition creation.
Figure 1.17 confirm the auto partitioning

Step 7 b: Manual Partitioning


if you want to create partitions manually with the size you want, select Something else
option and then click Continue.
Figure 1.18 manual partitioning
here, in this step, we will create partitions manually for Ubuntu 20.04 installation.
We will create below partitions.
UEFI System:
 /home _ 10 GB
 swap _ 4 GB
 /-Remaining (86 GB)
Legacy BIOS:
 /boot – 1 GB (Optional)
 /home – 10 GB
 swap – 4 GB
 / - Remaining (85 GB)
you should see some free disk space we created earlier. Select the free space and then
click on the + sign to create partition for Ubuntu 20.04 installation.

Figure 1.19 available free space


/boot – 1GB (Optional) – For Legacy BIOS System Only:
Figure 1.20 Boot Partition(for Legacy BIOS System)
/home Partition:

Figure 1.21 Home partition


Swap Partition:
Figure 1.22 swap partition
/(root) Partition:

Figure 1.23 root partition


once you have created the required partitions, click Install Now to write the changes to
disk.
Figure 1.24 Partitions List
click Continue to write the changes to disks.
Figure 1.25 Confirm manual partitioning

Step 8: Additional Configurations


select your locations from the map and then click Continue. This is for your system
timezone.
Figure 1.26 timezone
fill the user creation form to create a user account (administrative account (sudo)) for
your system. Also, set the host-name for your system and then click on the Continue to
begin the installation.
Figure 1.27 User Creation

Step 9: Ubuntu 20.04 – Installation


the below screenshot shows the installation of Ubuntu 20.04. the installation will take at
least 15 to 30 minutes to complete.
Figure 1.28 Ubuntu 20.04 Installation Progress
once the OS installation is complete, click the Restart Now to reboot the machine or
your computer.
Figure 1.29 Ubuntu 20.04 Installation Complete
Remove the installation DVD ROM, if required, and then press Enter Button.
Figure 1.30 Remove Installation Media or medium
Boot To Ubuntu 20.04
after the system reboot, you will get the grub menu, where you will see both Ubuntu
and Microsoft Windows listed.
Default OS is Ubuntu. Press Enter in while your selection is Ubuntu to boot into
Ubuntu 20.04.
UEFI System
Figure 1.31 Boot Ubuntu 20.04 -UEFI System
Legacy BIOS System
Figure 1.32 Boot Ubuntu 20.04 -Legacy BIOS System
Log in with your credentials to get the desktop screen.
Figure 1.33 Ubuntu 20.04 Login Screen
Ubuntu 20.04 Post – Installation
Upon successful login, you will get the Welcome to Ubuntu wizard.
If you want, you can connect your online accounts to your Ubuntu system. Otherwise,
you can skip.
Figure 1.34 Connect Online Accounts
If you are a subscriber to Ubuntu Advantage, then configure Livepatch that helps you
apply updates without requiring a reboot of your system.
Figure 1.35 Ubuntu Livepatch
You can either choose to send or not to send the system information to Canonical to
improve Ubuntu.
Figure 1.36 Improve Ubuntu
Decide whether you want to enable or disable location services.
Figure 1.37 Privacy
Ubuntu 20.04 is now ready for your use.
Figure 1.38 Ready to Go
You will now get the Ubuntu 20.04 desktop.
Figure 1.39 Ubuntu 20.04
Ubuntu 20.04 supports NTFS file systems. So, you can easily access Windows
partitions from Ubuntu.
Figure 1.40 Access Windows 10 File from Ubuntu 20.04

Boot To Windows Operating System


if you want to boot into Windows 10, reboot the system and select the Windows
partition.
UEFI System
Select the Windows Boot Manager (on dev/sda2) from the GRUB menu.
Figure 1.41 Boot To Windows 10 – UEFI System
Legacy BIOS System
Select the Windows 10(on dev/sda1) from the GRUB menu.
Figure 1.42 Boot To Windows 10 – Legacy BIOS System

1.2. Windows 10 Installation

Part 1: Booting to the Windows 10 Installer


Step 1 : Download windows 10 ISO file from internet and Create a boot able
Installation media
You can download on this page.
https://www.microsoft.com/en-us/software-download/windows10ISO
Write the downloaded Windows 10 OS image to a DVD using your favorite DVD burner in
Windows. I have used USB drive to install Windows 10, students you can used what you want
CD or DVD or USB .

Step 2: Make sure your Windows 10 installation media is connected.


In order for you to install Windows 10, your Windows 10 installation file must be loaded
onto a disc or flash drive, and the disc or flash drive must be inserted into your
computer.
Part 2: Installation of Windows 10
Step 1: Press the power button to boot your PC.
 Your PC will display this screen. Press a key ESC , F9 or F12 button to boot
from the USB or DVD.

Step 2: Click Next when prompted. You can also change the options on this page (e.g.,
the setup language) before continuing if need be.
Step 3: Click Install Now. It's in the middle of the window.

Step 4:
Enter your Windows 10 key, then click Next. If you don't have a Windows 10 key,
instead click Skip in the bottom-right corner of the screen.
Step 5: Click the "Accept" box and click Next. This will indicate that you accept the
terms of use.

Step 6: You can click Custom instead to clean install Windows 10 on your
computer. Doing so will prompt you to select a partition to format before continuing.
Step 7: Then select the hard drive (partition) you wish to install the OS and click
Next.

Wait for the installation to complete the first steps to install Windows 10 to a new hard
drive. This step will take a while.
When the installation steps are completed, your PC will display a restart notification
countdown. To restart immediately, click Restart now. See the second image below.
The restart will take a while. Then your PC will display the following screens. It may
stay on the Getting ready screen for a while. After the Getting ready screen, your PC
will restart again..

Windows 10 Installation Post Configuration


Check that your region is correct. Then click Yes to continue. Otherwise, select your
region and click Yes.

Then confirm that your keyboard is correct and click Yes. Or select a new keyboard.
At the option to add a second keyboard, to add a new keyboard click Add layout.
Otherwise, click Skip.

The installer will begin configuring some additional setups.


Then you will be offered the option to choose whether you are installing Windows for
personal use or for a company. Select an option and click Next. For this demo, I will
select Setup for personal use.

If you have micro soft account and internet connection you should fill your email and
password the space provided and then press sign in button.
If you don’t have any of the above press skip this step link and create local account for
the PC. Then type your PC user name and password then press next button.

Finally, on the next set of screens, configure various privacy options including Cortana.
For most of the screens, select an option then click Yes or No…or Accept or Decline.
 After making your selections, the installer will perform some final configurations
Then you will be automatically signed in.

Finally you have installed Windows 10.


Chapter Two

2. Basics Linux and Windows Commands

2.1. Basic Linux commands

1. System Information Commands


Date :- This command is used to display the current date and time.
Syntax:
$date
$date +%ch
Format Purpose Example
+%m To display only month $date+%m
+%h &&+%b To display abbreviated month name $date+%h and $date+%b
+%d To display day of month $date+%d
+%y To display last two digits of years $date+%y
+%H To display hours $date+%H
+%M To display minutes $date+%M
+%S To display seconds $date+%S
+%a To display abbreviated weekday $date+%a
+%A To display full name of weekday $date+%A
+%B To display full name of month $date+%B
+%c To display current day and time $date+%c
+%u To display week of the year $date+%u
+%Z To display timezone $date+%Z
+%T To display HH:MM:SS format $date+%T
+%P To display AM or PM $date+%P
+%L To display day of the year $date+%L
+%D To display Day in “mm/dd/yy” format $date+%D
Students I will show you the effects of some of the above commands when we write on
terminal, you should try your self the commands we are not discussed.

calendar command: - This command is used to display the calendar of the year or the
particular month of calendar year.
Syntax :
$cal <year>
$cal <month> <year>
the $cal command displays the current day of month march 2021.
you can type $cal year command displays the calendar of the year you have entered.
you can also display a calendar of a month of a year.

Uptime Command:- returns information about how long your system has been running
together with the current time, number of users with running sessions, and the system
load averages for the past 1, 5, and 15 minutes. It can also filter the information
displayed at once depending on your specified options.

w Command:- w command is used to get a list of currently logged in users on a system.


It also provides valuable information like host, login time, idle time, JCPU.

whoami Command:-It displays the username of the current user when this command is
invoked.
Finger command is a user information lookup command which gives details of all the
users logged in. This tool is generally used by system administrators. It provides details
like login name, user name, idle time, login time, and in some cases their email address
even.

df Command:-is used to display the disk space used in the file system. The 'df' stands
for "disk file system." It defines the number of blocks used, the number of blocks
available, and the directory where the file system is mounted.
uname command Uname is the short name for 'UNIX name'.command is used to display
basic information about the operating system and hardware.
uname – a Command: checking all the information of the system.

cat /proc/meminfo Command:-is used by to report the amount of free and used memory
(both physical and swap) on the system as well as the shared memory and buffers used
by the kernel.

free command:-command provides information about the total amount of the physical
and swap memory, as well as the free and used memory
2. File Commands
List Directory:- ls, ls -al, ls -it
ls commands

ls -it Command :-Sorting the Formatted listing by time modification

ls -R commands
You can use 'ls -R' to shows all the files not only in directories but also sub directories.
ls -al commands (Listing Hidden Files )
Hidden items in UNIX/Linux begin with -. period symbol at the start, of the file or
directory.
Any Directory/file starting with a '.' will not be seen unless you request for it. To view
hidden files, use the command.
cd command
type cd command shows Change to home directory

To change directory
cd directory_name
pwd Command :- Show current working directory

mkdir command:- Creating a directory

If you want to create a directory in a different location other than 'Home directory', you
could use the following command. Example mkdir /Documents/SampleFolder.

You can also create more than one directory at a time.


cat >file command:- Places the standard input into the file with its type and then press enter
button and type your document and press ctrl + D after you have finished writing your
document.

more file commands:- Output the contents of the file

touch file commands:- to create a blank file.

Word command (wc) :- To list the content count of no of lines , words, characters .
Syntax :- $wc<filename>
Options :
-c – to display no of characters.
-l – to display only the lines.
-w – to display the no of words.

Copy file Commands


To copy a file in the same directory
Type cp <file> <file.copy> and press Enter.

To copy a file into another directory


Type cp <file> <directory> and press Enter.
To copy a folder into another directory
In order to copy a directory on Linux, you have to execute the “cp” command with the
“-R” option for recursive and specify the source and destination directories to be copied.

Move file or directory Commands


To move a file to a new file in the same directory (i.e., rename a file)

To move a file to another directory


To move folder to another directory
Suppose we want to move the folder "sample1" to location /home/woldiex/Documents
executing the command. mv sample1 /home/woldiex/Documents

deleting files and directory


rm file command:- Deleting the file

rm -f file command:- Force to remove the file


rm prompts for confirmation removal if a file is write protected. The -f option overrides
this minor protection and removes the file forcefully.

rm -i file commands:- To invoke a prompt before removing a file; waits for a "Y" or
"N" response.
rm dir commands:- To remove a directory(that does not contain files).

If the directory is not empty, you will get the following error:
rmdir: failed to remove 'dir1': No such file or directory

In this case, you will need to use the rm command or manually remove the directory
contents before you can delete it.
Removing Directories with rm
rm is a command-line utility for deleting files and directories. Unlike rmdir the rm
command can delete both empty and non-empty directories.
By default, when used without any option rm does not remove directories. To delete an
empty directory, use the -d (--dir) option and to delete a non-empty directory, and all
of its contents use the -r (--recursive or -R) option.
rm -r dir commands:- Removes a directory even if it contains files. To remove non-
empty directories and all the files within them, use the rm command with the-r
(recursive) option:
rm -ri dir commands:- The -i option tells rm to prompt you to confirm the deletion of
each sub directory and file. If the directory contains a lot of files, this can be a little
annoying, so you may consider using the -i option what will prompt you only once
before proceeding with the deletion.

rm -rf dir commands :- Force to remove the directory


To remove non-empty directories and all the files without being prompted, use rm with
the -r (recursive) and -f options:
3. File Compression and Decompression
There are quite a few commands on Linux for compressing files.
Compress and Decompress files using zip
The zip command creates a compressed file while leaving the original file intact.
You can use the 'zip' command to compress a folder full of files.
Compress and Decompress files using gzip
The gzip is a utility to compress and decompress files using Lempel-Zip(LZ77) coding
algorithm.
To compress files replacing the original ones
to compress a file named file_name.txt, replacing it with a gzipped compressed version,
run: $ gzip file_name.txt then press enter button

gzip will replace the original file myname.txt with gzipped compressed version named
myname.txt.gz
To compress file without replacing the original ones
By default, gzip program will compress the given file, replacing it with a gzipped
compressed version. You can, however, keep the original file and write the output to
standard output. For example, the following command, compresses file_name.txt and
writes the output to compressed_file_name.txt.gz.
$ gzip -c file_name.txt >compressed_file_name.txt.gz.

Here is our example we are zipped midexam.txt without replacing the original ones.
Compress file with gzip by specifying compression level
Another notable advantage of gzip is it supports compression level. It supports 3
compression levels as given below.
 1 – Fastest (worst)
 9 – Slowest (best)
 6 – Default
To compress a file named midexam.txt, replacing it with a gzipped compressed version
with default compression level, we use:
$ gzip -6 midexam.txt >midexamco.txt.gz
midexamco.txt.gz is file name we want to be archived
In this case there is a prompt to compressed the file we have given, if we had enter “y”
the zipped file replaced the original one’s; if we enter “n” the file compressed with the
name we had given without replacing the original file.
Decompress file using gzip
To decompress the file file_name.txt.gz, replacing it with the original uncompressed
version, we do:
$ gzip -d file_name.txt.gz
example : decompress the file myname.txt.gz

we can also use gunzip to decompress the files


$ gunzip file_name.txt.gz
Exercise :
1. students try it at home how to decompress files or directory using gunzip command
without replacing the original one’s?
Compress and decompress files using bzip2
The bzip2 is very similar to gzip program, but uses different compression algorithm
named the Burrows-Wheeler block sorting text compression algorithm, and Huffman
coding. The files compressed using bzip2 will end with .bz2 extension.
To compress a file using bzip2, replacing it with compressed version, run:
$bzip2 file_name.txt

If you don’t want to replace the original file, use -c flag and write the out put to a new
file.
$ bzip2 -c file_name.txt > New_file_name.txt.bz2
To decompress file using bzip2
$ bzip2 -d file_name.txt.bz2
$ bunzip2 -d file_name.txt.bz2
First list files in your directory and then type a command bzip2 -d filename.txt.bz2 then
press enter button after that displayed your currently working directory then type ls
command and view what happened in your working environment.

Exercise :
1. students try it at home how to decompress files or directory using bunzip2
command?
Compress and decompress files and directory using tar command
The primary function of the tar command is to create backups. The archive format
preserves the directory structure, and the file system attributes such as permissions and
dates.
Tar syntax:
tar [function] [options] [paths]
The tar command supports the following functions:
 tar -c: Create a new archive.
 tar -A: Append a tar file to another archive.
 tar -r: Append a file to an archive.
 tar -u: Update files in an archive if the one in the file system is newer.
 tar -d: Find the different between an archive and the file system.
 tar -t: List the contents of an archive.
 tar -x: Extract the contents of an archive.
While specifying the function, the ‘-‘ prefix is not required, and the function can be
followed by other single letter options.
Some of the supported options include:
 -a: Read or write archives using the compression algorithm determined by the
archive file name.
 j: Read or write archives using the bzip2 compression algorithm.
 -J: Read or write archives using the xz compression algorithm.
 -z: Read or write archives using the gzip compression algorithm.
 -v: Perform the operations verbosely.
 -f: Specify the file name for the archive.
Create an archive file containing file1 and file2
$ tar cvf archive.tar file1 file2
Example : create an archive file newfile.tar containing myname.txt, newtest.txt.
In this case we had created a file with file name newfile.tar without replacing the
original files. After we had write filename.tar and typing file names to be compressed
and pressed enter button files we had compressed are listed.
Create an archive file containing the directory tree below dir
$ tar cvf archive.tar dir
Example : create an archive Desktop.tar containing files in side Desktop folder.

In this case an archive Desktop.tar is created without replacing of original folder


Desktop in side Downloads directory.
Extract the contents of archive.tar to the current directory
$ tar xvf archive.tar
Example : extract the file newfile.tar

Create an archive file containing the directory tree below dir and compress it using gzip
$ tar czvf archive.tar.gz dir
In this case we had created an archive file with file name newfile.tar.gz in side
Downloads folder, the command czvf copy's the newfile.tar from sub directory of
Downloads folder of directory New in Downloads with out removing the original file in
the sub directory. After we had write filename.tar and typing file names to be
compressed and pressed enter button files we had compressed are listed.

Exercise : students try it at home how to


 List the contents of archive.tar file
 Extract the contents of the gzipped archive file.
 Extract all “.doc” files from the archive.
4. Networking Commands
Networking is an essential part of an operating system. Most of the computers in the
world connect through a network. This network can be a small and straightforward
home-based or as complex as a cloud computing data center. The networking task
includes configurations, traffic monitoring, and troubleshooting.

Ifconfig command:-ifconfig (interface configurator) is one of the most basic and


commonly used commands for finding network details. It is also used to configure
network interface parameters.
We can use this command to get the IP address, MAC address, and MTU of available
networks.

ip command:- is the latest version of ifconfig. It is more powerful than ifconfig


command as it can perform several other tasks like configuring default or static routing,
showing IP addresses and its properties, setting up IP addresses, and routes for network
interfaces.
Ip link command:- is for configuring, adding, and deleting network interfaces. Use ip
link show command to display all network interfaces on the system :
ip route command:- Use the IP route to print or display the routing table. The following
command displays the contents of the routing table:

whois domain command:- whois command is used to get all the information about a
website. You can get all registration and ownership details using it.

Netstat command:- netstat command used to review each network connection and open
sockets on the Linux device. It provides connections, open sockets, routing tables
information.
Nslookup command:- nslookup (Name Server Lookup) command used to query DNS
to get a domain name, IP address mapping, or DNS records.

Dig domain command:-The dig command enables searching for a domain name. To
perform a DNS lookup, open the terminal and type. It is also used to verify DNS
mappings, MX records, and other DNS records.
This command, by defaults, shows only A-type DNS records; you can use additional
options to get other types of DNS records.
Syntax:
$ dig <domain name> <option>
Where <option> can be :
 MX for all MX type of DNS records
 NS for all NS type of DNS records
 ANY for all type of DNS records
Students you have to try by your self the above options.
traceroute command:- traceroute command is commonly used to troubleshoot the
network. It finds out the delay and pathway to your destination. It determines and
reports where is network latency comes from.

The above output shows the specified hostname, size of network packets, maximum
hops required, and IP address.
Ping command:- Use ping to see if a host is alive. This super simple command helps
you check the status of a host or a network segment. Ping command sends an ICMP
ECHO_REQUEST packet to the target host and waits to see if it replies.
By default, ping runs in an infinite loop. To send a defined number of packets, use -c
flag.
Syntax :
ping -c <number> <destination>
Where <number> is the packets limits you want to specify for the response.

Tip: The response rate of the ping command will be affected by your network connection
and the host’s physical location.
Exercise :
1.
2.
3.
4.
5.
6.

5. Grep Commands
Grep command in Unix/Linux is the short form of ‘global search for the regular
expression’. The grep command is a filter that is used to search for lines matching a
specified pattern and print the matching lines to standard output.
Syntax:
grep [options] [pattern] [file]
The pattern is specified as a regular expression. A regular expression is a string of
characters that is used to specify a pattern matching rule. Special characters are used to
define the matching rules and positions.
The grep command supports a number of options for additional controls on the
matching:
 -i: performs a case-insensitive search.
 -n: displays the lines containing the pattern along with the line numbers.
 -v: displays the lines not containing the specified pattern.
 -c: displays the count of the matching patterns.

Example : Show line number while displaying the output using grep -n, To show the
line number of file with the line matched and searching “hello” from the file
Downloads.txt.
Example : Checking for the whole words in a file : By default, grep matches the given
string/pattern even if it found as a sub-string in a file. The -w option to grep makes it
match only the whole words.

Example : Display the file names that matches the pattern : We can just display the files
that contains the given string/pattern.

Example : displaying the output using grep -v, To displays the lines not containing the
specified pattern “directory” from the file Downloads.txt.
Exercise:
1. displaying the output using grep -i and grep -c to search a word you want from the
file you have created before?
2. displaying the output using grep -l to search a file name from the file you have
created before?

6. File Permissions
Types of users
There are three types of users exist in Linux operating system, which is mentioned
below.
User (u):- is the owner of the file. By default, the person who created a file becomes its
owner. Hence, a user is also sometimes called an owner.
Group (g):- a user-group can contain multiple users. All users belonging to a group will
have the same Linux group permissions access to the file.
Other (o):- any other user who has access to a file. This file neither created a file, nor he
belongs to a user-group who could own the file.
All (a):- All users, identical to ugo.
Access to a file has three levels:
 Read permission r – If authorized, the user can read the contents of the file.
 Write permission w – If authorized, the user can modify the file.
 Execute permission x – If authorized, the user can execute the file as a program.
Checking file permission
run the following command to check the permission of all files and folders of current
directory.
$ ls -l
There’s a lot of information in those lines.
1. The first character will almost always be either a ‘-‘, which means it’s a file, or a
‘d’, which means it’s a directory.
2. The next nine characters (rw-r–r–) show the security; we’ll talk about them later.
3. The next column shows the owner of the file. In this case it is me, my userID is
“woldiex”.
4. The next column shows the group owner of the file. In my case I want to give the
“woldiex” group of people special access to these files.
5. The next column shows the size of the file in bytes.
6. The next column shows the date and time the file was last modified.
7. And, of course, the final column gives the filename.
chmod file permission command
Syntax :
chmod [permissions] [filename];
There are 2 ways to use the command -
A.Absolute mode
B. Symbolic mode
A. Absolute mode
In this mode, file permissions are not represented as characters but a three-digit octal
number.
chmod [option] [file]
The table below gives numbers for all for permissions types.
Number Permission Type Symbol
0 No Permission ---
1 Execute --x
2 Write -w-
3 Execute + Write -wx
4 Read r--
5 Read + Execute r-x
6 Read +Write rw-
7 Read + Write +Execute rwx

Let's see the chmod permissions command in action. Here are some examples of how to
use the chmod command in numeric mode:
Example : Give the file’s owner read and write permissions and only read permissions to
group members and all other users:
chmod 644 file_name
In this example the first number 6 give read and write permission to file’s owner or the
user, the second number 4 give read permission to group members and the third 4 give
read permission all other users or users except owner of the file.
Example : Give the file’s owner read, write and execute permissions, read and execute
permissions to group members and no permissions to all other users:
chmod 750 file_name
In this example the first number 7 give read, write and execute permission to file’s
owner or the user, the second number 5 give read and execute permission to group
members and the third 0 give no permission all other users or users except owner of the
file.
Exercise
1. Set read, write, and execute permissions to the file owner and no permissions for all
other users on a given file?
2. Set read, write, and execute permissions to the file owner and read permissions for
all other users on a given directory?
3. Remove the read, write, and execute permission for all users except the file’s
owner?

B. Symbolic mode
In the Absolute mode, you change permissions for all 3 owners. In the symbolic mode,
you can modify permissions of a specific owner. It makes use of mathematical symbols
to modify the Unix file permissions.
chmod [options] [ugoa] [permission] filename
The first set of flags ([ugoa…]), users flags, defines which users classes the
permissions to the file are changed.
 u - The file owner.
 g - The users who are members of the group.
 o - All other users.
 a - All users, identical to ugo
The second set of flags ([-+=]), the operation flags, defines whether the permissions are
to be removed, added, or set:
 - Removes the specified permissions.
 + Adds specified permissions.
 = Changes the current permissions to the specified permissions. If no permissions
are specified after the = symbol, all permissions from the specified user class are
removed.
Example : Give the members of the group and others permission to read the file, but not
to write and execute it and remove read permission for group and others :
chmod og+r filename and chmod og -r filename

Example: Add write and execute permission for user, group and others for file_name
$ chmod ugo+wx filename
In the above example firstly Desktop.txt had read, write and execute permission for user
or owner , read permission foe group and no permission for others. After we have added
permissions write and execute permission to the file Desktop.txt for
 user have read, write and execute permission for the file
 group have read, write and execute permission and others have write and execute
permission
Example : Remove the execute permission for all users: chmod a -x filename

In the above example firstly we have listed files with in their permission types using ls -
l command, then the file permission of Desktop.txt is
 read, write and execute for owner, read, write and execute for groups and write
and execute permission for others.
 After that we had removed execute permission for all users using chmod -x
Desktop.txt and then type the command ls -l and press enter button, the files are
listed with their permission types
 read and write permission for owner or user, read and write permission for
groups and write permission for others.
Exercise
1. Give read, write and execute permission to the file’s owner, read permissions to the
file’s group and no permissions to all other users?
2. Give read and execute permission to the file’s owner, read and write permissions to
the file’s group and no permissions to all other users?
3. Remove the read, write, and execute permission for all users except the file’s
owner?

Chown command
chown command is used to change the file Owner or group. Whenever you want to
change ownership you can use chown command.
 change ownership of the file
Changing the owner of a file with chown requires you to specify the new owner and the
file. The format of the command is:
syntax: chown [owner] [file]
Example: Change the owner of file1 to user2 assuming that it is currently owned by
the current user.

if you had type this command chown owner filename.filetype and the result becomes
changing ownership of your file ‘filename.filetype’ : operation not permitted you have
used sudo command before chown command to grant privilege.

In this case firstly the owner of the file midexam.txt is woldiex, then after we have used
sudo chown nik midexam.txt command the user of the file is changed to nik. Also
 change ownership of the directory
With chown, you can change a group for a file or directory without changing the owning
user. Chown :NewGroup directory
Example : Change the group of directory New to nik assuming that it is currently owned
by the current group woldiex.

Exercise
1. Change the ownership of a file you want to new_Group assuming that it is currently
owned by the current group of your device?
2. Change the owner of directory of your directory to new_owner assuming that it is
currently owned by the current group of your device?
3. Change the owner and group of directory of your directory to new_owner and
new_group assuming that it is currently owned by the current owner and group of your
device at the same time?
4. Change the owner and group of your file to new_owner and new_group assuming that
it is currently owned by the current owner and group of your device at the same time?
7. Process commands
ps command : To display the currently working processes

ps -ef command
To see a complete listing of all the processes currently scheduled. The -e option causes
ps to include all processes (including ones that do not belong to you), and the -f option
causes ps to give a long listing. The long listing includes the process owner, the process
ID, the ID of the parent process, processor utilization, the time of submission, the
process's terminal, the total time for the process, and the command that started the
process.

kill pid command : Kill the process with given pid


syntax : kill pid
example : if you want to kill a given process having an id 8821 then type your command
in terminal
kill 8821
top command : display all running processes.

ps -u command :
ps -x command : select all processes owned by you (runner of the ps command, root in
this case).

fg command : Brings the most recent job to foreground


2.2. Basic Windows Commands

System commands
Systeminfo command: Displays detailed configuration information about a computer
and its operating system, including operating system configuration, security information,
product ID, and hardware properties (such as RAM, disk space, and network cards).

whoami command: displays the user you are currently logged in and using in Windows.

cmdkey command: The Windows cmdkey command creates, lists and deletes stored
user names and passwords form a computer. The cmdkey command helps administrators
and security executives lists the user stored credentials and aids in finding evidence or
troubleshooting remote access issues.

qprocess command: Displays information about processes that are running on a Remote
Desktop Session Host server. You can use this command to find out which programs a
specific user is running, and also which users are running a specific program. This
command returns the following information:
 User who owns the process
 Session that owns the process
 ID of the session
 Name of the process
 ID of the process

winmgmt command: Winmgmt is the WMI service within the SVCHOST process
running under the "LocalSystem" account.
In all cases, the WMI service automatically starts when the first management application
or script requests connection to a WMI namespace.
wmic command: wmic is the abbreviation of Windows Management Interface
Command, is a simple command prompt tool that returns information about the system
you are running it on.
Common wmic queries
 how to find out the model of your computers
in order to find out the model name of a machine using wmi, simply follow the guide
below: go to in to command prompt and type wmic computersystem get model then you
will get:

 how to find your computer name and its systemtype


type wmic computersystem get name, systemtype

 how to find mac addresses of your computer


type wmic nic get macaddress, description

 how to find the serial number of your computer


type wmic bios get serialnumber or type wmic csproduct get identifyingnumber

 how to check physical memory of your computer


type wmic computersystem get totalphysicalmemory
color command: is an inbuilt command found inside the Windows Command
Processor (cmd.exe), that is used for changing the colors for the console's foreground
and background. By default, the console has white foreground color and black
background color (07 color code).

Date command: The date command can view or change the current date of the system
clock.
Type date without parameters to display the current date setting and a prompt for a new
date. Press enter to keep the same date.
If you press enter without typing a date, the current system date is not changed, and the
command exits.
If you provide a date in the format MM-DD-YY, the system date is set to that date.

time command: When this command is called from the command line or a batch script,
it will display the time and wait for the user to type a new time and press RETURN.
Pressing RETURN without entering a new time will keep the current system time. The
parameter '/T' will bypass asking the user to reset the time.

Echo command: Displays messages or turns on or off the command echoing feature. If
used without parameters, echo displays the current echo setting.
Echo is a command that outputs the strings it is being passed as arguments. It is a
command available in various operating system shells and typically used in shell scripts
and batch files to output status text to the screen or a computer file, or as a source part of
a pipeline.
File commands
dir command:

chdir command: Displays working (current) directory and/or changes to a different


directory. Used to change from one directory to another you specify.
mkdir command: Creates a new sub directory. If you do not specifically enter a path
designation, the directory will be created as a sub directory within the current directory.
There is no limit to the number of directories you can create.

Copy files and directories

Move files and directories

rmdir command: Do you want to delete a directory from Windows command


prompt(CMD)? This post explains how to use the command rmdir to delete folders
and their contents. You can also find examples for each use case of folder deletion –
empty folders, non empty folders, folders with white spaced names etc.
Delete folder from CMD
Run the command rmdir on the folder.
Rmdir directoryname

How to delete a non empty folder


The simple rmdir does not work for folders having some content.
Use /s option to delete the folder contents along with the folder. This deletes all
subfolders recursively. C:>rmdir /S nonemptydir

Force delete a folder without confirmation


To force delete directory, without being asked for confirmation, we can use /Q switch.
rmdir /Q /S nonemptydir

We can also use ‘rd’ in place of ‘rmdir‘. Both names refer to the same command. This
command works on Windows 2000, Windows XP, Server 2003, Vista, Windows 7 and
10.

Deleting directory with white spaces in the name


Rmdir can delete files with whitespaces in the name, you just need to wrap up the
folder name in double quotes as shown in the below example.
rmdir /Q /S "folder with spaces in the name"

Networking Commands
Chapter Three

Bash Shell Scripting


Shell Scripting is an open-source computer program designed to be run by the
Unix/Linux shell. Shell Scripting is a program to write a series of commands for the
shell to execute.

How to Write Shell Script in Linux/Unix

Shell Scripts are written using text editors. On your Linux system, open a text editor
program, open a new file to begin typing a shell script or shell programming, then give
the shell permission to execute your shell script and put your script at the location from
where the shell can find it.
Let us understand the steps in creating a Shell Script:
1. Create a file using a vi editor(or any other editor). Name script file with
extension .sh
2. Start the script with #! /bin/sh
3. Write some code.
4. Save the script file as filename.sh
5. For executing the script type bash filename.sh
"#!" is an operator called shebang which directs the script to the interpreter location. So,
if we use"#! /bin/sh" the script gets directed to the bourne-shell.
 To write your first shell programming
1. First open terminal and type vi filename.sh then press enter button
2. Type “i” button on your keyboard and then type “#! /bin/sh” then press enter
3. Type your code you want
4. After that press esc button
5. Then press shift plus colon
6. Type wq and press enter button.
 To execute your shell programming
Open terminal and type bash filename.sh command. OR Another method is first to
make the file executable: chmod a+x filename.sh And now, run the file using the below
command : ./filename.sh
Example: Write Script to see current date, time, username, and current directory.

After executing this commands the output will be

Comments
Comments are a programmer’s remarks about the purpose of the code or logic. It’s a
widespread practice to add comments so that in the future, anyone can understand code
by just reading comments. Comments are part of code but ignored by the compiler. In
the bash script, any line that starts with # is considered a comment.
For example:

Here “#here is the first comment to the shell” is a comment, and when we run this script
compiler will ignore the line.
Comments can be:
1. Single Line Comment
2. Multiple Line Comment
We use ‘#’ for single line comment and: ‘content’ for multiple line comments. Check the
below command for both single and numerous comments in a bash script.

Variables
Variables are named symbols used to store values temporarily. It can be a string or
numeric value that we may use at any place within the script. You can make variables
and assign them values. Variable names should be descriptive so that you can understand
the purpose you created that variable.
We have three kinds of variables in bash scripts:
1. Special Variables:
The following are the other unique preset variables:
 $#: number of command line parameters that were passed to the script.
 $@: All the parameters sent to the script.
 $?: The end status of the last process to execute.
 $$: The Process ID of the current script.
 $USER: The user executing the script.
 $HOSTNAME: The hostname of the machine executing the script.
 $SECONDS: The number of seconds the script has been running for.
 $RANDOM: Returns a random number.
 $LINENO: Returns the current line number of the script.
Example : displaying the output using special characters.
2. User-Defined Variables:
User-defined variables are those which are set by us in our script. For example, So now
create a file variables.sh and add the below lines in it.

you can see that we used $ to reference its value.


Getting User Input
Getting user input is very crucial for making a script interactive, so for this purpose in
bash script, we use ‘read’ command.
Example :

the output for the above shell script is


Example : Adding two numbers] Write a shell script that will add two numbers, which
are supplied as command line argument and run time input?
To pass arguments from the command line, add the argument values after the file name
while executing the script. In script $1 will refer the value of agr1, and $2 will refer the
value of arg2 and so on.

Here is another example of a shell script, which takes input from the user at run time.
Then calculate the sum of given numbers and store to a variable and show the results.

Conditional Statements
Conditional statements are one of the fundamental concepts of any programming
language. You make decisions based on certain conditions fulfilled. In the bash script,
we have conditional blocks.
If Statements
In a bash script, if the condition has several forms but let’s look at the basic condition.
if Condition
then
STATEMENTS
fi
You can see if statements start with evaluating the condition and Run statements
between ‘then’ and ‘fi’, provided the “If” condition evaluates to True otherwise
statement will be ignored.

In the above example, the user will be asked to input a number, and if the number is
more than 10, you will see output ‘The variable is greater than 10.’, otherwise you will
not see anything.
If Else Statements
Now we are going to add “if else” block as well, which will execute if the condition will
be false.
if Condition
then
STATEMENTS
else
STATEMENTS
fi
So we will modify the above example.
If you execute the code and enter a number, the script will print a string based on
whether the number is greater or less/equal to 10.
IF Else IF Statements
Bash has an equivalent syntax for ‘else if’ as well.
So after modifying the above example:

Example : Write Script to find out the biggest number from given three numbers.
Numbers are supplies as command line argument, run time input?

Here is another example of a shell script, which takes input from the user at run time.
Then comparing list three of a given numbers and show the results.
Here is the output for the above shell script

Loops
Loops are used in every programming language where you need to execute the same
code repetitively. There are two types of loops in bash script while and for loops. We
will see each one by one.
While loop
While it is used when you need to repeat the line of code an unknown number of times
until it satisfies certain conditions. Here is how it is formed:
#!/bin/bash
while [CONDITION]
do
[COMMANDS]
done
The condition is evaluated before executing the commands at every iteration, and it will
keep executing until the condition evaluates to false, and the loop will be terminated.

For loop
The for loop iterates over a list of items and performs the given set of commands. The
Bash for loop takes the following form:
#!/bin/bash
for item in [LIST]
do
[COMMANDS]
done
In the example below, the loop will iterate over each item and will generate a table of
variable i.
Functions
Just like other programming languages, the bash script also has the concept of functions.
It allows the user to write a custom code block that will be required to be reused again
and again.
function FunctionName()
{
statements
}
Example : a simple function that display printout message.

Create a function with parameters


Bash can’t declare function parameter or arguments at the time of function declaration.
But you can use parameters in function by using other variable. If two values are passed
at the time of function calling then $1 and $2 variable are used for reading the values.
Create a file named ‘function|_parameter.sh’ and add the following code. Here, the
function, ‘Rectangle_Area’ will calculate the area of a rectangle based on the parameter
values.
Pass the return value from a function
Bash function can pass both numeric and string values. How you can pass a string value
from the function is shown in the following example. Create a file named,
‘function_return.sh’ and add the following code. The function, greeting() returns a string
value into the variable, val which prints later by combining with other string.
How to write and execute c program using terminal

1. write your c program code on any text editor application and save as the file .c on
your working directory.
2. to execute your c program open terminal and type gcc your_filename.c -o binary
name or executable name we want. then press enter.
3. after execute your c program you can run, To run your c program using terminal type
the command ./binary_name you have entered during execution then press enter.
Example : write a c program that calculates the factorial of a given number received
from the user or keyboard?

The output for the above c program code is


Example : write a c program that calculates the area of rectangle whose sides length and
its width received from the user or keyboard?
How to Creating a process using c program

Process creation is achieved through the fork() system call. The newly created process
is called the child process and the process that initiated it (or the process when execution
is started) is called the parent process. After the fork() system call, now we have two
processes - parent and child processes. How to differentiate them? Very simple, it is
through their return values.
Note − Usually after fork() call, the child process and the parent process would perform
different tasks. If the same task needs to be run, then for each fork() call it would run 2
power n times, where n is the number of times fork() is invoked.

Creates the child process. After this call, there are two processes, the existing one is
called the parent process and the newly created one is called the child process.
The fork() system call returns either of the three values −
 Negative value to indicate an error, i.e., unsuccessful in creating the child process.
 Returns a zero for child process.
 Returns a positive value for the parent process. This value is the process ID of the
newly created child process.

You might also like