UNIX Recycle Bin - restore function

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions UNIX Recycle Bin - restore function
# 1  
Old 11-12-2010
UNIX Recycle Bin - restore function

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

A set of Linux shell scripts is required to allow users to ‘remove' files without them really disappearing until the ‘dustbin' is emptied. The three shell scripts required are :-

del <filename> - This script should move the file called <filename> (a full or relative pathname) to the
dustbin directory.

trash [-a] - This script should remove the contents of the dustbin directory.
If the -a option is not used, the script should print the filenames in the dustbin one by one and ask the
user for confirmation that they should be deleted.
Otherwise, If the -a option is used, the script should simply remove ALL files from the dustbin.

restore [-n] <filename> - This script should move the file called <filename> (a full or relative pathname)
back to its original directory.
If the -n option is used, the script should allow the file to be moved to a directory nominated by the user.


Help:

I need help with the restore function.
How can I save the original path of the file and then after deletion move it back? (bash code would help)
Any relevant ideas on how to do this can help me very much.
Thanks!


2. Relevant commands, code, scripts, algorithms:

bash code
using Puppy Linux OS
I used a dustbin directory to keep my deleted files


3. The attempts at a solution (include all code and scripts):

To get the path of the file I used this:
ABS_PATH=$(cd $(dirname ${1});pwd)

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Edinburgh Napier University , Edinburgh , UK , Dr Alistair Armitage , CSN08101 Systems and Services

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
# 2  
Old 11-12-2010
Create a clone tree ~/.snapshot/ with every subdirectory of ~ and every file hard linked. They can delete th originals and recover them from ~/.snapshot/. A monitoring daemon can ensure that all files created are linked in soon thereafter. The path is the same path plus /.snapshot/

Now, if you want to ensure you can recover even after an overwrite, you have to copy not move. If space is a problem, the .snapshot can be a zip file. The daemon can have a directory of cksum values or trust time stamps to decide what is new to save.

I have seen facilities where ther were N snapshots holding files for N prior days, so you can recover an old version.
# 3  
Old 11-12-2010
Great! I got something like this for the clone tree:

# cd /
# tar cf - . | (cd ../clonetree/; tar xpvf -)

And now, how do I actually restore the file from my dustbin to the original location? ( how do I use the clone tree?)
# 4  
Old 11-12-2010
What is it with tar, a command so old it it like going to rent a car and taking the 1962 VW beetle, especially when not leaving the host!

Yes, tar will make copies, so you just copy the file you want back. If /a/b/c/d is restored:
Code:
cp -p /clonetree/a/b/c/d /a/b/c/d

Copies are slower than links and take more space. You can use cpio -pl to make linked clone trees. The linking is more likely possible if you clone within one device.
https://www.unix.com/man-page/OpenSolaris/1/cpio/
# 5  
Old 11-17-2010
Quote:
Originally Posted by DGPickett
What is it with tar, a command so old it it like going to rent a car and taking the 1962 VW beetle, especially when not leaving the host!
tar is simple, efficient, and works. cpio also works, but its syntax is far more tortuous.

tar also has advantages over cp in some ways. I occasionally prefer it over cp in situations where I need to be very careful where it extracts because cp -R is entirely willing to create a new destination directory even when you didn't mean to. tar on the other hand is very precise and strict about what it creates where.

As for your continual harangues on tar's inefficiency:
Code:
# directory of tiny tiny files
$ du -hs ./code
187M        ./code
# creating a tarball of it
$ tar -cf code.tar code
# Did tar waste gigatons of space?
$ du -hs ./code.tar
184M
# NO, it didn't!  Don't believe me?  Let's look closer.
$ du -s ./code ./code.tar
188236	./code.tar
191296	./code
# Now we create a CPIO archive, which should be wayyyyy better right?
$ find ./code -type f -depth -print | cpio -ov > ./code.cpio
$ ls -l code.tar code.cpio
-rw-r--r-- 1 monttyle monttyle 192747520 Nov 17 08:14 ../code.tar
-rw-r--r-- 1 monttyle monttyle 191435776 Nov 17 08:22 ../code.cpio
$

...and even that minute 0.5% extra reduces to 26 kilobytes out of 100 megs when you compress -- 0.02%.

So tar works absolutely fine, and you really don't need to tell us how awful it is all the time. Thank you.
# 6  
Old 11-17-2010
Maybe it was that tar I got on my favorite jacket at Mystic Seaport. Smilie

You seem to have a newer tar, that has compression and allows '-' arguments, but there are some really old ones out there that do not behave as normally or nice. This forum is not UNIX-flavor-specific, and I hate it when an old command refuses my examples!

