Michele Pratusevich

mprat@alum.mit.edu

Back to the Miscellaneous project page.

October 26, 2018

Protecting Yourself Against rm

Those who use the command-line on GNU/Linux operating systems know and love rm. But it also comes with so much power! No one wants to accidentally rm -rf the company data. To prevent myself from doing this on our data server, I aliased rm to something more sensible.

First, I created a shell script ~/are_you_sure_rm.sh in my home directory. The file was pretty simple:

#!/bin/bash

echo "You just tried to do rm.
If you really meant to do so, then type /bin/rm followed
by what you want to do. It will be unprotected.
It is recommended you do /bin/rm -i for interactive mode."

Next, I made it executable:

chmod +x ~/are_you_sure_rm.sh

Lastly, I added an alias for rm to the native shell by adding this line to my ~/.bash_aliases file.

# make sure to prompt on every removal of a file
alias rm="~/are_you_sure_rm.sh"

After logging out and back in, my new superpower is activated.

Now every time I try to rm something when SSHed into the company data server, my shell warns me! Amazing!

comments powered by Disqus

All Posts about Miscellaneous

2019 April 18 -- Lasercutter Memes

2018 October 26 -- Protecting Yourself Against rm

2018 September 3 -- Why I Left Amazon

2018 August 25 -- Blogging with Jupyter for Learning Julia Part 2

2018 August 17 -- Favorite Podcasts 2017-2018

2017 March 18 -- Blogging with Jupyter for Learning Julia

2017 February 15 -- Favorite Podcasts 2016-2017

2015 September 8 -- Installing Zim Wiki on OSX

2015 February 5 -- Word Frequency in the King James Bible

2014 February 13 -- A Fictional Middle East

2013 June 6 -- MIT Graduation Cap

2011 April 28 -- Playing Zork on Linux