2016-07-28 13:52:26 +00:00
<!DOCTYPE html>
< html >
< head >
< meta charset = "utf-8" >
< meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< title > How to rickroll people that try to run " rm -rf" on your system< / title >
2018-10-24 11:53:55 +00:00
< meta name = "description" content = "WARNING: The method showed here could not prevent the actual execution of " rm -rf " if the " UNIX vandal " is clever enough . Proceed at your own risk , and make . . . " >
2016-07-28 13:52:26 +00:00
2018-10-24 20:36:54 +00:00
< link rel = "stylesheet" href = "https://maggioni.xyz/css/main.css" >
2016-07-28 13:52:26 +00:00
< link href = 'https://fonts.googleapis.com/css?family=Hammersmith+One' rel = 'stylesheet' type = 'text/css' >
2018-10-23 15:06:34 +00:00
< link href = "https://fonts.googleapis.com/css?family=Source+Code+Pro" rel = "stylesheet" >
2018-10-24 20:36:54 +00:00
< link rel = "canonical" href = "https://maggioni.xyz/linux/2016/07/28/how-to-rickroll-people-launching-rm-rf-on-your-system.html" >
< link rel = "alternate" type = "application/rss+xml" title = "maggioni.xyz" href = "https://maggioni.xyz/feed.xml" >
2016-07-28 13:52:26 +00:00
< link rel = "stylesheet" href = "//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" >
< script src = "https://rawgit.com/snaptortoise/konami-js/master/konami.js" > < / script >
<!-- Favicon -->
< link rel = "apple-touch-icon" sizes = "57x57" href = "/apple-icon-57x57.png" >
< link rel = "apple-touch-icon" sizes = "60x60" href = "/apple-icon-60x60.png" >
< link rel = "apple-touch-icon" sizes = "72x72" href = "/apple-icon-72x72.png" >
< link rel = "apple-touch-icon" sizes = "76x76" href = "/apple-icon-76x76.png" >
< link rel = "apple-touch-icon" sizes = "114x114" href = "/apple-icon-114x114.png" >
< link rel = "apple-touch-icon" sizes = "120x120" href = "/apple-icon-120x120.png" >
< link rel = "apple-touch-icon" sizes = "144x144" href = "/apple-icon-144x144.png" >
< link rel = "apple-touch-icon" sizes = "152x152" href = "/apple-icon-152x152.png" >
< link rel = "apple-touch-icon" sizes = "180x180" href = "/apple-icon-180x180.png" >
< link rel = "icon" type = "image/png" sizes = "192x192" href = "/android-icon-192x192.png" >
< link rel = "icon" type = "image/png" sizes = "32x32" href = "/favicon-32x32.png" >
< link rel = "icon" type = "image/png" sizes = "96x96" href = "/favicon-96x96.png" >
< link rel = "icon" type = "image/png" sizes = "16x16" href = "/favicon-16x16.png" >
< link rel = "manifest" href = "/manifest.json" >
< meta name = "msapplication-TileColor" content = "#ffffff" >
< meta name = "msapplication-TileImage" content = "/ms-icon-144x144.png" >
< / head >
2016-09-13 19:40:45 +00:00
< body >
< header class = "header" >
2018-10-23 14:38:45 +00:00
< section class = "head container" >
< h1 class = "title" > maggioni.xyz< / h1 >
2018-10-23 15:26:41 +00:00
< h4 > Eat
< a href = "https://en.wikipedia.org/wiki/Polenta" >
polenta< / a > and do not counter-aim!< / h4 >
2016-09-13 19:40:45 +00:00
< / section >
< nav class = "navbar" >
< div class = "container" >
< ul class = "navbar-list" >
< li class = "navbar-item" >
2018-10-29 10:15:52 +00:00
< a href = "https://maggioni.xyz/" > home< / a >
2016-09-13 19:40:45 +00:00
< / li >
2016-09-26 20:09:25 +00:00
2016-09-13 19:40:45 +00:00
< li class = "navbar-item" >
2018-10-29 10:12:30 +00:00
< a href = "https://maggioni.xyz/blog/" >
2018-10-23 14:38:45 +00:00
Blog< / a >
2016-09-13 19:40:45 +00:00
< / li >
< li class = "navbar-item" >
2018-10-29 10:12:30 +00:00
< a href = "https://maggioni.xyz/feed.xml" > RSS< / a >
2018-10-23 14:38:45 +00:00
< / li >
< / ul >
< ul class = "navbar-list" >
< li class = "navbar-item" >
< a href = "https://git.maggioni.xyz" > Git< / a >
2016-09-13 19:40:45 +00:00
< / li >
< li class = "navbar-item" >
2018-10-24 15:40:30 +00:00
< a href = "https://ci.maggioni.xyz" > Ci< / a >
2018-10-23 14:38:45 +00:00
< / li >
< li class = "navbar-item" >
2018-10-24 15:40:30 +00:00
< a href = "https://cloud.maggioni.xyz" > Cloud< / a >
2016-09-13 19:40:45 +00:00
< / li >
2018-10-23 14:38:45 +00:00
< li class = "navbar-item" >
< a href = "https://download.maggioni.xyz" > Downloads< / a >
< / li >
2016-07-28 13:52:26 +00:00
2016-09-13 19:40:45 +00:00
< / ul >
< / div >
< / nav >
2016-07-28 13:52:26 +00:00
2016-09-13 19:40:45 +00:00
< / header >
< main class = "container" >
2016-07-28 13:52:26 +00:00
< article class = "post" itemscope itemtype = "http://schema.org/BlogPosting" >
< header class = "post-header" >
2016-09-13 19:40:45 +00:00
< h2 class = "post-title" itemprop = "name headline" > How to rickroll people that try to run "rm -rf" on your system< / h2 >
2018-10-23 14:38:45 +00:00
< h4 class = "post-meta" > < time datetime = "2016-07-28T16:00:00+02:00" itemprop = "datePublished" > Jul 28, 2016< / time > < / h4 >
2016-07-28 13:52:26 +00:00
< / header >
< div class = "post-content" itemprop = "articleBody" >
2018-10-24 11:53:55 +00:00
< strong >
WARNING: The method showed here could not prevent the actual execution of "rm -rf" if the "UNIX vandal" is clever enough. Proceed at your own risk, and make backups!
< / strong >
< p >
I like Rick Astley late 80's songs, and you can see them here in my Spotify:
< / p >
< p >
< img
2018-10-24 19:57:19 +00:00
src="/images/spotify_rickastley.png"
2018-10-24 11:53:55 +00:00
alt="My Spotify with a bunch of Rick Astley songs">
< / p >
< p >
I like rickrolling people too, especially if they are trying to delete my entire
< code > /home< / code > directory or, even worse, < code > /< / code > . Since I learned
how to use the < code > alias< / code > 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.
< / p >
< p >
The method that I will show will lock any < code > rm< / code > command runned in
both recursive and force mode, so < code > rm -rf< / code > , < code > rm -f -r< / code >
and < code > rm -r --force< / code > are all blocked, even if they are runned with
< code > sudo< / code > . I am going to alias the rm command in
< code > /etc/profile< / code > , < code > /etc/bash.bashrc< / code > and in
< code > /etc/zsh/zshrc< / code > (I am a zsh user) so that the rickroll will be
possible from all users, even root and the ones with a brand new
< code > .bashrc< / code > or < code > .zshrc< / code > . Here is the code I appended to
those files:
< / p >
< p >
2018-10-23 14:38:45 +00:00
< figure class = "highlight" > < pre > < code class = "language-bash" data-lang = "bash" > < span class = "nb" > alias rm< / span > < span class = "o" > =< / span > /bin/rmAlias
< span class = "nb" > alias sudo< / span > < span class = "o" > =< / span > < span class = "s1" > 'sudo '< / span > < span class = "c" > # this enables aliases in sudo, see http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo< / span > < / code > < / pre > < / figure >
2018-10-24 11:53:55 +00:00
< / p >
2016-07-28 13:52:26 +00:00
2018-10-24 11:53:55 +00:00
< p >
Since < code > alias< / code > is not able to control the flags of the aliases (see
< a href = "http://apple.stackexchange.com/questions/50963/how-do-i-add-a-flag-to-an-alias" > here< / a > , we are going to redirect each call of < code > rm< / code > to
< code > /bin/rmAlias< / code > , 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
< code > sudo< / code > . So, let's see the code I put in < code > rmAlias< / code > :
< / p >
2016-07-28 13:52:26 +00:00
2018-10-24 11:53:55 +00:00
< p >
2016-07-28 13:52:26 +00:00
< figure class = "highlight" > < pre > < code class = "language-bash" data-lang = "bash" > < span class = "c" > #! /bin/bash< / span >
< span class = "c" > # Rickroll whoever tries to desert this system, even root.< / span >
< span class = "c" > # To achieve this, set the appropriate aliases even in /etc/profile and similars.< / span >
< span class = "c" > # Video played when rickrolling< / span >
< span class = "nv" > ROLLVIDEO< / span > < span class = "o" > =< / span > /opt/anti-rm/serious-video.mkv < span class = "c" > # it's just Never Gonna Give You Up on my system, but be free to customize this!< / span >
rickroll< span class = "o" > (){< / span >
< span class = "nb" > echo< / span > < span class = "s2" > "Never gonna desert this system..."< / span >
xdg-open < span class = "nv" > $ROLLVIDEO< / span > 2> & 1 &
< span class = "nb" > exit < / span > 0
< span class = "o" > }< / span >
2018-10-23 14:38:45 +00:00
< span class = "k" > while < / span > < span class = "nb" > getopts< / span > < span class = "s2" > ":rf-"< / span > opt< span class = "p" > ;< / span > < span class = "k" > do< / span >
2016-07-28 13:52:26 +00:00
< span class = "c" > # Prevent '--force' to be detected as -r and -f< / span >
2018-10-23 14:38:45 +00:00
< span class = "k" > if< / span > < span class = "o" > [< / span > < span class = "s2" > "< / span > < span class = "nv" > $opt< / span > < span class = "s2" > "< / span > < span class = "o" > =< / span > < span class = "s2" > "-"< / span > < span class = "o" > ]< / span > < span class = "p" > ;< / span > < span class = "k" > then
2016-07-28 13:52:26 +00:00
< / span > < span class = "nv" > OPTIND< / span > < span class = "o" > =< / span > < span class = "nv" > $OPTIND< / span > +1
< span class = "k" > continue
fi
2018-10-23 14:38:45 +00:00
if< / span > < span class = "o" > [< / span > < span class = "s2" > "< / span > < span class = "nv" > $opt< / span > < span class = "s2" > "< / span > < span class = "o" > =< / span > < span class = "s2" > "r"< / span > < span class = "o" > ]< / span > < span class = "o" > ||< / span > < span class = "o" > [< / span > < span class = "s2" > "< / span > < span class = "nv" > $opt< / span > < span class = "s2" > "< / span > < span class = "o" > =< / span > < span class = "s2" > "f"< / span > < span class = "o" > ]< / span > < span class = "p" > ;< / span > < span class = "k" > then
if< / span > < span class = "o" > [< / span > < span class = "s2" > "< / span > < span class = "nv" > $tmp< / span > < span class = "s2" > "< / span > < span class = "o" > =< / span > < span class = "s2" > ""< / span > < span class = "o" > ]< / span > < span class = "p" > ;< / span > < span class = "k" > then
2016-07-28 13:52:26 +00:00
< / span > < span class = "nv" > tmp< / span > < span class = "o" > =< / span > < span class = "nv" > $opt< / span >
< span class = "k" > continue
2018-10-23 14:38:45 +00:00
elif< / span > < span class = "o" > [< / span > < span class = "s2" > "< / span > < span class = "nv" > $tmp< / span > < span class = "s2" > "< / span > < span class = "o" > !=< / span > < span class = "s2" > "< / span > < span class = "nv" > $opt< / span > < span class = "s2" > "< / span > < span class = "o" > ]< / span > < span class = "p" > ;< / span > < span class = "k" > then
2016-07-28 13:52:26 +00:00
< / span > rickroll
< span class = "k" > fi
fi
done
for < / span > var < span class = "k" > in< / span > < span class = "s2" > "< / span > < span class = "nv" > $@< / span > < span class = "s2" > "< / span >
< span class = "k" > do
2018-10-23 14:38:45 +00:00
if< / span > < span class = "o" > [[< / span > < span class = "s2" > "< / span > < span class = "nv" > $var< / span > < span class = "s2" > "< / span > < span class = "o" > =< / span > < span class = "s2" > "--force"< / span > < span class = "o" > & & < / span > < span class = "s2" > "< / span > < span class = "nv" > $tmp< / span > < span class = "s2" > "< / span > < span class = "o" > =< / span > < span class = "s2" > "r"< / span > < span class = "o" > ]]< / span > < span class = "p" > ;< / span > < span class = "k" > then
2016-07-28 13:52:26 +00:00
< / span > rickroll
< span class = "k" > fi
done< / span >
< span class = "c" > # If it's safe, just run rm< / span >
/bin/rm < span class = "s2" > "< / span > < span class = "nv" > $@< / span > < span class = "s2" > "< / span >
< span class = "nb" > exit< / span > < span class = "nv" > $?< / span > < / code > < / pre > < / figure >
2018-10-24 11:53:55 +00:00
< / p >
< p >
It may look messy to a < em > UNIX< / em > guy more experienced than me, but it
works. The < code > getopts< / code > built-in sees if both the < code > -r< / code > and
the < code > -f< / code > flags are used and, if so, it starts
< code > rickroll()< / code > , which opens with < code > xdg-open< / code > that amazing
clip from < em > RickAstleyVEVO< / em > . From line 30 and below, the script checks
if the < code > --force< / code > flag is used instead of < code > -f< / code > .
< / p >
< p >
Let's give execution permissions to the script we have just created:
< / p >
< p >
2016-07-28 13:52:26 +00:00
< figure class = "highlight" > < pre > < code class = "language-bash" data-lang = "bash" > < span class = "c" > # chmod +x /bin/rmAlias< / span > < / code > < / pre > < / figure >
2018-10-24 11:53:55 +00:00
< / p >
< p >
Restart your shell, and enjoy. If you want to test safely, I suggest trying
to run < code > rm -rf< / code > with no folders or a nonexistant one, since this
script stops even these commands.
< / p >
< p >
If you want even more security, you can rename this script to
< code > /bin/rm< / code > 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...
< / p >
2016-07-28 13:52:26 +00:00
< / div >
< / article >
2016-09-13 19:40:45 +00:00
< / main >
< footer class = "site-footer" >
< div class = "icons" >
2018-10-23 14:48:50 +00:00
< a class = "icon" href = "https://github.com/praticamentetilde" >
< i class = "fa fa-github" > < / i > < / a >
< a class = "icon" href = "https://www.reddit.com/user/praticamentetilde" >
< i class = "fa fa-reddit" > < / i > < / a >
2016-07-28 13:52:26 +00:00
< / div >
2018-10-23 14:38:45 +00:00
< h6 class = "author" >
< i class = "fa fa-cc" aria-hidden = "true" > < / i >
Claudio Maggioni
< script >
document.write((new Date()).getFullYear());
< / script > < br >
Content under
< a href = "https://creativecommons.org/licenses/by-nc-sa/4.0/" >
CC BY-NC-SA 4.0< / a >
< / h6 >
2016-07-28 13:52:26 +00:00
< / footer >
2016-09-13 19:40:45 +00:00
< script >
var easter_egg = new Konami();
easter_egg.load("https://www.youtube.com/watch?v=URTcCh6QVwM");
< / script >
< / body >
2016-07-28 13:52:26 +00:00
< / html >