Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question

4 Answers 4

up vote 51 down vote accepted

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;
        echo "$REPLY";
        grep --color=auto "$@"
    }
}
share|improve this answer
    
what to do when an alias contains MORE aliases? –  user251046 Jul 26 at 10:34
    
@user251046 keep using type until you hit something other than an alias ... –  geirha Sep 3 at 19:03

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.

share|improve this answer
4  
Or type alias ls to find out what specifically ls is aliased to. –  poolie Feb 7 '12 at 4:10
1  
@poolie Indeed. I think the question was to see all the aliases, though, which is why i did not elaborate further on the alias command. –  Thomas W. Feb 7 '12 at 4:52

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
share|improve this answer
    
have this an equivalent on other distros? –  sepehr Jul 3 at 13:40
    
@sepehr Works on Debian, I assume it's a bash feature and should work on any distribution. –  Oliver Salzburg Jul 3 at 16:15
    
you're right, it works on bash but I have zsh and it doesn't work unfortunately. –  sepehr Jul 4 at 12:46

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.

share|improve this answer
    
bash has no which command. –  geirha Sep 11 at 9:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.