Linux Lab Programs
Linux Lab Programs
if [ $M -lt 2 ]; then
M=2 # Start from the first prime number if M is less than 2
fi
sum=0
display_menu() {
echo "Select a command to execute:"
echo "1) Display current date and time"
echo "2) List files in current directory"
echo "3) Show current working directory"
echo "4) Display disk usage"
echo "5) Show system information"
echo "6) Display logged-in users"
echo "7) Show memory usage"
echo "8) Display network configuration"
echo "9) Show running processes"
echo "10) Exit"
}
while true; do
display_menu
read -p "Enter your choice (1-10): " choice
case $choice in
1)
echo "Current date and time: $(date)"
;;
2)
echo "Files in current directory:"
ls -l
;;
3)
echo "Current working directory: $(pwd)"
;;
4)
echo "Disk usage:"
df -h
;;
5)
echo "System information:"
uname -a
;;
6)
echo "Logged-in users:"
who
;;
7)
echo "Memory usage:"
free -h
;;
8)
echo "Network configuration:"
ip link show
;;
9)
echo "Running processes:"
ps aux
;;
10)
echo "Exiting..."
break
;;
*)
echo "Invalid option, please select again."
;;
esac
echo ""
5) 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
echo "Files with read, write, and execute permissions:"
for file in *; do
if [ ! -f "$source_file" ]; then
echo "Error: File '$source_file' does not exist."
exit 1
fi
cp "$source_file" "$destination_dir"
if [ $? -eq 0 ]; then
echo "File '$source_file' has been copied to '$destination_dir'."
else
echo "Failed to copy '$source_file'."
fi
7) Write a shell script to create two data files and compare them to
display unique and common entries