This tag should be used for questions about the unix command "which", commonly used for determining the absolute pathname of an executable file in the current environment. See "man which".

learn more… | top users | synonyms

71
votes
3answers
4k views

Determining the path of an executable

When looking for the path to an executable or checking what would happen would you enter a command name in a Unix shell, there's a plethora of different utilities (which, type, command, whence, where, ...
36
votes
4answers
4k views

How to use `which` on an aliased command?

Like most users, I have a bunch of aliases set up to give a default set of flags for frequently used programs. For instance, alias vim='vim -X' alias grep='grep -E' alias ls='ls -G' The problem is ...
9
votes
1answer
527 views

What is the best way to detect (from a script) whether software is installed?

I've been frustrated before with differences in output from the which command across different platforms (Linux vs. Solaris vx. OS X), with different shells possibly playing into the matter as well. ...
8
votes
4answers
287 views

Why does the “which” command give duplicate results?

which -a ruby gives me /usr/ruby /usr/ruby /usr/ruby It gives the same path three times. Why does this happen?
8
votes
1answer
477 views

What is the difference between which and where

What is the difference between where and which shell commands? Here are some examples ~ where cc /usr/bin/cc /usr/bin/cc ~ which cc /usr/bin/cc and ~ which which which='alias | ...
7
votes
3answers
870 views

My `which` command may be wrong (sometimes)?

I've compiled the last emacs version from the source code (v24.2) because the version installed on my machine is (quite) old for me (v21.3). I've done the usual: $configure --prefix=$HOME make make ...
6
votes
2answers
214 views

Output of which command used for input to cd

I would like to take the output of a which command, and cd to the parent directory. For example, say I have the following: which someprogram With output: /home/me/somedirectory/someprogram And I ...
5
votes
4answers
166 views

How do I use which(1) with the system's default $PATH?

I would like to use which with the system's default path, ignoring any embellishments from the user's shell configuration files. Motivation I am attempting to write a script to find the system's ...
5
votes
2answers
228 views

What does which's --tty-only option do?

I just realized that my sysadmin has created a global alias for which: alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' The which manpage just says: Stop ...
5
votes
1answer
4k views

How do I get which to show aliases? [duplicate]

Possible Duplicate: How to use which on an aliased command? I'm used to working on systems where which would list aliases, so e.g. if I have an alias like this: alias ...
4
votes
2answers
8k views

How to add home directory path to be discovered by Unix which command?

I have installed node.js at custom location and added the location to the $PATH in .profile file. Hoons-MacBook-Air:npm Eonil$ node --version v0.6.2 Hoons-MacBook-Air:npm Eonil$ which node ...
4
votes
5answers
146 views

How to return the directory of a given executable?

If I want to return the path of a given executable, I can run: which mysql Which returns for example: /usr/bin/mysql I'd like to return only: /usr/bin How can I do that?
4
votes
2answers
646 views

What does '//' mean in return from `which`

I have an executable script test under the full path /home/sawa/foo/bar/test. The directory /home/sawa/foo/bar is within $PATH, and has priority over the default ones including /usr/bin. When I do ...
4
votes
2answers
614 views

xdg-open is installed yet also is not installed

$ xdg-open The program 'xdg-open' is currently not installed. You can install it by typing: sudo apt-get install xdg-utils $ sudo apt-get install xdg-utils Reading package lists... Done Building ...
3
votes
2answers
64 views

How do I know which library and man page will be found first?

With binaries, I can always do which foo to know which binary I am invoking with $ foo, but what about man pages? Is there a way to know the path of the man page will be loaded by default? Similarly, ...
3
votes
2answers
54 views

Using a glob pattern as an argument to “which”

Is it possible to use the which command on a glob pattern to return multiple results? For example, I want to know the full path of all my latex commands. I can try: ...
2
votes
3answers
273 views

Is there an alternative to the `which` command? [duplicate]

If the which command is not available, is there another 'standard' method to find out where a command's executable can be found? If there is no other 'standard' method available, the actual system I ...
2
votes
1answer
36 views

'which' reports one thing, actual command is another [duplicate]

I am running Ubuntu 12.04, which came with Cmake v 2.8.7. I had need for a more current CMake, so I downloaded the source for 12.8.12.1, built, and installed it per directions. The last step, make ...
2
votes
1answer
33 views

Missing 'which' executable on CentOS

We booted up our CentOS (6.4 Final, kernel version 2.6.32.... i686) VM today (running on a Windows machine, yeah I know...) and for some bizarre reason the 'which' binary has gone missing. (Last week, ...
1
vote
1answer
253 views

Why `which tmux` and `sudo which tmux` return 2 different values?

ssh bobby@tony:~$ which tmux /usr/bin/tmux ssh bobby@tony:~$ sudo which tmux ...
1
vote
3answers
585 views

How to determine which executable on my path will be run?

I run which and get the following, brendan$ which python /opt/local/bin/python brendan$ which -a python /opt/local/bin/python /usr/bin/python brendan$ ls -l /opt/local/bin/python lrwxr-xr-x ...
1
vote
2answers
69 views

Switch between two installs of one program

I have two copies of svn on my machine. /usr/local/bin/svn /opt/subversion/bin When I run which svn it states the first is running how can I switch it to the second?
1
vote
1answer
102 views

Find where a bash command is defined or sourced from? [duplicate]

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 /usr/bin/vim But what if ...
1
vote
3answers
606 views

Providing the full path doesn't work but calling just the name of the program does, why?

What am I missing? I can call "rvm" from the command line but not reference the entire path that which rvm says I'm using. Not that it's important, but I stay logged in as "jenkins" the entire time ...
0
votes
1answer
44 views

$PATH environment variable does not seem to be recognized

I've made a fresh install of Debian Wheezy, and installed zsh to it. Few days after, I've done a vanilla installation of TeX Live 2014, so I added the necessary binary paths to my $PATH. Now I started ...
0
votes
1answer
146 views

“which” command difference

What is the difference between (unix-system “which [name]) and which [name] commands. For example when I use the (unix-system “which visual_elite) command I get the following result: ...
0
votes
1answer
263 views

which and find not working to locate ruby.exe path

From the home directory which ruby.exe & find ruby.exe return "no such file or directory" However, I'm able to execute .rb programs in rubymine.