Where to start First steps track · 15 stages
Linux Labs

alias — command shortcuts

cheat sheet · bash https://lab.dimsanych.ru/en/wiki/alias/

Cheat sheet

  • alias ll='ls -lah' create
  • alias list
  • unalias ll remove
  • \cmd / command cmd run the original, bypassing the alias
  • echo "alias ..='cd ..'" >> ~/.bashrc make it permanent

Options

alias barely has any flags: it takes name='command' pairs. The useful ones are -p (print the list in a form suitable for re-execution, same as with no arguments) and unalias -a (remove every alias of the current session at once).

An alias created on the command line lives only until you close the terminal. To make it permanent, add it to ~/.bashrc (per user):

bash
echo "alias ll='ls -lah'" >> ~/.bashrc
source ~/.bashrc              # apply in the current session (or open a new terminal)

Ubuntu's default system aliases live in ~/.bash_aliases (sourced by ~/.bashrc). More on profiles and $PATH — env-vars.

An alias does not take arguments the way a beginner expects: alias gl='git log' gets substituted before the rest of the line, so gl -5 works (it becomes git log -5), but an alias cannot insert an argument in the middle of a command — that needs a shell function (see bash-scripting).

Loading…