Linux
Linux
BACHELOR OF COMPUTER
APPLICATION LINUX LAB PRACTICAL
FILE
2. 4
Lab Assignment 2 09-03-2023
3. Lab Assignment 3 16-03-23 5
5. 10
Lab Assignment 5 06-03-23
6. Lab Assignment 6 13-04-23
12
7. 14
Lab Assignment 7 20-04-23
8. 18
Lab Assignment 8 27-04-23
9. 22
Lab Assignment 9 04-05-23
10. 25
Write a shell script to print the table of 5. 11-05-23
11. Write a shell script to calculate the area 26
and perimeter of the rectangle, when
11-05-23
length and breadth of rectangle is given
by user.
12. Write a shell script to calculate the sum 27
of digits of a three-digit number. 11-05-23
13. Write a shell script which accepts 3 28
arguments a, b, c and prints the value 11-05-23
of a*20-b*2+c to standard output.
14. Write a shell script to print if the number 29
is odd or even accepted from user. 11-05-23
15. Write a shell script which takes a file 30
name along the command line and prints 11-05-23
its size.
16. 31
Write a menu driven shell script
which has the following options for 11-05-23
user to display and run according to
selection.
17. Write a shell script to print all 33
18-05-23
prime numbers from 1 to 100.
18. Write a shell script to find the factorial 34
value of a number entered by the user. 18-05-23
19. Write a shell script to print
18-05-23
35
Fibonacci series.
20. Write a shell script that computes the 36
gross salary of a employee according to 18-05-23
the some rules.
21. Write a shell script to print the sum of 10 37
numbers accepted from user and find the 18-05-23
average.
22. Write a shell script to calculate the grade 38
of student based on some conditions. 18-05-23
Take 5 subjects into consideration.
23. Write a shell script to find the simple 40
interest.
24. Write a shell script to print the weekdays 41
according to the number entered by the 18-05-23
user from 1 to 7 using cases.
25. Write a shell script to display “Good 42
Morning /Afternoon/ Evening/ Night”. 20-05-23
Take time from user and print as
banner.
26. Write a shell script to check, if string 43
entered by the user starts from a vowel or 20-05-23
consonant.
27. Write a shell script to accept 3 numbers 44
from user and find the largest 20-05-23
among them.
28. Write a shell script to print # pattern in 45
the given format. 21-05-23
29. Write a shell script to accept 10 46
21-05-23
numbers from user and sort them in
reverse order.
30. Write a shell script to search for the word 47
“exam” in a file and display total number 21-05-23
of matching word.
31. Write a script to convert seconds 48
accepted from user to hours and minutes. 21-05-23
32. Write a shell script to check whether a 49
string is palindrome or not. 21-05-23
33. Write a shell script to count the 50
21-05-23
number of ordinary files in root
directory.
34. Write a shell script to do following: 51
i)Print all files that have read permissions
21-05-23
only. ii) Print the number of users that are
logged in.
35. Write a shell script to create a directory 52
named BCA6E and then create a file
named p1 within BCA6E.Also display 25-05-23
the present directory as well as the list of
files containing BCA6E.
36. Write a shell script to accept a 53
filename, check if it is regular and show
25-05-23
its
contents. Also display the total number of
words in that file.
37. Write a shell script to accept a dirname, 54
check if it is directory & display its 25-05-23
content.
38. Write a shell script to accept a filename, 55
and create a copy of it named as 25-05-23
“newfile” in the same directory.
39. Write a shell script to accept an extension 56
name such as txt and display all the
filenames with this extension if exist, 25-05-23
otherwise display some appropriate
message.
40. Write a shell script to display “Good 57
Morning”, “Good afternoon”, and “Good 25-05-23
evening” depending on the hour.
41. Write a shell script to create a file named 58
student.txt containing the data provided
25-05-23
(Roll, Name and Marks) and then execute
the given operations.
42. Write a shell script to calculate the 59
maximum of three integers using
command line argument. The script also
25-05-23
displays the value of the special
variables/positional parameters such as
$0, $1 to $9, $$, $#, $*, $@ and $!.
Lab Assignment 1
2. Write a command to display the current user which we are currently using.
Command: whoami
Output:
3. Write a command to list the directories and files in current working directory.
Command: ls
Output:
+%D +%T
+%y-%m-%d
+%y/%m/%d
+%A %B %D %T %Y
2. Write the command to show to only show the memory in different measurement units.
Command: free -unitspecifier ( -b for byte -g for gigabyte -m for Megabyte)
Output:
-b
-k
-m
-g
5. Write a command to display the list of all the files and directory in the present
directory.
Command: ls
Output:
15. Write a command to show a long list of all the file and folders of the present working
directory.
Command: ls -l
Output:
17. Write a command to stay where you are and display the contents of /bin and /sbin.
Command: ls /bin /sbin
Output:
18. Write a command to display list of all files in human readable format.
Command: ls -ah
Output:
19. Write a command to display files in /boot in long format and human readable format.
Command: ls /boot -lh
Output:
21. Write a command to change to the /etc directory, stay here and create a directory newdir
in your home directory.
Command: cd /etc; mkdir ~newdir Output:
22. Write a command to remove the test dir.
5. Write a command to create a dir ~/test_backup and copy all files of ~/touched in the
~/test_backup
Command: mkdir ~/testbackup ; cp -r ~/touched ~/testbackup/ Output:
6. Write a command to delete testbackup and all its contents
3. Issue the following two commands, and look at the first character of each output Line.
Command: ls -l /dev/sd* /dev/hd*
ls -l /dev/tty* /dev/input/mou*
Output:
5. Are there any files in /etc/skel/ ? Check also for hidden files.
Command: ls -al /etc/skel/
Output:
7. Can you enter the /root directory ? Are there (hidden) files ?
Command: cd /root; ls -al
Output:
3. Use cat to create a file named count.txt that looks like this:
Command: cat > count.txt
Output:
5. Display catcnt.txt, but with all lines in reverse order (the last line first).
Command:
Output:
9. Use cat to create a file named tailing.txt that contains the contents of tailing.txt
followed by the contents of /etc/passwd.
Command:cat /etc/passwd >> tailing.txt
Output:
5. List (with ls) all files starting with file and ending in a number. ls
file*[0-9]
Output:
6. List (with ls) all files starting with file and ending with a letter ls
file*[a-z]
Output:
8. List (with ls) all files starting with File and having a digit as fifth character and nothing else.
ls File[0-9]
Output:
9. List (with ls) all files starting with a letter and ending in a number. ls
[a-z]*[0-9]
Output:
10. List (with ls) all files that have exactly five characters. ls
?????
Output:
11. List (with ls) all files that start with f or F and end with 3 or A. ls
[fF]*[3A]
Output:
12. List (with ls) all files that start with f have i or R as second character and end in a
number.
ls f[iR]*[0-
9] Output:
13. List all files that do not start with the letter F. ls
[!F]*
17. Make a list of all filenames in /etc that contain the string conf in their filename.
Command: ls /etc | grep conf
Output:
18. Make a sorted list of all files in /etc that contain the case insensitive string conf in their
filename.
Command: ls /etc | grep -i conf | sort Output:
19. Write a line that receives a text file, and outputs all words on a separate line.
$ cat text2
it is very cold today without the sun
Command: $ cat text2 | tr ‘ ‘ ‘\n’
Output:
Answer:
#!/bin/bash
Answer:
#!/bin/bash
Output:
Output:
Output:
case $choice in
1) option1 ;;
2) option2 ;;
3) option3 ;;
4) echo "Exiting..."; exit ;;
*) echo "Invalid choice. Please enter a valid option." ;; esac
echo
done
return 0
}
if [ $? -eq 0 ]; then
echo $num
fi
done
Output:
Answer:
#!/bin/bash
factorial() {
number=$1
fact=1
for ((i=2; i<=number; i++)); do
fact=$((fact * i))
done echo
$fact
}
result=$(factorial $num)
echo "The factorial of $num is: $result"
Output:
a=0
b=1
hra=$((basic_salary * 10 / 100))
da=$((basic_salary * 15 / 100)) gross_salary=$
((basic_salary + hra + da))
average=$((sum / 10)).$(printf "%02d" $(( (sum * 100 / 10) % 100 ))) echo
"Sum: $sum"
echo "Average: $average"
Output:
grade=""
case $number in
1)
echo "Monday"
;;
2)
echo "Tuesday"
;;
3)
echo "Wednesday"
;;
4)
echo "Thursday"
;;
5)
echo "Friday"
;;
6)
echo "Saturday"
;;
7)
echo "Sunday"
;;
*)
echo "Invalid number. Please enter a number from 1 to 7."
;;
esac
Output:
echo "$greeting!"
Output:
first_char="${string:0:1}"
largest=$n1
Output:
numbers=()
if [ ! -f "$filename" ]; then
echo "File not found!"
exit 1
fi
count=0
Answer:
#!/bin/bash
Output:
Answer:
#!/bin/bash
mkdir BCA6E
touch BCA6E/p1
echo "Present directory:"
pwd
echo "List of files containing BCA6E:"
find . -name '*BCA6E*'
Output:
Answer:
#!/bin/bash
if [ ! -f "$filename" ]; then
echo "Not a regular file!"
exit 1
fi
Answer:
#!/bin/bash
if [ ! -f "$filename" ]; then
echo "File not found!"
exit 1
fi
directory=$(dirname "$filename") cp
"$filename" "$directory/newfile"
Output:
Answer:
#!/bin/bash
num1=$1
num2=$2
num3=$3
max=$num1
if ((num2 > max)); then
max=$num2
fi
if ((num3 > max)); then
max=$num3
fi
Output: