WestleyR / srm

Safe remove ('rm') command with caching and undo/recover
BSD 3-Clause Clear License
8 stars 2 forks source link

batch recover? #6

Open tiansin opened 1 year ago

tiansin commented 1 year ago

Can I recover deleted files in bulk? @WestleyR

WestleyR commented 1 year ago

No bulk option has been added yet. How where you thinking it should work? Like a wildcard name match, or like everything in the last 2 minute? And also should it recover it to the original path? How would it function ideally for you?

tiansin commented 4 months ago

@WestleyR After mistakenly executing “rm -rf /*”, is it possible to use a command like “rm -revoke latest” to restore files to their original paths, or use “rm -revoke hash” to restore the entire deletion at a specific point in time?

WestleyR commented 4 months ago

That is not possible yet, I will try to see if I can add that feature soon-ish.

WestleyR commented 1 month ago

I updated the code a little, you can do something like this:

$ mkdir foo
$ touch foo/test-file1
$ touch foo/test-file2
$ touch foo/test-file3

$ ./srm foo/*
$ ./srm +l
10. ~/.cache/srm3/trashbin/cs5eal8cvu45ite47vfg/trash/newfile8 (was /home/westley/new-repos/srm/foo/newfile8) - 0 B
9. ~/.cache/srm3/trashbin/cs5eal8cvu45ite47vg0/trash/newfile9 (was /home/westley/new-repos/srm/foo/newfile9) - 0 B
8. ~/.cache/srm3/trashbin/cs5eal8cvu45ite47vgg/trash/newfile10 (was /home/westley/new-repos/srm/foo/newfile10) - 0 B
7. ~/.cache/srm3/trashbin/cs5eal8cvu45ite47vh0/trash/newfile11 (was /home/westley/new-repos/srm/foo/newfile11) - 0 B
6. ~/.cache/srm3/trashbin/cs5eal8cvu45ite47vhg/trash/newfile12 (was /home/westley/new-repos/srm/foo/newfile12) - 0 B
5. ~/.cache/srm3/trashbin/cs5eal8cvu45ite47vi0/trash/newfile13 (was /home/westley/new-repos/srm/foo/newfile13) - 0 B
4. ~/.cache/srm3/trashbin/cs5eal8cvu45ite47vig/trash/newfile14 (was /home/westley/new-repos/srm/foo/newfile14) - 0 B
3. ~/.cache/srm3/trashbin/cs5eauocvu45k4pvq4e0/trash/test-file1 (was /home/westley/new-repos/srm/foo/test-file1) - 0 B
2. ~/.cache/srm3/trashbin/cs5eauocvu45k4pvq4eg/trash/test-file2 (was /home/westley/new-repos/srm/foo/test-file2) - 0 B
1. ~/.cache/srm3/trashbin/cs5eauocvu45k4pvq4f0/trash/test-file3 (was /home/westley/new-repos/srm/foo/test-file3) - 0 B

$ ./srm +r 1 2 3
Recovering: /home/westley/.cache/srm3/trashbin/cs5eauocvu45k4pvq4f0/trash/test-file3 to /home/westley/new-repos/srm/foo/test-file3
Recovering: /home/westley/.cache/srm3/trashbin/cs5eauocvu45k4pvq4eg/trash/test-file2 to /home/westley/new-repos/srm/foo/test-file2
Recovering: /home/westley/.cache/srm3/trashbin/cs5eauocvu45k4pvq4e0/trash/test-file1 to /home/westley/new-repos/srm/foo/test-file1

$ ls foo/
test-file1  test-file2  test-file3

But basically if you use a wildcard, you need to specify the index of files to recover, eg 1 2 3. It might be worth adding an option like rm --revert-last-command or something.

I have not tried /*, but it might be easier to just add a hard-coded safety check to avoid that.

However, just a note, this is not designed to be a foolproof rm command, you still need to be careful.