OSP4
OSP4
AIM: Write a shell script for implementing directory management. (Create the menu driven
program for all file and directory management operations)
METHODOLOGY FOLLOWED:
echo "Enter an operation number"
echo " 1) Create directory"
echo " 2) Modify directory"
echo " 3) Navigate to directory"
echo " 4) List the directories"
echo " 5) Changing permissions"
echo " 6) Exit"
read opr
while [ true ]
do
case $opr in
1) echo "Create directory: Enter operation choice:"
echo "Enter a for creating a new directory"
echo "Enter b for creating a new file"
echo "Enter c for exiting the menu"
read choice1
case $choice1 in
a) echo "Enter name of the directory"
read newnamedir
mkdir $newnamedir;;
b) echo "Enter name of the file"
read newnamefile
touch $newnamefile;;
c) echo "Exiting.."
exit;;
*) echo "ENTER A VALID CHOICE" ;;
esac;;
2)echo "Modify directory: Enter operation choice:"
echo "Enter a for renaming the directory"
echo "Enter b for delete the directory"
echo "Enter c for moving the directory"
echo "Enter d for copying the directory"
echo "Enter e for exiting the menu"
read choice2
case $choice2 in
a) echo "Enter name of old file"
read olddir
echo "Enter name of new file"
read newdir
mv $olddir $newdir;;
b) echo "Enter name of the file to be deleted"
read deletefile
rmdir $deletefile;;
c) echo "Enter name of directory to move from"
read oldplace
echo "Enter name of directory to move to"
read newplace
mv $oldplace $newplace;;
d) echo "Enter name of the directory from which you want to
copy"
read file1
echo "Enter name of the directory to which you want to
paste"
read file2
cp $file1 $file2;;
e) echo "Exiting.."
exit;;
*) echo "ENTER A VALID CHOICE" ;;
esac;;
3) echo "Navigate to directory: Enter operation choice:"
echo "Enter a for going to the parent directory"
echo "Enter b for going to your a specific directory"
echo "Enter c for exiting"
read choice3
case $choice3 in
a) echo "Going to parent directory"
cd ..;;
b) echo "Enter name of path to go to specific directory"
read path
cd $path;;
c) echo "Exiting.."
exit;;
*) echo "ENTER A VALID CHOICE" ;;
esac;;
4) echo "List the directories: Enter operation choice:"
echo "Enter a to list all the files in the directory"
echo "Enter b to list all the files in the directory"
echo "Enter c for exiting"
read choice4
case $choice4 in
a) ls;;
b) ls -l;;
c) echo "Exiting.."
exit;;
*) echo "ENTER A VALID CHOICE" ;;
esac;;
5) echo "Change permissions: Enter operation choice:"
echo "Enter a to add permissions"
echo "Enter b to remove permissions"
echo "Enter c for exiting"
read choice5
case $choice5 in
a) echo "Enter file or directory name"
read fn
echo "Enter r to add read permission, w to add write
permission, x to add execute permission"
read rwx
echo "Enter u to add above permission for user, g to add
above permission for group, o to add permission for others"
read ugo
chmod $ugo+$rwx $fn
;;
b) echo "Enter file or directory name"
read fn
echo "Enter r to remove read permission, w to remove
write permission, x remove to execute permission"
read rwx
echo "Enter u to remove above permission for user, g to
remove above permission for group, o to remove permission for others"
read ugo
chmod $ugo-$rwx $fn
;;
c) echo "Exiting.."
exit;;
*) echo "ENTER A VALID CHOICE";;
esac;;
6) echo "Exiting..."
exit;;
*) echo "ENTER A VALID CHOICE" ;;
esac
done
INPUT/OUTPUT:
CREATING DIRECTORY
MODIFY DIRECTORY
NAVIGATE TO DIRECTORY
LIST THE DIRECTORIES
CHANGING PERMISSIONS