Linux Lab File
Linux Lab File
Experiment 1
Objective: Write about the history, advantages and disadvantages of
Linux Operating system.
Introduction to Linux Operating System:
In the world of computing, Linux is a prominent name that represents an open-
source operating system kernel .It has a rich history and has significantly shaped
the landscape of modern computing .Linux power sava strange of devices ,from
smart phones and servers to supercomputers and embedded systems. This article
will delve into the details of what Linux is, its origins, key features, and its impact
on the technology world.
Origin of Linux:
Linux was created by Linus Torvalds in 1991 while he was a computer science
student in Finland. Torvalds developed it as a hobby project but later released it
under the GNU General Public License (GPL), which made it open-source. This
licensing allowed the code to be freely used, modified, and redistributed by anyone,
sparking a collaborative development model that encourages contributions from
individuals and organizations around the world.
Key Features of Linux:
1. Open Source: The most distinctive feature of Linux is its open-source
nature, which fosters collaboration and innovation. Anyone can access the
source code, modify it, and distribute their own versions, leading to a diverse
ecosystem of Linux distributions (distros).
2. Stability and Reliability: Linux is known for its robustness and stability. It's
widely used in server environments due to its ability to run for extended
periods without needing frequent reboots. This reliability is crucial for
critical systems.
8. Community and Support: The Linux community is vast and active. Online
forums, mailing lists, and dedicated communities offer extensive support and
troubleshooting resources for users.
3. Embedded Systems: Linux is the go-to choice for embedded systems, which
are prevalent in devices like smart TVs, routers, IoT devices, and more.
History of Linux:
The history of Linux is a fascinating tale of collaboration, innovation, and the
power of open- source development. It began as a personal project of a Finnish
student and has since grown into one of the most influential operating systems
in the world. Let's explore the detailed history of Linux, from its humble
beginnings to its current global impact.
Experiment 2
Objective: Write about installation of Linux using WSL.
Procedure of Installation:
The Windows Subsystem for Linux, WSL for short, is an environment created on
top of the Windows operating system that helps users run the Linux
environment on their Windows 10 or Windows 11.
WSL includes things like command line tools, utilities, and other applications. But,
keep in mind that you won’t get the default GNOME GUI that comes with other
methods of installing Ubuntu in Windows 10.
That is to say, you can only run Ubuntu through the Windows Terminal by using
WSL. Also, to run WSL.
To install Ubuntu using WSL follow the below steps: -
On your Windows machine, go to the Start menu search bar, type in ‘windows
features,’ and select the best match. The Windows Features will be launched.
On it, select the Turn Windows Features on or off feature. From there, scroll
down to the Windows Subsystem for Linux, select the checkbox and click on OK.
The Ubuntu environment installation will begin on your PC. When the
installation gets finished, click on Open, toopen Ubuntu on Windows.
A new window will get launched and the Ubuntu installation will begin in your
WSL. The installation might take a few minutes to complete, depending on your
internet speed. So don’t worry if it takes a while.
After everything’s set and done, it’s a good idea to do a quick update for your
Ubuntu. Run the following command and hit Enter:
# sudo apt update
Wait till the update gets completed and by the time you’re done, Ubuntu will
be successfully running on your PC.
Experiment 3
Objective: Write a program for using various commands of Linux.
Description of various Linux commands:
Linux provide a CLI (Command Line Interface) to communicate with OS, CLI is
better for task which cannot be performed with GUI.
1. pwd: Display the current working directory of the terminal.
2. /: Root directory.
3. echo: Commands that writes its arguments to standard output.
4. su: Used to switch root user (so that super user permission can be used
to execute commands).
5. su username: Used to switch to different user.
6. sudo: Execute only that command with root/super user privileges
(used with ls).
7. Clear: This command is used to clear terminal screen. Contents will
not be deleted but scrolled down.
ls: This command lists all the contents in the current working directory.
1. ls path: By specifying the path after ls, the content in that path will be
displayed.
2. ls -l: Using “l” flag, list all the content along with its owner setting.
Permission and time stamp (long format).
3. ls -a: Using “a” flag, lists all hidden contents in the specific directory.
4. ls -author: Using “-author” flag, lists the contents in the specific
directory along with its owner.
5. ls -s: Using “s” flag, sorts and lists all the contents in specified directory
by size.
6. ls *.html: Using “*” flag, lists all the contents in the directory of a
particular format.
7. ls -ls>file.txt: Using “>” flag, copies the result of ls command into a text file.
Arin Arya (0701CS221008) 7
Department of Computer Science and Engineering
grep: This command is used to search for a particular string/word in a text file.
1. grep options file1.txt: Returns results of matching string options.
2. grep -I options file1.txt: Returns the results of case insensitive strings.
3. grep -n options file1.txt: Returns the matching strings along with their line
number.
4. grep -v options file1.txt: Returns the results of lines not matching the search
string.
5. grep -c options file1.txt: Returns no. of lines in which the results match
search string.
sort: We use ‘sort’ command to sort the results of a search either alphabetically or
numerically. Files, file contents and directories can be sorted.
1. sort File1.text File2.txt: Sorts the content of both file1.txt and file2.txt.
2. sort -r file1.txt: Returns the results in reverse order.
3. sort -f file1.txt: Does case insensitive sorting.
4. sort -n file1.txt: Returns the results in numerical order.
5. grep dh file1.txt file2.txt | sort: Searches for string ‘dh’ from both files and
sorts the results.
6. grep dh file1.txt file2.txt | sort -r: Sorts the results in reverse order.
Experiment 4
Objective: Use of GNU editor:
a. Write the program to print name using GNU text editor.
b. Write the for addition using GNU text editor.
c. Write the program for bubble sort using GNU text editor.
#include <stdio.h>
int main () {
return 0;
Output:
#include <stdio.h>
int main(){
int a,b,c;
printf("Enter a number:");
scanf("%d",&a);
printf(“Enter another number :”);
scanf("%d",&b);
c=a+b;
printf("Sum of %d and %d is %d\n",a,b,c);
return 0;
}
Output:
#include<math.h>
#include<stdio.h>
int main()
{
int arr[]={12,8,5,16,11};
int
N=sizeof(arr)/sizeof(arr[0]);
printf("Unsorted array :");
for(int i=0;i<N;i++)
{
printf("%d",arr[i]);
printf(",");
}
printf("\n");
insertionsort(arr,N);
Experiment 5
Objective: Illustration of different commands of Linux for accessing data.
Experiment 7
Objective: Write a program to print name using shell programming.
Code:
#! /usr/bin/bash
Output:
Experiment 8
Objective: Write a program for addition of two numbers using shell programming.
Code:
#!/bin/bash
echo "Enter a number:"
read a
echo "Enter another number:"
read b
sum=$((a+b))
echo "$sum"
Output:
Experiment 9
Objective: Write a program to illustrate if-else using shell programming.
Code:
echo "What are you doing?"
echo "1. Btech"
echo "2. Mtech"
read idea
if test $idea -eq
1 then
echo "Good"
elif test $idea -eq 2
then
echo "Excellence"
else
echo "What now?"
fi
Output:
Experiment 9
Objective: Write a program to find sum of digits using shell programming.
Code:
#!/bin/bash
read num
sum=0
while [ $num -gt 0 ]
do
mod=$((num % 10))
sum=$((sum + mod))
num=$((num / 10))
done
Experiment 13
Objective: Write a program to reverse a number using shell programming.
Code:
#!/bin/bash
{#string}
do string2=$string2${string:
$i:1} done
echo $string2
Output:
Experiment 15
Objective:Write a program to create a calculator using shell programming.
Code:
#!bin/bash
read a
read b
i='y'
] do
echo "1.Addition"
echo "2.Subtraction"
echo "3.Multiplication"
echo "4.Division"
read op
echo
1 then sol=$
((a+b))
then sol=$
((a-b))
then sol=$
((a*b))
then sol=$
((a/b))
else
fi
read i
if [ "$i" != "y" ]
then
exit
else
echo
done
Output: