Exercise
Aliasing Away Typos Exercise
Task
Turn a typo you keep making into a working command, and a dangerous command into a safer one, in every shell from now on.
- Hosts
-
workstation, thenservera
-
List the aliases the shell already defines
alias -
Alias a typo you make often
Move somewhere with something to list, confirm the typo fails, then define the alias.
cd /etc sl alias sl='ls' sl -
Bypass an alias once
An alias can shadow a real command. Make
rmask first, then answernso the file survives.cd ~ alias rm='rm -i' touch scratch_file.txt rm scratch_file.txtA backslash runs the real command, with no prompt.
\rm scratch_file.txt ls scratch_file.txt -
Confirm the aliases are gone in a new session
Log out of
serveraand log back in.exit ssh servera alias sl -
Put them in ~/.bashrc.d/aliases
Aliases could go straight into
~/.bashrc, but they are easier to find in a file of their own. The directory does not exist yet, so create it.mkdir -p ~/.bashrc.d vim ~/.bashrc.d/aliasesalias sl='ls' alias rm='rm -i'exit ssh servera alias sl