A1: Implementation to create/rename/delete a file.
-> Program:
while true
do
echo "1.Create File :"; #echo is just like the print f command in C
echo "2.Rename a File :";
echo "3.Delete File :";
echo "4.Exit";
echo "Enter your choice : ";
read ch;
case $ch in
1)
echo " Please enter File name : ";
read filename;
if [ -f $filename ];
then
echo"File already existing"
else
touch $filename;
echo "File created "
ls -t | head -n 15 #display the contents of the directory after the desired action has
fi # end of if statement
;; # to break first switch case
2)
echo "Enter the name of a file to be rename : ";
read oldfile;
echo "Enter the new file name to be assign : ";
read newfile;
mv $oldfile $newfile;
echo "File successfully renamed";
ls -t | head -n 15
;;
3)
echo "Enter the file name to be delete: ";
read filename
if [ -f $filename ];
then
rm -f $filename
echo "After deleting file: ";
ls -t | head -n 15
else
echo "No such file or directory"
fi
;;
4)
exit;
;;
esac #end of switch case
done
[student@localhost Assingments]$ gedit A-1.sh
[student@localhost Assingments]$ chmod 777 A-1.sh
[student@localhost Assingments]$ ./A-1.sh
1.Create File :
2.Rename a File :
3.Delete File :
4.Exit
Enter your choice :
1
Please enter File name :
test
File created
test //file 'test' created
A-1.sh
A-1f.sh
A-1f.sh~
test1
file_1
A-1.sh~
abc
A-6.sh
A-5.sh
A-4.sh
Assign2final.zip
A-2.sh
A-3.sh
Assign6B.zip
1.Create File :
2.Rename a File :
3.Delete File :
4.Exit
Enter your choice :
2
Enter the name of a file to be rename :
test
Enter the new file name to be assign :
file_name1
File successfully renamed
file_name1 //test renamed to file_name1
A-1.sh
A-1f.sh
A-1f.sh~
test1
file_1
A-1.sh~
abc
A-6.sh
A-5.sh
A-4.sh
Assign2final.zip
A-2.sh
A-3.sh
Assign6B.zip
1.Create File :
2.Rename a File :
3.Delete File :
4.Exit
Enter your choice :
2
Enter the name of a file to be rename :
abcd
Enter the new file name to be assign :
file_name2
No such file or directory
file_name1
A-1.sh
A-1f.sh
A-1f.sh~
test1
file_1
A-1.sh~
abc
A-6.sh
A-5.sh
A-4.sh
Assign2final.zip
A-2.sh
A-3.sh
Assign6B.zip
1.Create File :
2.Rename a File :
3.Delete File :
4.Exit
Enter your choice :
3
Enter the file name to be delete:
file_1
After deleting file:
file_name1
A-1.sh
A-1f.sh
A-1f.sh~
test1
A-1.sh~
file_name2
A-6.sh
A-5.sh
A-4.sh
Assign2final.zip
A-2.sh
A-3.sh
Assign6B.zip
1.Create File :
2.Rename a File :
3.Delete File :
4.Exit
Enter your choice :
3
Enter the file name to be delete:
test_unexisting //Deleting a file that does not exist!
No such file or directory
1.Create File :
2.Rename a File :
3.Delete File :
4.Exit
Enter your choice :
4
[student@localhost Assingments]$
0 comments:
Post a Comment