Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
- The problem statement, all variables and given/known data:
A set of Linux shell scripts is required to allow users to �remove' files without them really disappearing until the �dustbin' is emptied. The three shell scripts required are :-
del <filename> - This script should move the file called <filename> (a full or relative pathname) to the
dustbin directory.
trash [-a] - This script should remove the contents of the dustbin directory.
If the -a option is not used, the script should print the filenames in the dustbin one by one and ask the
user for confirmation that they should be deleted.
Otherwise, If the -a option is used, the script should simply remove ALL files from the dustbin.
restore [-n] <filename> - This script should move the file called <filename> (a full or relative pathname)
back to its original directory.
If the -n option is used, the script should allow the file to be moved to a directory nominated by the user.
- Relevant commands, code, scripts, algorithms:
bash code
using ubuntu
I used a dustbin directory to keep my deleted files
- The attempts at a solution (include all code and scripts):
del script
#!/bin/bash
echo "Do you want to delete this file?"
echo "Y/N"
read ans
case "$ans" in
Y) echo "`readlink -f $1`" >>/home/ian/store & mv $1 /home/ian/dustbin ;;
N) echo "File not deleted" ;;
esac
trash script
#!/bin/bash
if ["$1" == "-a"]
then
cd /home/ian/dustbin
rm -rf*
cd /home/ian
rm store
touch store
else
cd /home/ian/dustbin
ls > dustbin
for line in `cat dustbin`
do
echo "Do you want to delete?" $line
echo "Y/N"
read ans
case "ans" in
Y) rm $line;;
N) "";;
esac
done
rm dustbin
cd
rm store
touch store
fi
restore script
#!/bin/bash
if [ "$1" == "-n" ]
then
cd /home/ian/dustbin
restore =`grep $2 /home/ian/store`
filename = `basename "$restore"`
echo "Where do you want to save to?"
read location
location1 = `readlink -f $location`
mv -i $filename "$location1"/$filename
else
##if the restore script is run without the -n switch the file will be restored to its original location
cd /home/ian/dustbin
restore = `grep $1 /home/ian/store`
filename=`basename "$restore"`
mv -i $filename $location
fi
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Edinburgh Napier University , Edinburgh , UK , Dr Alistair Armitage , CSN08101 Systems and Services
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
***********************************
I am just looking to see if there is anything I can do to improve the scripts?
Any help would be appreciated