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.

Filter by
Sorted by
Tagged with
0
votes
1answer
21 views

command invocation location is inconsistent with `which` command output

I'm installing protocolbuf on my CentOS 7 box, and after installation, I saw some inconsistency while running the protoc compiler binary: $ which protoc /usr/local/bin/protoc $ protoc bash: /bin/...
5
votes
2answers
1k views

“which” can't find location of executable even though it runs

Background I log into a server to do scientific computations. It runs 'Scientific Linux version 7.4'. In order to get access to different software I have to run a command like 'module load x'. For ...
0
votes
1answer
26 views

What is the difference between `which <command>` and `command -v <command>`?

When I put in which npm, I get /usr/local/bin/npm. When I put in command -v npm, I get /usr/bin/npm. Why is that? What's the difference? man which says which "returns the pathnames of the filenames ...
0
votes
1answer
35 views

How can “which” find commands inside directories where I have no read permissions?

On my work PC, I noticed that the which command seems to be able to find executables in directories, that I have no read permissions for. $ export PATH=/usr/sbin:$PATH $ ls /usr/sbin ls: cannot open ...
1
vote
2answers
98 views

Why is the which command so hard to eradicate? [closed]

I'm coming from places like Why not use "which"? What to use then? and https://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script and am myself a long-...
0
votes
1answer
31 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
69 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
58 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
288 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
174 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
445 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
444 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
46 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 ...
1
vote
1answer
63 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
331 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
138 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
88 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
67 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/...
1
vote
0answers
83 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
44 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
60 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 ...
7
votes
2answers
2k 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
401 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 ...
3
votes
2answers
287 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
176 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
241 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
40 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
84 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
513 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
78 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 $...
30
votes
1answer
4k 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
687 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
50 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
68 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 ...
2
votes
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
3k 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
321 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
545 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
4k 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
384 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
2k 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
87 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/...
7
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
92 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
549 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 ...
7
votes
2answers
26k 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
4k 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
1k 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, ...
348
votes
4answers
48k 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
293 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?