0% found this document useful (0 votes)
0 views30 pages

Linux Lab File

The document provides an overview of the Linux operating system, detailing its history, advantages, and disadvantages. It covers key features such as open-source nature, stability, customizability, and security, along with its impact on technology, including server infrastructure and embedded systems. Additionally, it includes instructions for installing Linux using Windows Subsystem for Linux (WSL) and examples of various Linux commands.

Uploaded by

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

Linux Lab File

The document provides an overview of the Linux operating system, detailing its history, advantages, and disadvantages. It covers key features such as open-source nature, stability, customizability, and security, along with its impact on technology, including server infrastructure and embedded systems. Additionally, it includes instructions for installing Linux using Windows Subsystem for Linux (WSL) and examples of various Linux commands.

Uploaded by

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

Department of Computer Science and Engineering

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.

3. Customizability: Linux provides a high degree of customization. Users can


select from various desktop environments, package managers, and software
components to tailor their Linux experience to their preferences

4. Security: Linux has a strong security reputation. Its multi-user


architecture, access control mechanisms, and active community of
developers working on security patches contribute to its resilience against
threats.
Arin Arya (0701CS221008) 1
Department of Computer Science and Engineering
5. Performance: Linux is highly efficient, making it an excellent choice for
resource-intensive tasks, including scientific computing, web hosting, and
cloud services.

6. Scalability:Linux can scale from embedded devices with limited resources to


supercomputers. Its adaptability to different hardware and workloads makes
it versatile.

7. Cost-Efficiency: Being open source, Linux is cost-efficient for businesses.


They don't have to pay licensing fees, and the vast array of free and open-
source software available for Linux reduces operational costs.

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.

Impact and Adoption:


Linux's impact on the technology world is undeniable. It's the foundation for
numerous operating systems and platforms:
1. Server Infrastructure: Linux dominates the server market. It powers a
significant portion of web servers, cloud infrastructure, and data centers
worldwide.

2. Android: The Android operating system, used on the majority of smart


phones globally, is based on the Linux kernel. This has made Linux one of
the most widely used operating systems on the planet.

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.

4. Scientific Research: Linux is widely used in scientific research due to


its performance and customization capabilities.

5. Development and Education: Many developers prefer Linux for software


development, and it's commonly used in educational settings to teach
computer science and programming.

Arin Arya (0701CS221008) 2


Department of Computer Science and Engineering

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.

Birth of the Idea:


The Linux story begins in 1991 when a young computer science student named Linus
Torvalds started working on a new operating system kernel. At the time, he was
using a version of the MINIX operating system, but he found it limited and
wanted to create something more capable and free. Inspired by the Unix operating
system, Linux set out to build a Unix-like kernel that would run on his personal
computer.

Licensing and Open-Source Movement:


Linux was released under the GNU General Public License (GPL), which ensured that
the source code remained open and accessible. This licensing choice was crucial
to the widespread adoption of Linux. It allowed anyone to use, modify, and
distribute Linux freely, leading to a large and vibrant developer community.

Arin Arya (0701CS221008) 3


Department of Computer Science and Engineering

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.

Arin Arya (0701CS221008) 4


Department of Computer Science and Engineering
Windows will begin installing the WSL files, so give it a few minutes. After the
installation is finished, reboot your PC or let it reboot by itself if you have the
option.
After the reboot, launch the Command prompt. Go to the Start menu search bar,
type in ‘cmd,’ and select the best match. In the Command prompt, type bash and
hit Enter.
Now you need to install Ubuntu on Windows, so head to https://aka.ms/wslstore.
As soon as you enter the website URL in the address bar, Microsoft Store will be
launched on your PC.
There, you’ll see a host of different Linux distributions that you are free to run
side-by-side on your Windows operating system. Click on Ubuntu. From
there, click on Get to download Ubuntu on Windows.

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.

Arin Arya (0701CS221008) 5


Department of Computer Science and Engineering

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.

Arin Arya (0701CS221008) 6


Department of Computer Science and Engineering

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

cd: Change the directory.


1. cd ~: This command also changes the directory to home directory.
2. cd/: Changes the directory to root directory.
3. cd. : Change the directory to its parent directory.
4. cd ‘xx yy’: If there is space in folder name (e.g. program file).

Arin Arya (0701CS221008) 8


Department of Computer Science and Engineering
cat: This command is used to display the contents of text file and concatenate
several files into one.
1. cat -b: This is used to add line numbers to non-blank lines.
2. cat -n: This is used to add line numbers to all lines.
3. cat -s: This is used to squeeze blank lines into one line.
4. cat -E: Shows $ at the end of line.
5. cat >file.txt: The ‘>’ flag can be used to create a new file and enter text
contents from terminal.
6. cat file1.txt>>file2.txt: The ‘>>’ flag can be used to append text contents to
an existing file from the terminal.

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.

Arin Arya (0701CS221008) 9


Department of Computer Science and Engineering
cp: This command is used to copy files and directories.
1. cp -I: Enters interactive mode; CLI asks before over writing file.
2. cp -n: Does not overwrite the file.
3. cp -u: Updates the destination file only when source file is different
from destination file (runs when names of 2 files are different).
4. cp -R: Recursive copy for copying directories; copies even hidden files.
5. cp -v: Verbose; prints informative messages.

mv: This command is used to move files and directories.


1. mv -I: Enters interactive mode; CLI ask before overwriting file.
2. mv -u: Updates the destination file only when source file is different
from destination file.
3. mv -v: Verbose; Prints source and destination files.

Arin Arya (0701CS231035) 10


Department of Computer Science and Engineering
mkdir: This command is used to create a new directory.
1. mkdir -p: Creates both a new parent directory and a sub directory.
2. mkdir -parents This is also used for the same process.
3. mkdir -p file1/ {f2, f3, f4}: This is used to create multiple sub-
directories inside the new parent directory.
rmdir: This command is used to remove the specific directory (empty).
1. rmdir -p: Removes both parent and child directory.
2. rmdir -pv: Removes all parent and sub-directories along with the verbose.
3. rm-r: Removes even non empty directories.
4. rm-rp: Removes non empty directories including parent and sub directories.

Arin Arya (0701CS231035) 11


Department of Computer Science and Engineering

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.

a. Write the program to print name using GNU text editor.

#include <stdio.h>

int main () {

printf("Arin Arya (0701CS221008)\n ");

return 0;

Output:

Arin Arya (0701CS231035) 12


Department of Computer Science and Engineering

b. Write the for addition using GNU text editor.

#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:

Arin Arya (0701CS231035) 13


Department of Computer Science and Engineering
c. Write the program for bubble sort using GNU text editor.

#include<math.h>
#include<stdio.h>

void insertionsort(int arr[],int N)


{
for(int i=1;i<N;i++) {
int key=arr[i];
int j=i-1;
while(j>=0 && arr[j]>key) {
arr[j+1]=a
rr[j]; j=j-1;
}
arr[j+1]=key;
}
}

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);

Arin Arya (0701CS231035) 14


Department of Computer Science and Engineering

printf("Sorted Array :");


for(int i=0;i<N;i++)
{
printf("%d",arr[i]);
printf(",");
}
printf("\n");
return 0;
}
Output:

Arin Arya (0701CS231035) 15


Department of Computer Science and Engineering

Experiment 5
Objective: Illustration of different commands of Linux for accessing data.

vi program5then write names in any combination up to 20-25 names.


1. Write a command to print the names containing ‘a.’
cat program5 | grep a
2. Write a command to find names of student starting with ‘a.’
cat program5 | grep a$
3. Write a command to find names of student starting with ‘a.’
cat program5 | grep ^a
4. Write a command to find names containing any number of ‘b.’
cat program5 | grep b
5. Write a command to find names of student with word a in both lower and
upper cases.
cat program5 | grep -i a
6. Write a command to find names that do not contain ‘a.’
cat program5 | grep -v a
7. Write a command to find names that don’t contain ‘a’ (both in lower and
upper cases).
cat program5 | grep -v -i a
8. Write a command to find the count of matching number of lines.
cat program5 | grep -c a
9. Write a command to find count of names containing ‘a’ (upper and lower).
cat program5 | grep -c -i a
10.Write a command to sort data in alphabetical order.
cat program5 | sort program5
11.Write a command to sort data in reverse order.
cat program5 | sort -r program5
12.Write a command to sort data in reverse order that do not contain ‘a.’
cat program5 | grep -v a | sort -r
13.Write a command to sort data in reverse order containing ‘a.’
cat program5 | grep -i a | sort -r

Arin Arya (0701CS231035) 16


Department of Computer Science and Engineering

Arin Arya (0701CS231035) 17


Department of Computer Science and Engineering

Arin Arya (0701CS231035) 18


Department of Computer Science and Engineering

Arin Arya (0701CS231035) 19


Department of Computer Science and Engineering

Arin Arya (0701CS231035) 20


Department of Computer Science and Engineering

Experiment 7
Objective: Write a program to print name using shell programming.

Code:
#! /usr/bin/bash

echo -e "Hello myself arin"

Output:

Arin Arya (0701CS231035) 21


Department of Computer Science and Engineering

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:

Arin Arya (0701CS231035) 22


Department of Computer Science and Engineering

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

Arin Arya (0701CS231035) 23


Department of Computer Science and Engineering

Output:

Arin Arya (0701CS231035) 24


Department of Computer Science and Engineering

Experiment 9
Objective: Write a program to find sum of digits using shell programming.

Code:

#!/bin/bash

echo "Enter a number :"

read num

sum=0
while [ $num -gt 0 ]

do

mod=$((num % 10))
sum=$((sum + mod))
num=$((num / 10))
done

echo "Your answer is : $sum "


Output:

Arin Arya (0701CS231035) 25


Department of Computer Science and Engineering

Experiment 13
Objective: Write a program to reverse a number using shell programming.

Code:
#!/bin/bash

echo "Enter a string :"

read string len=$

{#string}

for (( i = len - 1 ; i >= 0 ; i-- ))

do string2=$string2${string:

$i:1} done

echo $string2

Output:

Arin Arya (0701CS231035) 26


Department of Computer Science and Engineering

Experiment 15
Objective:Write a program to create a calculator using shell programming.

Code:
#!bin/bash

echo "Enter a number :"

read a

echo "Enter another number :"

read b

i='y'

while [ "$i" = "y"

] do

echo "Give your operation :"

echo "1.Addition"

echo "2.Subtraction"

echo "3.Multiplication"

echo "4.Division"

echo "Enter your operation number:"

read op

echo

if test $op -eq

1 then sol=$

((a+b))

Arin Arya (0701CS231035) 27


Department of Computer Science and Engineering
echo "Your answer is $sol"

elif test $op -eq 2

then sol=$

((a-b))

echo "Your answer is $sol"

elif test $op -eq 3

then sol=$

((a*b))

echo "Your answer is $sol"

elif test $op -eq 4

then sol=$

((a/b))

echo "Your answer is $sol"

else

echo "Invalid operation given"

fi

echo "Do you want to continue ? (y/n)"

read i

if [ "$i" != "y" ]

then

exit

else

echo

Arin Arya (0701CS231035) 28


Department of Computer Science and Engineering
fi

done

Output:

Arin Arya (0701CS231035) 29


Department of Computer Science and Engineering

Arin Arya (0701CS231035) 30

You might also like