Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
1answer
20 views

POSIX command for `which --all`, to list all on PATH not just first?

Many shells have an --all flag to which: --all, -a Print all matches in PATH, not just the first But which is not POSIX-compliant; shellcheck points us at command -v. command however has ...
0
votes
1answer
36 views

Why is `which <command>` not picking up aliases? [duplicate]

I'm on OSX and if I run python --version in a bash shell, I get this: $ python --version Python 3.7.3 But the which python command appears to be pointing to version 2.7. $ which python /usr/local/...
1
vote
3answers
47 views

How do I control which command is when i type python in the shell

I use anaconda as a way to handle virtual environments. This means I have multiple version of python installed. I experience that the wrong python version starts when I run python from the shell. ...
0
votes
2answers
218 views

Syntax error near unexpected token 'which'

I'm trying to script something in OS X Automator and i ultimately want to send the output of which npm to <npm> install and i'm getting the error Syntax error near unexpected token 'which' Any ...
0
votes
2answers
67 views

content from pwd and which failed with sed to be replaced [duplicate]

I have a file which has the following content: BWA='/software/bwa/bwa-0.7.12/bwa' SAMTOOLS='/software/samtools/samtools-1.3.1/samtools' The above tools are on my computer: which bwa => /work/...
0
votes
0answers
330 views

Symbolic link to python 3.6 is ignored

How can the following be? dims@pterosaur:~$ ls -l /usr/local/bin/python3 lrwxrwxrwx 1 root root 18 Aug 15 12:18 /usr/local/bin/python3 -> /usr/bin/python3.6 dims@pterosaur:~$ which python3.6 /usr/...
1
vote
1answer
203 views

Why can't I which pushd

I've been using pushd and popd for a long time while writing bash script. But today when I execute which pushd, I get nothing as output. I can't understand this at all. I was always thinking that ...
1
vote
1answer
41 views

Which is not searching full $PATH

If I run sudo which abc I would expect it to search the superusers $PATH for the program 'abc', but it looks like it only searches a subset. I can see this by running sudo echo $PATH and comparing ...
0
votes
0answers
19 views

python pip: “type -a” shows more alternatives, how to change

I installed a side version of python following these nice how-to how-to-install-latest-python-on-centos python is fine, the centos 6.9 shipped version (2.6.6) is preserved : type -a python python ...
1
vote
1answer
59 views

Installing command line tool if it's not in the PATH

I have this bash function which I am trying to use to install a command line tool if it's not already in the PATH: ncf(){ if ! type -f ncf &> /dev/null || ! which ncf &> /dev/null; ...
-1
votes
1answer
255 views

Command which do not locate the real path of command

