LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-11-2010, 11:24 AM   #1
chopperdday
LQ Newbie
 
Registered: Nov 2010
Posts: 1

Rep: Reputation: 0
Restoring a file


Hey,

I've written a vary basic script that moves a specified file into the dustbin directory. The script is as follows:

Code:
#!/bin/bash
#move items to dustbin directory
mv "$@" ~/dustbin/
echo "File moved to dustbin"
This works fine for me, any file I specify gets moved to the dustbin directory. However, what I would like to do is create a new script that will move the file in the dustbin directory back to its original directory. I know I could easily write a script that would move it back to a location specified by the user, but I would prefer to have one that would move it to its original directory.

Is this possible?

I'm using Mac OS X 10.6.4 and Terminal
 
Old 11-11-2010, 11:32 AM   #2
udaman
Member
 
Registered: Oct 2010
Location: New England, USA
Distribution: OpenSUSE/Slackware64/RHEL/Mythbuntu
Posts: 189

Rep: Reputation: 39
Yes it's possible, but you kinda have to cheat a little. I'd write a tracer file, or marker file, that holds the name of the old directory. And then read in that file into your new script, so you know where it came from. I don't know any other method of keeping track, and it's not the best programming method.

Code:
echo "old dir here" > .tracer
 
Old 11-11-2010, 02:27 PM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
As udaman suggested, you can use some file to store the old path. For example:

Code:
#!/bin/bash
foreach item in "$@" ; do
    if [ "${item:0:1}" == "/" ] ; then
        OLDNAME="$item"
    else
        OLDNAME="`pwd`/$item"
    fi
    BASENAME=`basename $item`
    echo $OLDNAME > ~/dustbin/.dustbin.$BASENAME
    mv "$item" ~/dustbin/$BASENAME
done
I haven't tested that, but it should give you some idea where to start.
 
Old 11-15-2010, 02:25 AM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 11-15-2010, 11:01 AM   #5
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,272

Rep: Reputation: 154Reputation: 154
Your solution does not take into account files with the same name, or files with the same name and path but created/deleted at different times.

Off the top of my head I would create random file names (with mktemp) and rename the file to the renamed file under the trash directory. I would then use an index file to store the deleted file name and path against a deleted time stamp and the random name.

Obviously that makes recovery a little more difficult. You would tool needs to give you a list of file names and time stamps, and then ultimately recover a specific version of the file.
 
  


Reply



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
restoring windows file system true_atlantis Linux - Software 4 02-23-2006 03:31 PM
Restoring an old xord.config file Bryanlee Linux - Newbie 9 05-15-2005 08:35 PM
Help restoring file permissions from a Dump bminish Linux - Newbie 3 12-12-2004 01:34 PM
Restoring a rm'ed file? sharpie Linux - Newbie 6 02-03-2004 03:05 AM
Restoring / Undeleting a file richardrex Linux - General 4 10-24-2003 07:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:05 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
Open Source Consulting | Domain Registration