Bash alias-function that accepts a parameter: “srf” for “sudo rm -rf”

Add the following to your .bashrc file, and “reload” it with either of the following:

  • source ~/.bashrc
  • . ~/.bashrc
   Alias-like function for recursive deletion, with are-you-sure prompt.
   Example call:
      srf /home/jeffy/django_files/rest_tutorial/rest_venv/

   With the following setting, this is *not* added to the history:
       export HISTIGNORE="*rm -r*:srf *"

   - Y/N prompt:
   - Alias w/param:
srf()  {
    #Actual line-breaks required in order to expand the variable.
    read -r -p "About to
sudo rm -rf $1
Are you sure? [y/N] " response
    response=${response,,}    # tolower
    if [[ $response =~ ^(yes|y)$ ]]
        echo -e "sudo rm -rf $1"
        sudo rm -rf "$1";
        echo "Cancelled."

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s