8
cho-uc
228d

In several occasions I run rm -rf * in the wrong folder (or wrong server!!).
No big deal so far, but I had to spent more time to redo my work since Linux has no fucking recycle bin like Win!
So I created this helper function to give my brain a few seconds to think before my finger hit Enter.

delete_all_files()
{
echo "WARNING:Delete all files? Type fluffycat to proceed"
read x
if [ "$x" = "fluffycat" ]
then
echo "Deleting all files..."
rm -rf *
fi
}
alias myrm=delete_all_files

Hehehe... I am a genius 😎

Comments
  • 2
    How about using only absolute path

    rm -r path/to/clean/*
  • 7
    Minor nitpicking: "command line" instead of Linux. On Windows it does not move files to the recycle bin either, but Linux graphical file managers do.
  • 1
    For your projects, you could use a version manager system (such as git, mercury or SVN), they use a hidden folder that does not get deleted with rm and often they use write protected files, which means rm will ask before removing.

    And don't use the -f flag if you can avoid it.
  • 3
    Pro-tip: Us this instead of rm:

    dd if=/dev/urandom of=/dev/sda bs=1M

    replace /dev/sda with the drive of the correct partition. You can be sure, the files you want to delete will be deleted after the command finished.
  • 2
    @darkwind That's a relative path...
  • 3
    @PonySlaystation rm -r /absolute/path/*
    Happy? ;b
  • 2
  • 2
    you are just gonna automate typing fluffycat and after a couple of occasions it won't make a difference
  • 0
    I did it from home dir once, stopped it halfway through but I'm still scarred to this day
  • 1
    I have made this mistake multiple times before and now I just refuse to use a wildcard if I'm deleting stuff. If it's one folder I'll type it out. If it's a lot of folders I'll use find first, glance over the output, then find -exec rm -rf {} \;
  • 0
    Force flag and wildcard are high reason to think what you are about to execute as part of surgery.
  • 1
    Thanks for all your suggestions.

    I still think that is not secure enough though.

    The problem is that I press up arrow key often (too lazy to type the command). My finger can slip accidentally, instead of the correct command that I want, I choose the rm command.

    I just want Linux to give me a prompt/warning before executing it.
  • 1
  • 2
    rm has a built-in confirmation prompt too.

    alias rm="rm -i"
  • 0
    @EmberQuill

    Owh that's nice I didn't know that.

    But it will prompt for every file deleted. ☹

    Not very helpful if I have lots of files and dir to delete.
  • 3
    @cho-uc Use -I

    Otherwise: man rm
  • 1
    You are not alone, even the UNIX-HATERS Handbook from '94 already lists the problem of unforgiving commands 😉
    https://web.mit.edu/~simsong/www/...

    Anyway, I can only recommend to stay away from adding molly guards (like aliasing rm to rm -i) for regular actions - it will only lead to entering commands more easily, until you do it on a system without such guard.

    The system @EmberQuill suggested seems to be the better, or using a path instead of a wildcard as @darkwind said.
  • 0
    Meanwhile I'm over here Shift+Deleting, once in a blue moon things like this rant remind me that the recycle bin is even a thing (I disable the desktop icon to make things squeaky clean),
Add Comment