Please (Delete script)

[LEFT]
Hello everybody.
Actually I would like to ask you who can I make delete commend by shell script to delete some files from anywhere in my director and send it to specific place but whit the PATH because if want to restore it will return to the original place which I delete it from (As recycle pan in windows).
To be honest with you I do not have experience in Unix commend so please help me.
thanks [/LEFT]

What options you have depend greatly on what version of UNIX you have and which shell you are using.

In order to move deleted files to a faux recycle bin, you're going to need to store more than just the files there. You'll need to have some kind of config file or a .ini file for each deleted file that tells UNIX where it came from and when it was deleted. You also will have to find a naming convention so that files deleted that have the same name, but came from different directories don't overwrite each other.

Another option would be to keep the original directory structure where the file came form within your recycle-bin directory. However, this could get difficult to maintain and will require you to parse the directory structure where the file was originally so that you can create the identical structure in your recycle-bin.

Its possible there is some free-ware utility that does this for you, but I have not heard of one.

Hopefully, this gives you some ideas about how you might accomplish what you are asking.

  1. Very simplest way is:
rm -i FILENAMES

Which asks you confirmation before deleting the file, so there you should decide.

  1. Use GNOME or KDE to delete.

Simple like the windows OS, if you use GUI, then the deleted files will be moved to Trash ( Recycle bin there ), from where you can restore.

  1. For command line: As suggested earlier, it is very difficult to maintain all the meta data, and original file and so on.

So if you have deleted a wrongly, you have lot of tools to restore it. ( but it is of not 100% recovery anyway. )

  1. What i do ?

I will ask my sysadmin to restore my file ( they have 30 days incremental backup -- so no worry at all ).., if i wrongly deleted a file at my work !! -- but nothing to do if i do it in my laptop....

Thank for comments, but as I wrote I have little Unix background and what I wanted as homework also i will hand in on the last of this week so as you know I don�t have long time to cover all commends and I am worry about that. So if you can write any code I will try to understand it and do it.

Hi
I use this commend to move any files to backup file

mv $* $HOME/backup/.

But if I want to remove files with their paths because if I want to restore it from (backup file) to the original place I think will need it also if I have the same file name in the deferent place will give me error when I remove it.

The purpose from this work how I can remove files and restore these again.
thanks

Hello,
When I am deleleting some file that time I am moving that file to backup
directory and when I say restore then its showing me the backupdirectory
path and file with index..Ex..if i delete 3 files then restore will shoe me:
:0:/backup/somedeletedfile
:1:/backup/somedeletedfile10
:2:/backup/somedeletedfile20

   My concern is if someone will say restore 1...then i want to restore    
   somedeletedfile20 to its original location i.e. the location from where it is
  deleted

  Can Nyone please help me.

In short:
Replace the rm command by a deliberately tailored "tar" command.
Whenever you type "rm file" it will actually execute "tar Recycle-bin/file.tar file" - which will move the file into the recycle bin, and maintain the file's original path.

You can achieve this replacement by the "alias" command.

A few points to take into account:

  1. will work if "rm" used with full path, but not if relative path is used. (can be worked around, but will require some thinking and looking up man pages. Maybe even coockoig up a few lines of a script)
  2. The command line options of "rm" and of "tar" are different. Need to deal with that.

Another approach:
Alias the "rm" command, so that it creates a folder under the recycleBin. This folder will have the file's name. The deleted file will be moved Into this folder, and another little text file will be created in the folder to contain the path of the file"
Restoring will be simply moving the file into the path that can be taken form the little text file.

The points to notice mentioned above, apply here too with slight modifications.

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.