Follow

I accidentally ran `rm -rf ~/` and managed to cancel a second afterwards. It tore through my vim config, gpg directory, and the bin directory. This is what I know so far.

Having the config in code helped a lot when recovering. And thankfully I had backed up the gpg keys the most paranoid way too.

Any workarounds to avoid my foolishness in the future?

@chamilad Not really. You can keep your home director in a git repo with a script in cron to auto add/commit/push, which would make for easy restoration.

@mike yeah, I do this selectively for a few files and directories. `.vim/` was one of them so I was safe.

Do you think I should add all files and dirs in ~ to git? I feel like it's a bit too much for git, but considering the monorepo stories I've heard, it may not be.

@chamilad I doubt that it would be too much for git. Depending on where you're using git, it'll support massive repos. Speaking personally, I don't store most of my files in my home directory. I have a Synology for that. Almost everything in my Home directory is configuration. I don't even do the thing with git because most of my configs are generic. If they're not, I just rebuild them every time I reinstall.

@chamilad The simplest way to do this I can think of is aliasing rm to wait for a few seconds before removing files, but it can be annoying if you actually want to remove the files.

lias rm='echo "Are you sure you are removing this?"; sleep 2; rm'

@huy_ngo hmm.. yeah, and overtime, you may even not notice the delay, since it wouldn't be a gate. @telroy proposed using `rm -I` which seems like the best option for my stupid actions.

@chamilad I've put the following function in my .bashrc:

function rm { if [ "$1" = "-rf" -o "$1" = "*" -o "$2" = "*" ] ; then echo "think well, and eventually use /bin/rm" ; else /bin/rm "$@" ; fi }

@chamilad On more recent Fedora Releases or many many OpenSUSE releases I would just suggest to activate the snapper timeline for /home, but I guess you are on Ubuntu, right? There you should be able to do your update with deja-dub/duplicity (you can do that on the other distros as well, but it's a bit less fancy) which comes out of the box and keep an hourly backup on an extern drive/NAS/cloudstorage.

There is not much else you can do to prevent that except of backups.

Sign in to participate in the conversation
Fosstodon

Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.