Saturday, 12 January 2019

linux - What is the unix command to find out what executable file corresponds to a given command?


For example, if passed ls as input it should tell me that /bin/ls will run if run ls on the command-line.



Answer



The command to use varies from shell to shell.


Only a shell built-in will tell one correctly what the shell will do for a given command name, since only built-ins can fully know about aliases, shell functions, other built-ins, and so forth. Remember: Not all commands correspond to executable files in the first place.




  • For the Bourne Again shell, bash, the built-in is the type command:


    $ type '['
    [ is a shell builtin


  • For the Fish shell, fish, The type builtin works similarly to bash. To get just the path to an executable, use command -v:


    $ type cat
    cat is /bin/cat
    $ command -v cat
    /bin/cat


  • For the Korn Shell, ksh, the built-in is the whence command — with type initially set up as an ordinary alias for whence -v and the command built-in with the -v option equivalent to whence:


    $ whence -v ls
    ls is a tracked alias for /bin/ls


  • For the Z Shell, zsh, the built-in is the whence command, with the command built-in with the -v option equivalent to whence and the built-ins type, which, and where equivalent to whence with the options -v, -c, and -ca respectively.


    $ whence ls
    /bin/ls


  • For the T C Shell, tcsh, the built-in is the which command — not to be confused with any external command by that name:


    > which ls
    ls: aliased to ls-F
    > which \ls
    /bin/ls




No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...