1️⃣ Create File
2️⃣ Delete File
3️⃣ View File Content
4️⃣ Rename File
5️⃣ Exit
Script: file_menu.sh
#!/bin/bash
while true
do
echo "----------------------------"
echo "1. Create File"
echo "2. Delete File"
echo "3. View File"
echo "4. Rename File"
echo "5. Exit"
echo "Enter your choice:"
read choice
case $choice in
1)
echo "Enter file name to create:"
read fname
touch "$fname"
echo "File created successfully."
;;
2)
echo "Enter file name to delete:"
read fname
if [ -f "$fname" ]
then
rm "$fname"
echo "File deleted successfully."
else
echo "File does not exist."
fi
;;
3)
echo "Enter file name to view:"
read fname
if [ -f "$fname" ]
then
cat "$fname"
else
echo "File does not exist."
fi
;;
4)
echo "Enter existing file name:"
read oldname
echo "Enter new file name:"
read newname
if [ -f "$oldname" ]
then
mv "$oldname" "$newname"
echo "File renamed successfully."
else
echo "File does not exist."
fi
;;
5)
echo "Exiting program..."
break
;;
*)
echo "Invalid choice! Try again."
;;
esac
done
✅ How to Run
chmod +x file_menu.sh
./file_menu.sh
🎯 Sample Output
1. Create File
2. Delete File
3. View File
4. Rename File
5. Exit
Enter your choice: 1
Enter file name to create:
test.txt
File created successfully.
🔥 Important Exam Points
touch→ create filerm→ delete filecat→ display file contentmv→ rename file-f→ check file existscase→ menu selection