• 📘 For quick revision only • ✏ These questions were shared by Nithya Ma’am for 3BCA03 • 🔍 Use it as a last-minute reference tool • ⚠ Cross-check • 🤝 All the best for your lab exam OS– End Term Lab Exam Answers 1. Execute Unix Commands and File Manipulation Commands Basic Unix Commands pwd → Shows current working directory ls → Lists files and directories cd folder/ → Changes directory mkdir test → Creates a new directory rmdir test → Removes empty directory touch file1 → Creates an empty file cp f1 f2 → Copies file mv f1 f2 → Renames or moves file rm f1 → Removes a file cat f1 → Displays file contents 2. Shell Script to Check Whether Number is Even or Odd echo "Enter a number:" read n if [ $((n % 2)) -eq 0 ] then echo "Even number" else echo "Odd number" fi 3. Check Leap Year or Not echo "Enter year:" read y if [ $((y % 400)) -eq 0 ] || ( [ $((y % 4)) -eq 0 ] && [ $((y % 100)) -ne 0 ] ) then echo "Leap Year" else echo "Not a Leap Year" fi 4. Find Factorial of a Number echo "Enter a number:" read n fact=1 while [ $n -gt 0 ] do fact=$((fact * n)) n=$((n - 1)) done echo "Factorial = $fact" 5. Swap Two Integers echo "Enter a:" read a echo "Enter b:" read b temp=$a a=$b b=$temp echo "After swapping: a=$a b=$b" 6. Find Smallest Digit in a Number echo "Enter a number:" read n small=9 while [ $n -gt 0 ] do digit=$((n % 10)) if [ $digit -lt $small ] then small=$digit fi n=$((n / 10)) done echo "Smallest digit = $small" 7. Perform Basic Arithmetic Operations echo "Enter two numbers:" read a b echo "1. Add" echo "2. Subtract" echo "3. Multiply" echo "4. Divide" echo "Choose option:" read ch case $ch in 1) echo "Sum = $((a + b))" ;; 2) echo "Difference = $((a - b))" ;; 3) echo "Product = $((a * b))" ;; 4) echo "Quotient = $((a / b))" ;; *) echo "Invalid Choice" ;; esac 8. Reverse a Number echo "Enter number:" read n rev=0 while [ $n -gt 0 ] do digit=$((n % 10)) rev=$((rev * 10 + digit)) n=$((n / 10)) done echo "Reversed Number = $rev" 9. Fibonacci Series of N Terms echo "Enter n:" read n a=0 b=1 echo "Fibonacci Series:" for((i=1;i<=n;i++)) do echo "$a" temp=$((a + b)) a=$b b=$temp done 10. Print Sum of N Natural Numbers echo "Enter n:" read n sum=$((n * (n + 1) / 2)) echo "Sum = $sum" 11. Largest of Three Numbers echo "Enter three numbers:" read a b c if [ $a -ge $b ] && [ $a -ge $c ] then echo "$a is largest" elif [ $b -ge $c ] then echo "$b is largest" else echo "$c is largest" fi 12. Print Multiplication Table echo "Enter a number:" read n for((i=1;i<=10;i++)) do echo "$n x $i = $((n*i))" done 13. Copy Contents of One File to Another echo "Enter source file:" read f1 echo "Enter destination file:" read f2 cp $f1 $f2 echo "File Copied Successfully" 14. Check Whether File Exists and Readable echo "Enter filename:" read f if [ -r $f ] then echo "File is readable" else echo "File is not readable" fi 15. Search a Particular String in a File echo "Enter filename:" read f echo "Enter string to search:" read s grep $s $f Marks Allotment ● Lab Programs (2 × 20M) = 40 Marks ● Lab Record = 10 Marks ● Converted to 100 Marks