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, then servera
  1. List the aliases the shell already defines

    alias
  2. 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
  3. Bypass an alias once

    An alias can shadow a real command. Make rm ask first, then answer n so the file survives.

    cd ~
    alias rm='rm -i'
    touch scratch_file.txt
    rm scratch_file.txt

    A backslash runs the real command, with no prompt.

    \rm scratch_file.txt
    ls scratch_file.txt
  4. Confirm the aliases are gone in a new session

    Log out of servera and log back in.

    exit
    ssh servera
    alias
    sl
  5. 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/aliases
    alias sl='ls'
    alias rm='rm -i'
    exit
    ssh servera
    alias
    sl