How to rickroll people that try to run "rm -rf" on your system
I like Rick Astley late 80's songs, and you can see them here in my Spotify:
I like rickrolling people too, especially if they are trying to delete my entire
/home
directory or, even worse, /
. Since I learned
how to use the alias
built-in, I wanted a way to prevent that
random people tinkering with my laptop (that I may forgot to lock) could
delete potentially important stuff, just for fun or boredom.
The method that I will show will lock any rm
command runned in
both recursive and force mode, so rm -rf
, rm -f -r
and rm -r --force
are all blocked, even if they are runned with
sudo
. I am going to alias the rm command in
/etc/profile
, /etc/bash.bashrc
and in
/etc/zsh/zshrc
(I am a zsh user) so that the rickroll will be
possible from all users, even root and the ones with a brand new
.bashrc
or .zshrc
. Here is the code I appended to
those files:
Since alias
is not able to control the flags of the aliases (see
here, we are going to redirect each call of rm
to
/bin/rmAlias
, that would run the command if it is safe. I did
not use a function because it is a bit tricky to make that work with
sudo
. So, let's see the code I put in rmAlias
:
It may look messy to a UNIX guy more experienced than me, but it
works. The getopts
built-in sees if both the -r
and
the -f
flags are used and, if so, it starts
rickroll()
, which opens with xdg-open
that amazing
clip from RickAstleyVEVO. From line 30 and below, the script checks
if the --force
flag is used instead of -f
.
Let's give execution permissions to the script we have just created:
Restart your shell, and enjoy. If you want to test safely, I suggest trying
to run rm -rf
with no folders or a nonexistant one, since this
script stops even these commands.
If you want even more security, you can rename this script to
/bin/rm
and move the original one in some other place, getting rid of all the aliases. I prefer the solution above because it's tidier: you haven't to move anything. In fact, this could be just an AUR package...