Reputation: 692
I want to find out the file path of commands in Linux e.g., ls
has file path as /bin/ls
. How can I find out the exact path of some commands?
Upvotes: 4
Views: 18197
Reputation: 22237
You did not specify, which shell you are going to use, but I strongly recommend using which
, as it does not necessarily do, what you expect. Here two examples, where the result possibly is not what you expect:
(1) Example with bash, and the command echo
:
which echo
would output /usr/bin/echo
, but if you use the echo
command in your bash script, /usr/bin/echo is not executed. Instead, the builtin command echo
is executed, which is similar, but not identical in behaviour.
(2) Example with zsh, and the command which
:
which which
would output the message which: shell built-in command
(which is correct, but certainly not a file path, as you requested), while
/usr/bin/which which
would output the file path /usr/bin/which
, but (as in the bash example) this is not what's getting executed when you just type which
.
There are cases, when you know for sure (because you know your application), that which
will produce the right result, but beware that as soon as builtin-commands, aliases and shell functions are involved, you need first to decide how you want to handle those cases, and then choose the appropriate tools depending on the kind of shell which you are using.
Upvotes: 1
Reputation: 19743
you can use which
, it give you path of command:
$ which ls
/bin/ls
you can use type
:
$ type ls
ls is /bin/ls
Upvotes: 4
Reputation: 75
Yes you can find it with which
command
which <command>
eg which cat
/bin/cat
Upvotes: 1
Reputation: 311478
You can use the which
command. In case of a command in your $PATH
it will show you the full path:
mureinik@computer ~ $ which cp
/usr/bin/cp
And it will also show details about aliases:
mureinik@computer ~ $ which ls
alias ls='ls --color=auto'
/usr/bin/ls
Upvotes: 1
Reputation: 2683
As pointed out, which <progName>
would do it. You could also try:
whereis -b <progName>
This will list all the paths that contains progName
. I.e whereis -b gcc
on my machine returns:
gcc: /usr/bin/gcc /usr/lib/gcc /usr/bin/X11/gcc
Upvotes: 8