LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-25-2014, 04:29 PM   #1
Thomzin
LQ Newbie
 
Registered: Nov 2014
Posts: 5

Rep: Reputation: Disabled
Trash & Restore Scripting Issue


Hi there, new to the forums.

I'm currently working on two scripts. The first takes a file and sens it to a folder named "Trash", as a method of file deletion. This works fine. Note this script also takes the "original file path" and stores it into a file.

The 2nd script is the issue. I'm currently trying to take the file path from file and restore the file to it's original destination. I will attach both scripts for your input.

Code:
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 is working fine ^

Code:
#!/bin/bash

#Restore Script - this script will restore a previously deleted file (in trash). Back to it's original location.

#restore="$(grep "$1" "$HOME/Paths")"

#filename="$(basename "$restore")"

#location1="$(readlink -f "$location")"

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

# End
Note i commented out a previous attempt.

Thankyou very much in advance if you do take the time to assist me. I understand it's a very simplistic issue, but i'm just starting out and a little confused!
 
Old 11-25-2014, 05:00 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,836

Rep: Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360Reputation: 1360
With a couple of changes, and using only your original code, this works:

Code:
#!/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
Code:
#!/bin/bash
restore=$(find my-documents/* | grep $1)
filename=$(readlink -f $restore)
mv -i "$filename" "$(grep $1 $HOME/TrashLog)"
But, in the future, you will have a lot of problems with this script. There are a lot of ways to break it in its current form.

Last edited by szboardstretcher; 11-25-2014 at 05:02 PM.
 
1 members found this post helpful.
Old 11-25-2014, 05:07 PM   #3
Thomzin
LQ Newbie
 
Registered: Nov 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
Code:
#!/bin/bash
restore=$(find my-documents/* | grep $1)
filename=$(readlink -f $restore)
mv -i "$filename" "$(grep $1 $HOME/TrashLog)"
But, in the future, you will have a lot of problems with this script. There are a lot of ways to break it in its current form.[/QUOTE]

I had a look at this, and tested it. I actually was returned with an error.

(There is a file in Trash currently called "Derp".)

I did.. restore derp. In the console. I was returned with..
"find: `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

Super confused :/

Is this a permissions issue? or something not quite working with the original code which is causing issues later with my restore?

Thanks for your time.
 
Old 11-25-2014, 06:20 PM   #4
Thomzin
LQ Newbie
 
Registered: Nov 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
Still very eager for any assistance someone could shed? Ripping my hair out currently!
 
Old 11-25-2014, 06:37 PM   #5
Thomzin
LQ Newbie
 
Registered: Nov 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
A friend gave me this segment of script here, which looks like it could be useful, this also doesn't work. However the error i get is one of which it claims the file cannot be moved as there is no such file or directory. I think we're getting close?

Code:
mv -i "$1$ "$(grep "$1" "$HOME/TrashLog")"
 
Old 11-25-2014, 07:37 PM   #6
Thomzin
LQ Newbie
 
Registered: Nov 2014
Posts: 5

Original Poster
Rep: Reputation: Disabled
update: after some help from other sources. I'm now at this stage..

#!/bin/bash

Code:
cd "$HOME/my-documents/mydir01/Trash" || exit 1
mv -i "$(grep "$1" "$HOME/TrashLog")"
again any help at this stage would be amazing.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell Scripting for Recycle Bin. Delete,Trash,Restore mohitnarula Linux - Newbie 27 11-27-2012 04:27 PM
HowTo Restore Trash Icon GNewbie MEPIS 1 01-15-2006 05:26 PM
How to restore the Empty/Full trash Icons? tr4nce Slackware 2 04-13-2003 04:15 PM


All times are GMT -5. The time now is 05:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration