Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

Sometimes I want to know what a command I type into bash actually evaluates to. Usually I can figure out the location of the executable very easily with which.

$ which vim

But what if I've created an alias for vim?

$ alias vim="echo mwahaha"
$ which vim

Hmm, not good. If I suspect something and want to check if vim has been aliased, I know I can type

alias vim

... but if I had an alias vim='vim -p', I would never actually think to check vim aliases because it would still work just fine.

How can I know exactly what a specific command in bash is being evaluated to?

share|improve this question

marked as duplicate by Gilles, slm, Cory Klein, Anthon, jasonwryan Sep 11 '13 at 0:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Cory, please search the site before asking such a basic question. This question has been covered numerous times on the site. – slm Sep 10 '13 at 22:40
Here's a good one: unix.stackexchange.com/questions/10525/… – slm Sep 10 '13 at 22:42
@slm I was actually positive that there was already such a question on the site, but my searches didn't yield such a question - most likely because of my wording. I agree with meta though, that if my search doesn't result in an answer to my question that the question can still be asked, and that these questions improve the site. I also agree that this is a duplicate and should be closed - just not deleted. – Cory Klein Sep 10 '13 at 22:58
@CoryKlein - I 100% agree with you. I've often done extensive searches and not found anything relevant only to have someone else put a duplicate (usually Gilles) on something that I was convinced had none. Duplicates serve an important function to the SE sites in providing paths to the penultimate Q&A's but on something simple as this, I would always bet on the house that there is already a Q&A on it. Just my $0.02's obviously, we always appreciate questions, so it's best to error on the side of asking!!!! – slm Sep 10 '13 at 23:03
@CoryKlein - also my comment was 1/2 directed to Chris who in answering this should've known that this was a duplicate and directed you 8-) – slm Sep 10 '13 at 23:03

Use type, which is internal to bash.

$ type vim
vim is /usr/bin/vim
$ type -p vim
$ alias vim="echo mwahaha"
$ type vim
vim is aliased to `echo mwahaha'
$ type -p vim

There's a good breakdown of the different ways to get information about a command in this answer by Stephane Chazelas. You shouldn't rely on which, even non-maliciously, it doesn't know about your shell's hash lookup table, which can cause problems.

share|improve this answer

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