-1

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.

alias
  • 35

1 Answers1

1

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
/bin/ls
$ alias ls='ls --color=auto'   # Step 3 above
$ command -v ls
alias ls='ls --color=auto'
alias
  • 35
  • 1
    aka https://unix.stackexchange.com/a/10532/117549: ( unalias vim; type vim ) – Jeff Schaller Apr 05 '19 at 17:02
  • @JeffSchaller I don't feel, but could feel humiliated. At least now I know :) – alias Apr 05 '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 05 '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 05 '19 at 21:15
  • @JeffSchaller Is this something I can do? I don't see any button like I sometimes do. – alias Apr 05 '19 at 21:18