In this question it is recommended repeatedly that to figure out where an executable is located, one should run command -v file.

I've tried running command -v ls on a few different systems now and I keep getting alias ls='ls --color=auto' (always in Bash).

I have three questions:

  1. What am I missing? How is it that command -v ls helps?

  2. Given that which doesn't work properly (according to the comments and answers to the linked question) and assuming that I'm not missing anything in question 1 and command -v ls does help, how can I know which ls is actually ran?

  3. What is a POSIX compliant way of figuring this out? My examples are in Bash, but I'm hoping for a portable solution. I know about type -P.

  • @JeffSchaller I can't find the answer to 1. or 3. in there.
    – alias
    Apr 5 '19 at 16:06
  • @StephenKitt Please read my comment above.
    – alias
    Apr 5 '19 at 16:06

I believe I've found an answer to all three questions. It's pretty obvious once you see it, but it wasn't obvious for me at all, hence the question.

  1. Remove alias
  2. Run command -v. (See POSIX on this).
  3. Realias if that is one's wish.

For a specific example for those who might not know exactly how to do this, below I apply this process to ls.

$ command -v ls
alias ls='ls --color=auto'
$ unalias ls                   # Step 1 above
$ command -v ls                # Step 2 above
$ alias ls='ls --color=auto'   # Step 3 above
$ command -v ls
alias ls='ls --color=auto'
  • 1
    aka unix.stackexchange.com/a/10532/117549: ( unalias vim; type vim )
    – Jeff Schaller
    Apr 5 '19 at 17:02
  • @JeffSchaller I don't feel, but could feel humiliated. At least now I know :)
    – alias
    Apr 5 '19 at 17:55
  • @JeffSchaller Would you turn that into an answer? I'm an unregistered user in an incognito window and I'm unable to accept my answer for two more days. If no one gives an answer I can accept, this is going to stay unaccepted.
    – alias
    Apr 5 '19 at 20:48
  • If that feels like an Answer to you, then I think the right thing to do is to close this Q as a duplicate of the other.
    – Jeff Schaller
    Apr 5 '19 at 21:15
  • @JeffSchaller Is this something I can do? I don't see any button like I sometimes do.
    – alias
    Apr 5 '19 at 21:18

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