Professional Documents
Culture Documents
Practical Linux
Practical Linux
Practical Linux
AND SCIENCE
Name:Suraj Malap
Roll No:8624
Std:TYIT
Div:D
INDEX
Practical Details Date Remark
No.
PRACTICAL 1
Aim : Graphical User Interface and Command Line Interface and Processes
1. Installation of RHEL 6.X
- step 1: Install the Vmware Workstation Pro 16 Setup from the internet. Download and extract it ,
then open it and click next
- step 2 : Then Click next option and then proceed.
- step 3 : select the path where you wanted the fiel to be located.
- step 4: click next and then proceed.
- step 9 : After then , the installation process start’s , select Typical(recommanded) and then click
next.
- step 10 : select the image file that you have downloaded from the internet and click the next button.
- step 11: set the full name , username, password and set confirm password then click next.
- step 12: after that we can rename the virtual machine then click next
- step 13: Give the disk size (30GB) or less and select “strore virtual disk as a single file” then click
next
- step 14: Then click on the “Customize hardware” and set the properties.
- step 15: then Memory upto “8gb”, processor should be “2” for both the cores and set the iso file ,
which is been already downloaded from internet.
- step 16: Then set the language thet you want and click “continue”
- step 17: Then select the region and time zone , set the GUI mode and choose the disk.
- step 18: then create a linux profile and set the usernamae and password.
- step 19: after installing all the files , the GUI interface will get displayed
PRACTICAL 1
Aim : Graphical User Interface and Command Line Interface and Processes
2. Exploring the Graphical Desktop
PRACTICAL 1
Aim : Graphical User Interface and Command Line Interface and Processes
3. The Command Line Interface
i. Pwd,cd commands :
ii. Mkdir commands
iii. Rmdir commands
Cat commnads
-b ( for numbering but it does not number the space)
Now to shrink the extra space between the lines in the terminal which takes extra space we
use -s cmd :
For getting the list of files in new file
4) Managing Processes.
Shows the processes running in the background
Top:
Kill :
PRACTICAL 2
Aim : Storage Devices and Links, Backup and Repository
1. Working with Storage Devices and Links
A) How to work with storage device and links in red hat linux
● Dev is under root , however we are in student. Hence we need permission from th root using su
command
● It then ask for roots password (roots)
● Now we are in root directory(#),
● df command gives info of external devices connected to software
● When pendrive is attached space is created in dev directory.
● Now select 1) virtual machine 2)red hat linux.(second one ,)
● Now again type df now new line is generated at the end , its our pendrive stored in devfolder.sda1
● Now we create a folder using mkdir /mnt/test123
● Now we mount using mount -t vfat /dev/sda1 /mnt/test123 (sda can change checkurs always)
● Now we can find this data in test123 so we go in this folder using cd /mnt/test123
● Now ls the content of test123
● Now if we remove the pendrive and reattach it then we need to use su command again, now if we df
we can see all files(last one is sdb1)
B) LINKS(soft/symbolic link)
PRACTICAL 2
Step2:
after installing yum install the rpm
“ yum install rpm-build”
Step 3:
Run the command “ yum repolist all ”
Stepp 4:
After that change the directory to repos.d
“ cd /etc/yum.repos.d”
PRACTICAL 3c
Attach pendrive
fdisk -l : to check the connected pendrive (gives location )
Step 2 :
Type the Command :
fdisk –l /dev/sda1
To check partition
-fdisk -l /dev/sda1
fdisk -c /dev/sda1
Step 3 :
For manual press m which’ll open up the manual for fdisk.
Step 4:
Press n to add a new partition and p to print the partition table, give the value of 19865252 which is
the default size.
PRACTICAL 4
Giving password
-u (unlock)
ABSOLUTE PERMISSION
To give execute permission to user in file 1
PRACTICAL 5
iptables -L -v
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -m multiport -p tcp --port 21,80 -j ACCEPT
OUTPUT :
PRACTICAL 6a
Step 1:
Use the commad “httpd” for Configuring Apache
If not available then install the httpd from yum.
Step 2:
To restart the httpd
“service httpd restart”
Step 3:
To chack the configuration
“chkconfig httpd list”
Step 4:
To create file
“cd /var/www/html
Step 5:
After that open the gedit editor with example.html
To create html file.
Step 6:
Write the html code in the file.
Step 7:
After that save and close the html file and restart it by using command :
“service httpd restart”
Step 8:
Check the file location in var->www->html and open it .
Step 9:
run on the browser : http://locallost/example.html\
Step 10 :
if the network is close then go in setting then turned on the wired .
PRACTICAL 6b
Step 1 :
Create shell script by gedit :
gedit example.sh
Step 2:
Write the script in example.sh file
Shell script :
#!/bin/bash
# monitoring process httpd
COUNTER=0
while ps aux | grep httpd | grep -v grep > /dev/null
do
COUNTER=$((COUNTER+1))
sleep 1
echo COUNTER is $COUNTER
done
logger HTTPMONITOR: httpd stopped at 'date'
service httpd start
mail -s Apache server just stopped root
PRACTICAL 6c
Step 1:
Open the vi editor
Create “vi example2.sh”
Shell Script :
echo 'Enter the name of an RPM of the file that you want to check or install or delete'
read RPM
echo 'select a task form the menu'
select TASK in 'check from which RPM this file comes' 'check if this RPM is installed' 'Remove this
RPM'
do
case $REPLY in
1) rpm -qf $RPM*;;
2) rpm -qa | grep $RPM*;;
3) rpm -ivh $RPM*;;
4) rpm -e $RPM*;;
*) echo error && exit 1;;
esac
if [ -n "TASK" ]
then
echo you have selected TASK $TASK
break
else
echo invalid choice
fi
done
Step 2:
After saving the changes run the .sh file
Step 3:
multiple options will appear, then choose 2
Practical 7a
Aim: Working with shell scripting.
a)Write a shell script to the user name and age from input and print the year when the user
would become 50 years of age.
Shell Script :
#!/bin/bash
# Read user name
echo "Enter your name:"
read name
# Read user age
echo "Enter your age:"
read age
# Calculate the year when the user will turn 50
year_when_50=$((50 - age + $(date +%Y)))
# Print result
echo "$name will turn 50 years old in the year $year_when_50"
OUTPUT:
Practical 7b
Aim: Working with shell scripting.
b) Write a shell script to create a directory called demo1 inside /tmp and three blank file
file1,file2,file3 inside it and list them.
Shell Script:
#!/bin/bash
# create the demo1 directory inside /tmp
mkdir /tmp/demo1
# change to demo1 directory
cd /tmp/demo1
# create three blank files
touch file1 file2 file3
# list the files in demo1 directory
ls -l
OUTPUT:
Practical 7c
Aim: Working with shell scripting.
c). Write the shell script to delete the file3 created in the question 2 above and also print the
time after deletion of the file.
Shell Script:
#!/bin/bash
rm file3
echo "File3 has been deleted."
echo "Time after deletion: $(date)"
OUTPUT :
Practical 7d
Aim: Working with shell scripting.
d). Writing Shell Scripts for following: Find Factorial Number, Palindrome
Number,Palindrome String,Reverse Number, Armstrong Number,Count of Digit.
Shell Script :
#!/bin/bash
read -p "Enter a number: " num
fact=1
for((i=1;i<=num;i++))
do
fact=$((fact * i))
done
echo "The factorial of $num is $fact"
OUTPUT :
2. Palindrome Number
Shell Script :
#!/bin/bash
read -p "Enter a number: " num
original=$num
reverse=0
while [ $num -gt 0 ]
do
rem=$((num % 10))
reverse=$((reverse * 10 + rem))
num=$((num / 10))
done
if [ $original -eq $reverse ]
then
echo "$original is a palindrome number"
else
echo "$original is not a palindrome number"
fi
OUTPUT :
3. Palindrome String:
Shell Script :
#!/bin/bash
read -p "Enter a string: " str
if [ "$str" == "$(echo $str | rev)" ]
then
echo "$str is a palindrome string"
else
echo "$str is not a palindrome string"
fi
OUTPUT :
4. Reverse Number:
Shell Script :
#!/bin/bash
read -p "Enter a number: " num
reverse=0
while [ $num -gt 0 ]
do
rem=$((num % 10))
reverse=$((reverse * 10 + rem))
num=$((num / 10))
done
echo "The reverse of the number is $reverse"
OUTPUT :
5. Armstrong Number:
Script Shell :
#!/bin/bash
read -p "Enter a number: " num
original=$num
sum=0
while [ $num -gt 0 ]
do
rem=$((num % 10))
sum=$((sum + rem ** 3))
num=$((num / 10))
done
if [ $original -eq $sum ]
then
echo "$original is an Armstrong number"
else
echo "$original is not an Armstrong number"
fi
OUTPUT :
6. Count of Digits:
Script Shell :
#!/bin/bash
read -p "Enter a number: " num
count=0
while [ $num -gt 0 ]
do
count=$((count + 1))
num=$((num / 10))
done
echo "The number of digits in the number is $count"
OUTPUT :
Practical 8a
Aim: Working with advance shell script.
1. Write a shell script to perform numeric comparison in Linux.
Shell Script:
#!/bin/bash
# Script to perform numeric comparison in Linux
# Take two numbers as input
read -p "Enter first number: " num1
read -p "Enter second number: " num2
# Check if num1 is equal to num2
if [ $num1 -eq $num2 ]; then
echo "$num1 is equal to $num2"
OUTPUT :
Practical 8b
Aim: Working with advance shell script.
2. Write a shell script to find out unique word in a file and also count the occurrence of
each of the word.
Shell Script :
Here
l corresponds to line
w corresponds to word
c corresponds to character
Practical 8c
Aim: Working with advance shell script.
3.Write a shell script to validate password strength .
Shell Script :
#!/bin/bash
exit 0
OUTPUT
Practical 8d
Aim: Working with advance shell script.
4.Write a shell script to get the current date time username and working directory.
Shell Script :
#!/bin/bash
OUTPUT
Practical 8e
Aim: Working with advance shell script.
5. Write a shell script that adds two numbers if provided as the command line argument and
if the two numbers are not entered it outputs error message
Shell Script :
#!/bin/bash
if [ $# -eq 2 ]; then
num1=$1
num2=$2
result=$((num1 + num2))
echo "The result is: $result"
else
echo "Error: Please provide two numbers as command line arguments."
fi
OUTPUT
PRACTICAL 8a
Shell Script :
else
echo "2nd number is greater"
fi
vi practical.sh
Bash practical.sh