How to see the command attached to a bash alias?

Solution 1:

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.

Solution 2:

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.

Solution 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