21EC3A1 - Lab Experiments
21EC3A1 - Lab Experiments
Lab Experiments
After finishing each session, write a report that explains the result of each step
and answer any questions asked.
Note: Make use of the following link/s to know more about the shell
programming
Ref:
1. Shell Programming: http://www.freeos.com/guides/lsst/ch02.html
2. Python Reference: https://docs.python.org/3/tutorial/index.html
3. Perl: https://perldoc.perl.org/
Rubrics:
1. Execution of the programs and commands – 5 Marks
2. Submission of the Record book with Observations – 5 Marks
3. Attendance – 5 Marks
4. Answering VIVA Questions – 5 Marks
Each Week they are going to score 20 points. If they are absent they lose all
those marks of that week.
Have the Print out of the students batch wise to evaluate them.
5. Use all of the date arguments one by one and write a brief
explanation of the results.
Exp 2 SESSION I
Session 2
1. Log into the system.
2. Recursively list the directories under your home directory (the
ones created in Session I).
3. Move to the UNIX directory.
4. Check your current directory.
5. Using vi, create a file named hw4 that contains short answers to
at least five review questions in this chapter.
6. Save the file (it should be saved under the UNIX directory).
7. Move to your home directory.
8. Print the content of hw4 from your home directory.
9 Make a copy of hw4 and call it hw4.bk. Store it under the same
directory where hw4 is stored.
10. From your home directory, check to see if both files (hw4 and
hw4.bk) exist.
11. Move to the UNIx directory.
12. Check your current working directory.
13. Make a hard link to the hw4 file. The link should be under the
UNIX subdirectory and be called hw4HL.
14. Make a soft link to hw4 called hwa SL and store it under the
UNIX directory.
15. Check the inode of hw4, hw4.bk, hw4HL, and hw4SL. Are all the
same? Are all different? Explain how you determined the answer.
15 Use the is command to find the file types of hw4, hwa. bk,
hw4HL, and hw4 SL. Explain your observation.
17 Log out of the system.
Exp 3 SESSION 3:
1. Log into the system.
Create a backup directory in your home directory called backups.
Use the find command to find the pathnames of all of the files
(hw4, hw4.bk, hwds and hw4SL) that you created in Session IL. All
of them should be found using only o
find command. The command must also copy all of them to the
backups directorv
4. Check the number of links and inode number of hw4, hw4. bk,
hw3HL, and hw4SL. Make note of the results.
5. Delete the original hw4 file without moving from your home
directory.
6. Check the existence of hw4, hw4.bk, hw4HL, and hw4SL.
7. Check the contents of hw4, hw4.bk, hw4HL, and hw4SL.
Electronics and Communication Engineering 3rd Sem
Ability Enhancement Course – Unix and Shell Scripting
Session IV
1. Log into the system.
2. Use wildcards to display all of the files you have created under
the HWs directory
without moving from your home directory.
Rename hw4.bk to hw4.bak.
4. Create a short friendly letter, called friend. 1, using vi and store it
under the
friendly directory.
Create a short formal letter, called formal.1, using vi and store it
under the
formal directory. Give a title to formal.1 letter.
6. Copy the file formal.1 and call the new copy formal .2.
7. Change only the title of formal .2 (using vi) and store it.
8. Using wildcards, print the contents of formal.1 and formal.2.
9. Make a directory called busLetters under your home directory.
10. Move the formal directory (with all of its contents) under the
busLetters directory.
11. Make a recursive list of your directory structure.
12. Draw the new directory structure on paper.
13. Log out of the system.
Exp 4 1)Write a shell script that accept a file name number of lines as
arguments and display all the lines from starting number?
THEORY:
Cat: cat command is used to create the file
Syntax: cat > file name for creation
Syntax: cat file name for displaying a file
man ls > lsman (it runs man command and dumps it in lsman file
name)
Read file
Echo -n “Enter number of lines to read: “
Read lines
Cat $file | head -n $lines
^z (Ctrl+z) # closes the file
$ chmod u+x readnlines.sh
$ ./readnlines.sh (Run the script)
2. Write another shell file to read from the bottom of the file (use
tail -n $lines)
3. Write a shell script which will give 10 random numbers between
300 and 1000.
cat random.sh
#!/bin/bash
echo -n "Enter the Min number > 100:"
#MIN=200
read MIN
echo -n "Enter the Max number < 1000:"
#MAX=500
read MAX
let “scope = $MAX - $MIN”
if [ “$scope” -le “0” ]; then
echo “Error - MAX is less than MIN!”
fi
for i in `seq 1 10`
do
let result=”$RANDOM % $scope + $MIN”
echo “A random number between $MIN and $MAX is $result”
done
VIVA QUESTIONS
1.what is a file system?
2.why we are using head command?
3.which command is used to create file?
4.why we are using chmod?
5.which permissions are provided to files?
Exp 5 3)Write a shell script that displays a list of all the files in the current
directory to which the user has read, write and execute
permissions?
THEORY:
Cd: The cd command can be used for to change the directory that
means we can change the existing directory.
Electronics and Communication Engineering 3rd Sem
Ability Enhancement Course – Unix and Shell Scripting
VIVA QUESTIONS:
1.what is a directory?
2.which command is used to create directory?
3.what is the purpose of wc cmd?
Electronics and Communication Engineering 3rd Sem
Ability Enhancement Course – Unix and Shell Scripting
Source code:
i=7
c=24+8j
f=701
s='HELLO EVERYONE!!\nThis is john\'s python programming..'
# NOTE: boolean has truth values that are case sensitive Ex: True (T
is caps!)
b= True
print("the value of c is:",i,'\nits type is:',type(i))
print("the value of c is:",f,'\nits type is:',type(f))
print("the value of c is:",c,'\nits type is:',type(c))
print("the value of c is:",s,'\nits type is:',type(s))
rint("the value of c is:",b,'\nits type is:',type(b))
print('NOTE: boolean has truth values that are case sensitive Ex:
True (T is caps!)')
b) Write a program to perform different arithematic operations
on numbers in python
Source code:
a=10; b=3
print("addition of a:",a,"&b:",b,"is:",a+b)
print("substraction of a:",a,"&b:",b,"is:",a-b)
print("multiplication of a:",a,"&b:",b,"is:",a*b)
print("division of a:",a,"&b:",b,"is:",a/b)
print("floor divison of a:",a,"&b:",b,"is:",a//b)
print("moduli of a:",a,"&b:",b,"is:",a%b)
print("exponent of a:",a,"&b:",b,"is:",a**b)
Exp 7 1. Write a Python program to guess a number between 1 to 9.
Note : User is prompted to enter a guess. If the user guesses wrong
then
the prompt appears again until the guess is correct, on successful
guess,
user will get a "Well guessed!" message, and the program will exit.
Expected Output : 0 1 2 4 5
Hint: have a for loop and visit each ele and multiply the result with
each ele.
Hint
Given dict = {‘0’:1, ‘1’:2, ‘2’:3}
Input:
Enter value to check: 2
Expected output
Result: True
Hint
dict = {0:”Value 1″, 1:”Value 2″}
Expected output
Value of key 0 is Value 1
Value of key 1 is Value 2
Hint
Given
d = {‘key 1’: 2, ‘key 2’: 3, ‘key 3’: 4}
Expected output
Ascending: [(‘key 1’, 2), (‘key 2’, 3), (‘key 3’, 4)]
Descending: [(‘key 3’, 4), (‘key 2’, 3), (‘key 1’, 2)]
Hint
dict1 = {‘key 1’: 200, ‘key 2’: 300}
Expected output
Result: 500
Hint
dict1 = {‘key 1’: 200, ‘key 2’: 300}
Expected output
Max: 300
Min: 200
Hint
Given num = [2,3,4,5,2,6,3,2]
Expected output
Result: [2, 3, 4, 5, 6]
Source code:
while(1):
print("1.CELSIUS TO FAHRENHEIT\n2.FAHRENHEIT TO
CELSIUS\n3.EXIT\n")
choice=input("ENTER YOUR CHOICE:")
ch=int(choice)
if(ch==1):
c=int(input("ENTER TEMPERATURE IN CELSIUS:"))
f=((9*c)/5)+32
print("converted temperature is:",f)
elif(ch==2):
f=int(input("ENTER TEMPERATURE IN FAHRENHEIT:"))
c=((f-32)/9)*5
print("converted temperature is:",c)
elif(ch==3):
exit()
Electronics and Communication Engineering 3rd Sem
Ability Enhancement Course – Unix and Shell Scripting
else:
print("wrong choice")
Write a script named copyfile.py. This script should prompt the user
for the
names of two text files. The contents of the first
the second file.
Source code:
Note: create a text file as “input.txt” and write some date in it. This
will be used in the program.
with open("input.txt") as input:
with open("output.txt","w") as
for line in input: output.write(line)
print("JOB DONE!!")
Exp 12 Write a program that inputs a text file. The program should print all
of the
Electronics and Communication Engineering 3rd Sem
Ability Enhancement Course – Unix and Shell Scripting