Professional Documents
Culture Documents
GauravShardul - CO17 - Linux Lab CS505
GauravShardul - CO17 - Linux Lab CS505
TO- BY-
Proff. Garima Kumrawat Gaurav Shardul
0827CO191017
3rd Year- 5th Sem
CO4: Mapping the relationship between UNIX Kernel support for files
CO5: Understand Kernel support for process creation and termination and memory allocation
Acropolis Institute of Technology and Research, Indore
Department of Computer Science and Information Technology
LAB MANUAL
LIST OF PROGRAMS
3. Create a file called wlcc.txt with some lines and display how many lines, words and characters are present
in that file.
4 Append ten more simple lines to the wlcc.txt file created above and split the appended file into 3 parts.
What will be the names of these split files? Display the contents of each of these files. How many lines
will be there on the last file?
6 Write a Shell Script that accepts a file name, starting and ending line numbers as arguments and
displays all lines between the given line numbers.
7 Write a shell script that deletes all lines containing a specific word in one or more files
supplied as arguments to it.
8 Write a shell script that displays a list of files in current directory to which the user has read,
write and execute permissions.
9 Write a shell script that accepts one or more file name as arguments and converts all of them to
uppercase, provided they exist in the current directory.
10
write a shell script that computes the gross salary of an employee according to the following rules:
i) If basic salary is <1500 then HRA=10% of the basic and DA=90% of the basic
ii) If the basic salary is>=1500 then HRA=500/- and DA=98% of the basic
11
Write an interactive file –handling shell program. Let it offer the user the choice of copying removing,
renaming, or linking files. Once the user has made a choice, have the same program ask the user for the
necessary information, such as the file name ,new name and so on.
12
Write a shell script that accepts any number of arguments and prints them in the reverse order.
13
Write a Shell script to count the number of lines in a file that do not contain vowels.
14 Write a shell script which receives two file names as arguments. It should check whether the two file
contents are same or not. If they are same then second file should be deleted
15 Develop an interactive script that ask for a word and a file name and then tells how
many times that word occurred in the file.
17 Write a shell script that accepts two integers as its arguments and computes the value of
first number raised to the power of the second number.
18 Write a shell script that takes a command –line argument and reports on whether it is
directory, a file, or something else.
19 Develop an interactive grep script that asks for a word and a file name and then tells
how many lines contain that word.
EXPERIMENT NO: 1.
Gaurav
EXPERIMENT NO: 2.
AIM: Study & use of commands for performing arithmetic operations with unix/linux.
SOURCE CODE :
vi arithmeticOperation.sh
#!/bin/sh
# perform addition
add=`expr $a + $b`
EXPECTED OUTPUT
EXPERIMENT NO: 3.
AIM: Create a file called wlcc.txt with some lines and display how many lines, words and
characters are present in that file.
SOURCE CODE
AITR has always been at the forefront of adopting new technologies. CSIT department @
AITR has three courses those include the emerging areas as recommended by the AICTE
committee. As exponential growth in information on various platforms, future engineers
must have the expertise in core computer science as well as latest technologies. It
requires blending of emerging areas with core subject and therefore AICTE introduced as
new branch CSIT.
The courses @ CSIT incorporate both theory and practical / labs in the emerging areas of
AI, ML, IoT, Blockchain and Data Sciences as core subjects and Quantum Computing,
Virtual Reality and Cyber Security as Professional Electives. The above emerging areas
have been identified by the national level committee as part of National Perspective Plan
for Engineering Education and accepted by AICTE. AICTE has also prescribed the
model curriculum for the above emerging areas.
wc wlcc.txt
EXPECTED OUTPUT
EXPERIMENT NO: 4 .
AIM: Append ten more simple lines to the wlcc.txt file created above and split the appended file
into 3 parts. What will be the names of these split files? Display the contents of each of these
files. How many lines will be there on the last file?
SOURCE CODE
split -n 3 wlcc.txt ls
wc -l xac.txt
EXPECTED OUTPUT
EXPERIMENT NO: 5.
SOURCE CODE
touch arithmeticOperation.sh vi
arithmeticOperation.sh
EXPECTED OUTPUT
EXPERIMENT NO: 6.
AIM: Write a Shell Script that accepts a file name, starting and ending line numbers as
arguments and displays all lines between the given line numbers.
SOURCE CODE
echo "enter the filename"
read fname
cat newline
sed -n $s,$n\p $f
EXPECTED OUTPUT
touch lineReader.sh vi
lineReader.sh chmod +x
lineReader.sh
./lineReader.sh
EXPERIMENT NO: 7.
AIM: Write a shell script that deletes all lines containing a specific word in one or more files
supplied as arguments to it.
SOURCE CODE
if [ $# -lt 1 ]
then
echo “ Check the arguments once ”
exit fi
echo “Enter a word”
read word for file
in $* do
grep –iv “$word” $file | tee 1> /dev/null done
echo “ lines containing given word are deleted”
EXPERIMENT NO: 8.
AIM: Write a shell script that displays a list of files in current directory to which the user has
read, write and execute permissions.
SOURCE CODE
# Shell script to display list of file names # having
read, Write and Execute permission echo "The name of
all files having all permissions :"
# check if it is a file
if [ -f $file ] then
EXPECTED OUTPUT
EXPERIMENT NO: 9.
AIM: Write a shell script that accepts one or more file name as arguments and converts all of them to
uppercase, provided they exist in the current directory.
SOURCE CODE
touch upper.sh vi
upper.sh
# get filename
echo -n "Enter File Name : " read
fileName
# make sure file exits for reading if
[ ! -f $fileName ]
then
echo "Filename $fileName does not exists"
exit 1 fi
# convert uppercase to lowercase using tr command tr
'[A-Z]' '[a-z]' < $fileName
EXPECTED OUTPUT
AIM: write a shell script that computes the gross salary of an employee according to the following rules:
i) If basic salary is <1500 then HRA=10% of the basic and DA=90% of the basic
ii) If the basic salary is>=1500 then HRA=500/- and DA=98% of the basic
SOURCE CODE
EXPECTED OUTPUT
AIM: Write an interactive file –handling shell program. Let it offer the user the choice of copying
removing, renaming, or linking files. Once the user has made a choice, have the same program ask the user
for the necessary information, such as the file name ,new name and so on.
SOURCE CODE
vi menu.sh
while true
do
echo "*******MENU*********"
echo "
1. List of files.
2. Copying files.
3. Removing files.
4. Renaming files.
5. Linking files.
press [CTRL+C] TO
EXIT" echo "enter your
choice " read ch case "$ch"
in
1 ) echo "The list of file names."
ls -l || echo "These are file";; 2)
echo "Enter the old filename."
read ofile
echo "Enter the new file name."
read nfile
cp $ofile $nfile && echo "Copied sucessfully." || echo "Copied is not possible." ;;
3 ) echo "Enter the file name to remove."
read rfile
rm -f $rfile && echo "Successfully removed." ;;
4 ) echo "Enter the old file name." read ofile
echo "Enter the new file name."
read nfile
mv $ofile $nfile && echo "The file $ofile name renamed to $nfile." || echo "You
cann't Rename the file.".;;
5 ) echo "Enter the original filename." read
ofile
echo "Enter the new filename to link a file." read
lfile
ln $ofile $lfile && echo "Creat the linking file Sccessfully." || echo "You
cann't Linking the file.";; * ) echo "Invalid option." Echo " Enter correct
choice." esac
done
chmod +x gsalary.sh
bash gsalary.sh
EXPECTED OUTPUT
EXPERIMENT NO: 12.
AIM: Write a shell script that accepts any number of arguments and prints them in the reverse order.
SOURCE CODE
vi reverse.sh
a=$#
echo "Number of arguments are" $a
x=$* c=$a res=''
while [ 1 -le $c ]
do c=`expr $c -
1` shift $c
res=$res' '$1 set
$x done
echo Arguments in reverse order $res
EXPECTED OUTPUT
Gaurav Shardul CO17
AIM: Write a Shell script to count the number of lines in a file that do not contain vowels.
SOURCE CODE
vi linecounter.sh
#!/bin/bash echo
"Enter file name"
read file
awk '$0!~/[aeiou]/{ count++ }
END{print "The number of lines that does not contain vowels are: ",count}' $file
bash linecounter.sh
EXPECTED OUTPUT
EXPERIMENT NO: 14.
AIM: Write a shell script which receives two file names as arguments. It should check whether
the two file contents are same or not. If they are same then second file should be deleted.
SOURCE CODE
vi duplicateremover.sh
echo # compare the contents of two file , if same delete 2nd one
echo $0
echo $1
else
echo Different
rm $1
fi
EXPECTED OUTPUT
AIM: Develop an interactive script that ask for a word and a file name and then tells how many
times that word occurred in the file.
SOURCE CODE
cat > words.txt
Computer Science is the study of computers and computational systems. Unlike electrical and
computer engineers, computer scientists deal mostly with software and software systems; this
includes their theory, design, development, and application.
Principal areas of study within Computer Science include artificial intelligence, computer
systems and networks, security, database systems, human computer interaction, vision and
graphics, numerical analysis, programming languages, software engineering, bioinformatics and
theory of computing.
vi wordcounter.sh
bash wordcounter.sh
EXPECTED OUTPUT
EXPERIMENT NO: 16.
SOURCE CODE
vi stringop.sh bash
stringop.sh
EXPECTED OUTPUT
AIM: Write a shell script that accepts two integers as its arguments and computes the value of
first number raised to the power of the second number.
SOURCE CODE
vi power.sh
if [ $# -ne 2 ] then
echo "Invalid number of arguments"
exit fi
pwr=`echo $1^$2 |bc` echo "$1
raised to $2 is : $pwr"
bash power.sh 2 5
EXPECTED OUTPUT
AIM: Write a shell script that takes a command –line argument and reports on whether it is
directory, a file, or something else.
SOURCE CODE
vi filetype.sh
bash filetype.sh
mkdir Semester
bash filetype.sh
EXPECTED OUTPUT
AIM: Develop an interactive grep script that asks for a word and a file name and then tells how
many lines contain that word.
SOURCE CODE
vi wordcontainer.sh
EXPECTED OUTPUT
AIM: Write a shell script to list all of the directory files in a directory.
SOURCE CODE cd Semester touch 1st 2nd 3rd 4rth 5th 6th 7th 8th mkdir
{Attendance,Certificates} vi listdirectory.sh
bash listdirectory.sh
EXPECTED OUTPUT