Skip to content

The alias command

The alias command makes a short name for a longer command: after alias ll='ls -alF'…

The alias command makes a short name for a longer command: after alias ll='ls -alF', typing ll runs ls -alF.

Taught in Intermediate, lesson 25

A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.

Usage

alias NAME='COMMAND'
alias [NAME]...

Make a short name for a longer command. Defines a shortcut: after alias ll='ls -alF', typing ll runs ls -alF, and anything you type after it is added on the end. With no arguments alias lists every alias; with a name it shows that one. Aliases last until the terminal closes, so to keep one, add the alias line to the file ~/.bashrc, which bash reads every time a terminal opens (run source ~/.bashrc to load it now). The practice terminal reads ~/.bashrc when it starts, too. Use single quotes around the command, and no spaces around the =.

How to use alias

Make an alias

No spaces around =, and quotes around the command. Words you type after the alias go on the end.

alias c='clear'
alias lt='ls -lt' && type lt
lt is aliased to `ls -lt'

List your aliases

The practice terminal’s ~/.bashrc sets two, as many Linux systems do.

alias
alias la='ls -A'
alias ll='ls -alF'

Keep an alias for next time: ~/.bashrc

Aliases last until the terminal closes. Add the line to ~/.bashrc, which bash reads in every new terminal, and run source ~/.bashrc to load it now.

echo "alias gs='git status'" >> ~/.bashrc && source ~/.bashrc && alias gs
alias gs='git status'

Remove an alias, or skip it once

unalias removes one. A backslash in front of the name, as in \ls, runs the real command just this once.

unalias la

More examples

alias ll='ls -alF'
A shortcut for a long listing
alias rm='rm -i'
Make rm ask first (a common safety alias)

Questions about alias

Where do I put aliases so they stay?

In ~/.bashrc (or ~/.zshrc if you use zsh). Every new terminal reads it; run source ~/.bashrc to use the change straight away.

Can an alias take arguments in the middle?

No. An alias only replaces the first word, and the rest of the line goes on the end. For anything more, write a shell function.

How do I see what an alias does?

Type alias name, or type name, which also tells you whether a name is an alias, a builtin or a program.

Learn it step by step

Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.