I do not memorize cpio syntax, I write it in scripts, or I get cpio managed free in recursive modes of cp, rcp, scp, scp2. Some scp2 have a -d that says the target must be a pre-existing dir, so the 'different result second time' problem is averted.

Also tar does not have a linking to original, not copying, option like cpio pass and cp, since when space was a concern and overwrite was not, the object was to create a clone tree of hard links?
# 7  
Old 11-17-2010
Quote:
Originally Posted by DGPickett
Maybe it was that tar I got on my favorite jacket at Mystic Seaport. Smilie

You seem to have a newer tar, that has compression and allows '-' arguments, but there are some really old ones out there that do not behave as normally or nice.
I gzipped the files after.

tar and cpio were standardized at the same time. You might also find it illuminating that POSIX-2001 restandardized the tar format in a backwards-compatible way to support files >8GB, but cpio couldn't be adapted -- they removed it from POSIX instead. It's gone.

In short -- tar won, cpio lost. On many of my systems it didn't even come with the base OS!
Quote:
This forum is not UNIX-flavor-specific, and I hate it when an old command refuses my examples!
Preaching to the choir, my friend. Smilie My personal bugbear is solaris /bin/sh...
Quote:
Also tar does not have a linking to original, not copying, option like cpio pass and cp, since when space was a concern and overwrite was not, the object was to create a clone tree of hard links?
This is true. tar and cpio are not totally equivalent in functionality.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Recycle bin.

Hi. I've created scripts for a recycle bin that can list, restore and empty it. I only have the problem of deleting two files with the same name. When I do it one file overwrite the other. What could I do to resolve it? The only thing I can think is asking the user to rename file before moving to... (2 Replies)
Discussion started by: ReonarudoB
2 Replies

2. UNIX for Dummies Questions & Answers

Recycle bin on minix 3.2.1?

Hi. I'm started to use minix 3.2.1 recently and I'm trying to create a recycle bin for it. I'm kinda struggling on how to do it. I searched internet and I found scripts created for it but I actually didn't learn how to create scripts in college and I'm not sure if I understand them. I just wanted... (1 Reply)
Discussion started by: ReonarudoB
1 Replies

3. Shell Programming and Scripting

Possible to use /usr/bin/watch to call a function?

I want to have a script both define functions and have the ability to run an external program calling one of them. This is the simplified construct: #!/bin/bash foo() { echo "this is foo" } bar() { echo "this is bar" } case "$1" in one) foo ;; two) export... (1 Reply)
Discussion started by: graysky
1 Replies

4. Shell Programming and Scripting

Recycle Bin

what is recycle bin mode in unix??? (4 Replies)
Discussion started by: arun508.gatike
4 Replies

5. Shell Programming and Scripting

/usr/bin/time Shell Scripting Function

Hello, I have made a Linux Shell Script that downloads 6 files from the Internet and then deletes them. Now i want to use the function "/usr/bin/time" and "bc" to calculate how long the avergate run time for the shell script is. I therefore need to do it 100 times. My shell script code is below: ... (6 Replies)
Discussion started by: solo2
6 Replies

6. UNIX for Dummies Questions & Answers

Help with my recycle bin code

Hi~ I have a problem with my recycle bin code. #!/bin/bash if test !-d ~/.recyclebin #if recycle bin does not exists then mkdir ~/.recyclebin # then create recycle bin else mv $1 ~/.recyclebin #else move the deleted file in the recycle bin fi so when I... (10 Replies)
Discussion started by: zel2zel
10 Replies

7. Shell Programming and Scripting

Recycle Bin Script

Hello, I have having problems with an assignment and am pretty desperate. My assignment is to create a shell script that does a Recycle_Bin tasks. You can only open this with PuTTY software or Knoppix. Perhaps on other software that are able to read linux language. My part is stuck... (2 Replies)
Discussion started by: chueu
2 Replies

8. Shell Programming and Scripting

intro to UNIX - making a sort-of recycle bin (for fun)

Hello, I'm only taking Intro to UNIX in school right now, so please bear with me. My problem is with a sort-of recycle-bin rig I've created for fun. I'm using Ubuntu 9.04, I am the admin. (only user, actually) of this computer. I'm using this script in ~/.bashrc # if files exist, remove contents... (6 Replies)
Discussion started by: jzacsh
6 Replies

9. Windows & DOS: Issues & Discussions

Path of Recycle Bin on Windows

hello everybody, I am trying to find the path of the Recycle Bin. I know that it's a temporary storage place, but it should have a path that we can refer to. I want to know it because I sometimes use cygwin to work on Windows, and when you delete something with it, it's gone. I just checked... (4 Replies)
Discussion started by: milhan
4 Replies
Login or Register to Ask a Question