Questions tagged [which]

The unix command "which" is commonly used to search for an executable in the PATH, even though it is not very good at this job.

which is a shell command that searches for an executable in the command search path ($PATH — see ) by name. Use this tag for questions about the which utility and about other commands that perform a similar function.

which has many pitfalls. It is usually more reliable to use command -v or type instead.

Further information

90 questions
478
votes
5 answers

Why not use "which"? What to use then?

When looking for the path to an executable or checking what would happen if you enter a command name in a Unix shell, there's a plethora of different utilities (which, type, command, whence, where, whereis, whatis, hash, etc). We often hear that…
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
97
votes
7 answers

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 that if I want to use which to see where my…
Adrian Petrescu
  • 1,077
  • 1
  • 9
  • 10
50
votes
2 answers

Bash remembers wrong path to an executable that was moved/deleted

When I do which pip3 I get /usr/local/bin/pip3 but when I try to execute pip3 I get an error as follows: bash: /usr/bin/pip3: No such file or directory This is because I recently deleted that file. Now which command points to another version of…
spiderface
  • 615
  • 1
  • 6
  • 8
23
votes
3 answers

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 install Now I am testing emacs and realized that…
yves Baumes
  • 569
  • 1
  • 4
  • 11
20
votes
2 answers

how is whence different than which?

I read `which`, but all but I cannot really get the difference. I am running zsh 5.4.2 on 64-bit debian-buster. Both which and whence are shell-builtins . Can people point out where whence would be more appropriate than which and vice-versa…
shirish
  • 11,967
  • 27
  • 107
  • 190
18
votes
1 answer

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 | /usr/bin/which --tty-only --read-alias --show-dot…
nikhil
  • 992
  • 2
  • 10
  • 16
13
votes
3 answers

Is there an alternative to the `which` command?

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 face currently is a bare Android emulator with an…
n611x007
  • 957
  • 3
  • 11
  • 21
12
votes
2 answers

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. $ node --version v0.6.2 $ which node $ echo $PATH /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:~/Unix/homebrew/bin $ cat ~/.profile export…
Eonil
  • 4,607
  • 11
  • 30
  • 30
11
votes
2 answers

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 dependency tree Reading state information...…
nacnudus
  • 253
  • 1
  • 2
  • 8
10
votes
2 answers

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 would like to cd to the directory that someprogram…
well actually
  • 3,045
  • 5
  • 20
  • 11
10
votes
1 answer

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. type has been suggested as a better alternative,…
iconoclast
  • 9,057
  • 12
  • 56
  • 95
9
votes
4 answers

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?
Aswini
  • 101
  • 2
7
votes
1 answer

Find where a bash command is defined or sourced from?

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 I've created an alias for vim? $ alias vim="echo…
Cory Klein
  • 18,391
  • 26
  • 81
  • 93
7
votes
2 answers

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 processing options on the right if not on tty. What does…
RSFalcon7
  • 4,367
  • 6
  • 30
  • 56
7
votes
5 answers

IFS=',' /usr/bin/read vs IFS=',' read

Context $ bash --version GNU bash, version 4.4.19(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software; you are…
WMC
  • 171
  • 2
1
2 3 4 5 6