Aliases in Linux: the alias command

Updated November 1, 2026

An alias is a short name that the shell expands into a longer command.

Common cases

alias ll='ls -lh'        # define an alias
alias                    # list every alias
alias gs='git status'    # another example
unalias ll               # remove an alias

Sample output

$ alias ll='ls -lh'
$ ll
total 4.0K
-rw-r--r-- 1 student student 3 Jul 26 12:10 notes.txt
$ type ll
ll is aliased to `ls -lh'
$ unalias ll
$ ll
bash: ll: command not found

How it works: an alias lives in the shell

The shell expands the alias on its own before it runs a command, so it works only in an interactive session and is invisible to scripts. If you set it on the command line, it disappears when you close the shell. To keep it for good, add the alias ... line to ~/.bashrc. If an alias shadows a real command, run the command by its full path or with a leading \: \ls ignores the alias.

Common mistakes

Spaces around the = break the command, and it looks like success. alias ll = 'ls -lh' first prints alias ll='ls -alF': that is how bash answers a query about the alias ll you already have. Two errors follow, bash: alias: =: not found and bash: alias: ls -lh: not found. No new alias was made, and the first line of output is what convinces you otherwise.

sudo does not see aliases: sudo ll answers sudo: ll: command not found. Your shell does the expanding, and sudo receives the plain word ll and looks for a file by that name in PATH. The fix is the line alias sudo='sudo ' with a trailing space: the space makes bash expand the next word too.

An argument is appended at the end of the line, not where $1 sits. The alias alias mkcd='mkdir $1 && cd $1' looks like it works, but mkcd /tmp/newdir answers mkdir: missing operand: $1 is empty and the path stuck to the very end. An alias can only put text at the front of a command; for arguments in the middle you need a shell function.

Used in

You need this in the lesson The shell environment. The theory is the chapter The shell environment and configuration.

See also

The ~/.bashrc file.

Try it

Open the sandbox: a real throwaway Linux terminal in your browser. Run the commands above by hand - the container is deleted when you leave.