#!/bin/bash
echo "Are you sure you want to move this file to the Recycle Bin?" "(Yes/No)"
read ans
case "$ans" in
Yes) echo "$(readlink -f $1)" >> "$HOME/TrashLog" && mv "$1" "$HOME/my-documents/mydir01/Trash" ;;
No) echo "File was NOT deleted and remains. ";;
esac
This script moves a file to a trash
folder in which acts as a recycling bin. The 2nd script I'm trying to make should take the location of the original file (stored in TrashLog
as a file path) and restore the file to its original location. Here's what I had so far (which isn't working).
#!/bin/bash
restore=$(find my-documents/* | grep $1)
filename=$(readlink -f $restore)
mv -i "$filename" "$(grep $1 $HOME/TrashLog)"
my-document/*': No such file or directory readlink: missing operand Try 'readlink --help' for more information. mv:cannot stat
/root/my-documents/mydir01/derp: no such file or directory" – Craig Nov 25 '14 at 22:32grep -e "$1"
isn't very reliable since it'll pick up parts of file names. If you wanted to specify a file by a regular expression, usefind -name "$1"
– Gilles 'SO- stop being evil' Nov 25 '14 at 22:33