Today I noticed that I lost approximately 1 TB of very old movies in my collection. I have no idea how it happened, but Munin shows what happened. I'm pretty sure it was my fault. (I was awake at that hour, yes; but, I am not 100% sure.) How can I prevent something like that from happening again? How can I prevent myself (or a program/script) from deleting more than x GB of data? Any suggestion is welcome. Munin - Disk usage


As someone who has successfully removed the /Windows subdirectory from a running windows system, AND deleted the contents of /bin on a running linux boxen (it didn't die!)... I know the feeling. (But I don't know HOW I did the Windows thing, shouldn't be possible, Windows locks files in use.)

Several options:

  • chattr and the immutable flag as of now seems to be the best idea, I could apply it to every file that matches a certain mask. Mounting as read only isn't the best solution because every time I want to move a file to the mounted drive would be a pain. BTW, one year ago circa I made a batch script that renamed every single file in c:\windows\system32\ to *.torrent. Don't ask me how I did that. I still can't figure it out. Of course that wasn't my intent! – giovi321 Jun 21 '14 at 12:36

I feel like the best option here might be to rename rm (or whatever you tend to use to delete stuff) and wrap that in a new rm script. By best option I don't mean best option, but its fun to think about doing this. You might just want to be more careful with your deletes.

I tested it out quickly after renaming rm to rm-real

/bin/rm $1

And that works. You can have that make use of a few functions in rm and echo yourself a little note to use rm-real for full functionality, or go through the exercise of getting the arguments right.

Edit: Actually the best option is good backups. Changing rm is fun, but as noted in the comments a bit wonky.

  • 1
    Watering down the commands will bite you when you sit in front of a non-neutered Linux system. Learn not to do foolish commands. This is the first lesson on that class. – vonbrand Jun 21 '14 at 2:29
  • 1
    This doesn't help deletions through a GUI though, nor find . -iname "Earth*" -delete, or Midnight Commander, or , or , ... – lornix Jun 21 '14 at 2:30
  • The best solution in my opinion would be a script that changes rm. This script should check if the amount of data that you are trying to delete is greater than x MB. If it is greater than X it should ask you "are you really sure you want to delete this amount of data?" Do you think that this would be possible? – giovi321 Jun 21 '14 at 12:33
  • I mean, what road should I follow? I just need a path to follow, or a start point. – giovi321 Jun 21 '14 at 13:29
  • I think the chattr idea above is much better then what's going on here. Backups still good though. – Roman K. Jun 21 '14 at 16:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.