Bash - aliasing unalias

alias, bash, linux, shell

Solution

A commonly used technique to prefix a command with a backslash i.e. `\` to make sure to avoid any aliases and run it from system default path:

Example:

$> alias ps=date
$> ps
Wed Feb 18 12:33:17 EST 2015
$> \ps
 PID TTY           TIME CMD
 615 ttys000    0:00.66 -bash
 621 ttys001    0:07.36 -bash
 913 ttys002    0:01.19 -bash

As you can use running `\ps` runs system default `/bin/ps` while running `ps` runs the aliased command `date`.

Problem

I know that using alias command in bash can define custom functions in bash, and can even overwrite inbuilt functions (for e.g. alias sudo="help" works). Unalias -a can tidy up the mess made with alias command, but unalias can also be aliased (I have run alias unalias="unalias" command successfully, so I guess it works for other commands too - I did not want to mess up the os since it was a public computer). My question is that if I alias the unalias to something else, and then the alias too, can I reset the commands if they are themselves not usable? What happens if I aliased sudo too? For e.g. if I wanted to be a troll and run this command on the machine of a friend of mine ``` alias sudo="clear" && alias unalias="clear" && alias alias="clear" ``` all these commands will be unusable, so I'm sure it will be a hard time to restore the functionality of sudo. Is it possible without reinstalling the OS? (I can think about using ctrl+alt+f1 that switches to a terminal, but I do not know if the aliased stuff is aliased there too. What if I do the same thing there?)

Original source