Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

How to see the command attached to a bash alias?

Writer Andrew Mclaughlin

Suppose I have an alias in the bash shell. Is there a simple command to print out what command the alias will run?

6 Answers

The type builtin is useful for this. It will not only tell you about aliases, but also functions, builtins, keywords and external commands.

$ type ls
ls is aliased to `ls --color=auto'
$ type rm
rm is /bin/rm
$ type cd
cd is a shell builtin
$ type psgrep
psgrep is a function
psgrep ()
{ ps -ef | { read -r; printf '%s\n' "$REPLY"; grep --color=auto "$@" }
}

type -a cmd will show all the commands by that name in order of precedence, which is useful for the ls alias above, where the alias itself calls ls.

$ type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls

This tells you that when you run ls, /bin/ls will be used, and --color=auto will be included in its list of arguments, in addition to any other you add yourself.

7

Just type alias while at the Shell prompt. It should output a list of all currently-active aliases.

Or, you can type alias [command] to see what a specific alias is aliased to, as an example, if you wanted to find out what the ls alias was aliased to, you could do alias ls.

3

I really like Ctrl+Alt+E as I learned from this answer. It "expands" the currently typed command line, meaning it performs alias expansion (amongst other things).

What does that mean? It turns any alias, that might be currently written on the command line, into what the alias stands for.

For example, if I type:

$ ls

and then press Ctrl+Alt+E, it is turned into

$ ls --time-style=locale --color=auto
7

Strictly speaking correct answer is using BASH_ALIASES array, e.g.:

$ echo ${BASH_ALIASES[ls]}
ls -F --color=auto --show-control-chars
5

You could use the which command.

If you set an alias for ls as ls -al and then type which ls, you will see:

ls: aliased to ls -al.

4

At terminal

$ alias | grep ALIAS

Outputs

ALIAS='some_command'

Replace ALIAS with your alias.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy