Running a "restore" script which moves a file previously deleted (moved to a trashbin folder) back to where it came from. Running the secondary script I receive this error...

"mv: cannot stat `test': No such file or directory"

Test is the name of the file I am moving to the trash and attempting to restore.

Here is the secondary script:

mv -i "$(grep "$1" "$HOME/TrashLog")"

Also here is the first script should you require it...

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. "

bumped to the homepage by Community yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


It should be readlink -f "$1". It seems obvious that the file does not exist – in that position. The restore script would work only if it happens to be executed in (working directory) $HOME/my-documents/mydir01/Trash. So the solution should be to add

cd "$HOME/my-documents/mydir01/Trash" || exit 1

at the beginning.

  • What exactly should readlink -f "$1" be in place of? Sorry if that seems like a stupid question! – Craig Nov 26 '14 at 0:05
  • @Craig You used the quotes with grep but forgot them with readlink. Meanwhile I noticed that there are probably two problems: Why is it $1$ in the mv restore call and not just $1? Is that a typo? The delete script does not add the $ to the name. Strange that it does not appear in the mv error message. – Hauke Laging Nov 26 '14 at 0:10
  • ah sorry, noticed a few typo's when i submitted it. Hopefully that's the typo's out of the way. Any thoughts as to why it's not working? – Craig Nov 26 '14 at 0:18
  • This is the current error without the typos # restore test mv: missing destination file operand after /root/my-documents/mydir01/Trash/test\n/root/my-documents/mydir01/test' Also wanted to add - that they are both seperate scripts but the first one seems to work fine. It's just the restore script that i'm having issues with. Cheers! – Craig Nov 26 '14 at 0:20
  • @Craig It seems you haven't added my cd ... line to your script. Furthermore you have destroyed the mv call by not just deleting the trailing $ but the whole "$1$". – Hauke Laging Nov 26 '14 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.