We have a RHEL 7.x with Hortonworks (HDP) installed and need an advice why we get on which command: no hadoop in ... The Hadoop client is installed under /usr/bin and from env we get [root@...
1
vote
1answer
104 views

Why is the “wrong” executable being run? [duplicate]

I am trying to run ipython from the bash (version 4.4.19) command line. As a Python developer, I have various installations of ipython at various versions in various virtualenvs' paths, and so it is ...
0
votes
1answer
74 views

how is it possible that which -a shows two paths?

When I execute which -a python I get two paths: /home/autumn/anaconda3/bin/python /usr/bin/python If I delete the directory ~/anaconda3 the first link to the python binary automatically vanishes....
2
votes
0answers
54 views

“which” command doesn't match program being executed [duplicate]

I was trying to install a newer version of curl and when I ran: curl -V, the version number didn't change. After running which curl, it displayed the path of the newly installed version: /usr/local/...
0
votes
0answers
53 views

Which and whereis fail to find command?

Why is it sometimes that which and whereis fail to find a command? e.g. $ awswl -bash: /Users/geoffrey/Library/Python/2.7/bin/awswl: No such file or directory $ which awswl $ whereis awswl $ I ...
2
votes
1answer
32 views

Command 'which' not showing output for custom PATH locations

Scenario I have a ProductivityScripts project on GitHub, and when I install Linux (Debian 9), I add this folder to PATH for ease of use. I.e., I add the following line to ~/.bashrc: export PATH="~/...
0
votes
1answer
56 views

Why does gnu which show a script instead of a file path

I encounterd the following output while using which [user@localhost ~]$ which gem gem () { \typeset result; ( \typeset rvmrc; rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc"); if [[ -n ...
0
votes
2answers
586 views

how is whence different than which? [duplicate]

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 ...
1
vote
2answers
290 views

`which` for SunOS 5.10 [duplicate]

I have (normal user) access to a SunOS 5.10 machine. /usr/bin/which is broken (it blocks). Clearly something is wrong on the system, but not having root access limits drastically what I can do. I ...
2
votes
2answers
219 views

How to use which command in Crontab?

I would like to make crontab run this script as a regular user: #!/usr/bin/env bash PIDFILE=wp-content/uploads/sphinx/var/log/searchd.pid if ! test -f ${PIDFILE} || ! kill -s 0 `cat ${PIDFILE}`; ...
0
votes
1answer
94 views

Why doesn't “export” overwrite existing values?

Why isn't export python=/usr/local/bin/python2.7 changing the path to python? I am baffled by the following: $ which python /usr/bin/python $ export python=/usr/local/bin/python2.7 $ which python /...
0
votes
2answers
158 views

how do I get the 'which' command to resolve symlinks?

I've symlinked a script file into my ~/bin, and when I do which foo the output is: /Users/me/bin/foo Is there a way to have this resolve the symlink and show me the real file?
0
votes
1answer
37 views

Command run is not the one returned by the command `which` [duplicate]

$ which doxygen /home/gauthier/bin/doxygen $ $(which doxygen) -v 1.8.13 $ doxygen -v 1.8.11 # <- ??? $ doxygen error: Doxyfile not found and no input file specified! Doxygen version 1.8.11 ...
2
votes
1answer
74 views

Linux/bash does not execute the executable that “which” tells me [duplicate]

Observation: I have an executable named foo, located in /b/foo. It is compiled against an old header of a dynamic library, causing it to segfault when executed: $ foo Segmentation fault. // Expected ...
1
vote
0answers
333 views

Why I cannot find (using which) usermod as a regular user in RHEL7

Any ideas why the which command is unable to find the usermod command in rhel 7. Here is what I did (and corresponding output) [ec2-user@ip-10-0-4-109 ~]$ echo $PATH /usr/local/bin:/usr/bin:/usr/...
0
votes
1answer
62 views

basic linux executable path does not show up [duplicate]

I am trying to find the path of basic commands like ls or cd using which command. I see the path for ls but not for cd. Of course both the commands work fine. Any idea? $ which ls /bin/ls $ which cd $...
0
votes
0answers
35 views

bash insist looking for executable in the wrong PATH directory [duplicate]

I have an executable hub, which previously lived under ~/bin, but is now under a different location, specifically ~/git/gopath/bin/hub. Both locations are on the path, but under my current terminal ...
25
votes
1answer
2k views

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 ...
1
vote
1answer
532 views

Shell script for kill command

I'm following a tutorial on using text editors and one exercise was to make a "safer" kill command script. I made a ~/bin directory. Then made the following kill command script called ekill. #!/bin/...
0
votes
1answer
44 views

Correcting the installed path in MacOSx

I have installed a software in my MacOsX called Plumed as a prerequisite for another software called GROMACS. Process of installation for Plumed is pretty standard. ./configure --prefix=Users/...
0
votes
2answers
55 views

Command which that isn't in norm

I have this example cp `which mv` rename In instruction of my homework is, that this command isn't in norm and replace the command with different example that does do exactly the same. My question ...
1
vote
3answers
1k views

Where is `exit` defined?

Suppose I want a bash command to do something extra. As a simple example, imagine I just want it to echo "123" before running. One simply way to do this would be to alias the command. Since we ...
0
votes
1answer
2k views

why Whereis not able to show command path, while which is working correctly? [duplicate]

I have created a executable bash shell script file command. I added directory path of my custom command to $PATH variable, but whereis not showing the command path but which shows correctly. I am ...
1
vote
1answer
267 views

Would like to change directory to the result of which function [duplicate]

The which function returns the full path to some other function, if I'm not mistaken. $ which ls # => /bin/ls But if I wanted to the directory the function is in, how would I do that? I'm ...
3
votes
2answers
371 views

How do I find the actual binary/script using 'which' in zsh? [duplicate]

In zsh, when I enter which git it shows: git: aliased to noglob git How do I find out which git binary it actually invokes? (eg: /usr/bin/git vs ~/bin/git). Basically I want to bypass the aliases ...
1
vote
2answers
3k views

Why do I have double slash here?

$ which mycommand /home/t/program_files/document/other edits//mycommand Why do I have double slash // here?
1
vote
4answers
312 views

Can I use which command on aliases? [duplicate]

Example: I have alias chrome='google-chrome'. I want which chrome to return the same thing which google-chrome returns, i.e.: /usr/bin/google-chrome Is that possible?
3
votes
1answer
1k 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 ...
3
votes
2answers
80 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: [lucas@lucas-ThinkPad-W520]/home/...
6
votes
3answers
3k 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
91 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 ...
5
votes
4answers
460 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 ...
6
votes
2answers
21k 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
1answer
3k 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 I'...
6
votes
1answer
853 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, ...
308
votes
4answers
39k views

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, ...
4
votes
5answers
270 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?
3
votes
2answers
177 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, ...
6
votes
2answers
924 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 ...
8
votes
4answers
347 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?