OSA: File management (Create,rename,delete and list the file's in present working directory)

while(true)
do

echo  " Enter operation you want to perform
------------------------------------------------------------------------------
1)Create a File
2)Rename a File
3)Delete a File
4)List File's "
echo "enter your choice->"

read choice
case $choice in

1) echo "Enter the name of file to be created"
read filename
if [ -f $filename ];
then
echo "file already exists,please try another name"
else
touch $filename
echo "file has been created successfully"
fi #
;;

2) echo "Enter the name of File to be renamed "
read oldfilename
if [ -f $oldfilename ];
then
echo "enter the new file name to be assigned "
read newfilename
mv $oldfilename $newfilename
else
echo "file doesn't exist please try an existing filename"
ls
fi #
;;


3) echo "Enter name of File to be deleted "
read name
if [ -f $name ];
then
rm -f $name
echo "file has been deleted successfully"
else
echo "No such file ,please try again here are the contents of the directory:"
ls
fi #
;;

4) echo "list of file's in present working directory"
ls
#
;;


5) exit
echo "program terminated"
exit0
;;

esac #
done



Comments

Popular posts from this blog

NASM: program to find largest number from an array of 32-bit numbers(hard-coded)

Rules for drawing a FLOWCHART