Skip to main content

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
4 votes
2 answers
970 views

Does any implementation of `which` output "no" when executable cannot be found?

I am reading the source code of the Maven wrapper written for the Bourne shell. I came across these lines: if [ -z "$JAVA_HOME" ]; then javaExecutable="$(which javac)" if [ ...
Stefan van den Akker's user avatar
-2 votes
1 answer
100 views

How to trim directory from which output without basename?

For a shell script I need to call an executable by name, regardless of the path leading there; thus far I know this code reports the right name: tmpprog=`which program` prog=${tmpprog%%*/} if $prog=&...
jarnosz's user avatar
  • 200
2 votes
0 answers
64 views

'which' behaves inconsistently on different machines - Why the difference?

My company has multiple servers that were setup to be identical. After using dev32 for several weeks, which stopped functioning. I go to dev35 and get similar behavior -- works for several weeks then ...
JB Looney's user avatar
0 votes
1 answer
45 views

What a linux command take the result of "which" command as an argument and list the configuration file paths related to the command we gave to which?

I can't recall that command and I can't even find it in Google. It's just killing me. The usage of the command is like: <that command> `which bash` The output looks like: /etc/skel/.bash_logout ...
Maksim Orlov's user avatar
0 votes
0 answers
161 views

which wget returns error: /usr/bin/env: «node»: No such file or directory

I uninstalled nodejs the other day and now for some reason when I access it I get the error that node is not found. The argument of the which command can be anything. > which wget ...
Daniil Screpchenko's user avatar
0 votes
1 answer
235 views

Why isn't `which ls | file` working?

I would like to use the result of which ls and see the file type using file. However, when I type in which ls | file it doesn't work. When I try to do file < which ls, that doesn't work either. Any ...
Grateful's user avatar
  • 113
5 votes
1 answer
596 views

'which' is unable to find command even though it is definitely installed

I have recently installed the cryptsetup. I've double checked with sudo apt-get install cryptsetup. Reading package lists... Done Building dependency tree... Done Reading state information... Done ...
rful7877's user avatar
2 votes
0 answers
199 views

command to find out what package manager installed this executable/file

I am looking for a script that would tell me what exactly installed a binary (or other asset) on a (Debianish) Linux system. Nowadays there are so many package managers (snap, flatpak, pip, npm, ...
allanlaal's user avatar
  • 852
1 vote
1 answer
291 views

which command returning undocumented things

I am trying to locate which conda executable I am using. For this, I want to use which command. As per man pages, it should return the path of the executable. Instead it returns some bash function (...
asdf's user avatar
  • 111
0 votes
0 answers
15 views

I have a situation in which "which -a python" is not showing execution order when run on CentOS 6 with Python 3.7 [duplicate]

Does anyone know where to begin with debugging this? [chuck@vmlnx-tacx32 openssl-1.1.0h]$ which -a python /usr/local/bin/python /usr/bin/python [chuck@vmlnx-tacx32 openssl-1.1.0h]$ /usr/local/bin/...
seanmus's user avatar
  • 141
4 votes
2 answers
11k views

sh: which: line 1: syntax error: unexpected end of file; sh: error importing function definition for `which'

We are running: Red Hat Enterprise Linux release 8.5 (Ootpa). We allow the server to update weekly using "yum -y update". We recently began receiving the following errors when executing ...
Greg Sims's user avatar
  • 191
0 votes
1 answer
86 views

Where is the executable?

I have this command that I run. Let's call it foo. I can execute foo without specify the full path to foo like so: $ foo missing args I suspect foo is a bash script so I want to look at the source ...
Red Cricket's user avatar
  • 2,213
0 votes
1 answer
188 views

What is which command output ordering? [closed]

In bash I see which returns the paths in order, but in zsh it has different ordering. I now primarily use zsh, how can I get proper output ordering of which in zsh? Why is it different? I expected the ...
Michael Ozeryansky's user avatar
0 votes
1 answer
325 views

output of which perl is /bin/perl instead of /usr/bin/perl

Hi I'm running Redhat Server 7.9 and running into an interesting issue. If I type which perl, I get /bin/perl, but it should be /usr/bin/perl. The same for git. This same machine would print /usr/ ...
alpaca28's user avatar
7 votes
5 answers
2k views

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 <http://gnu.org/...
WMC's user avatar
  • 171
2 votes
2 answers
524 views

What's the difference between two uname files

I have to find the uname file on a Debian machine, check from which package it is and delete it. When I use which to find it, I get /usr/bin/uname. When I try to check it by dpkg -S uname there is no ...
MisterWM's user avatar
0 votes
1 answer
126 views

command -v <foo> returns wrong result after overwriting <foo> as function

I have the following functions in my .bashrc which just creates a python project with venv and creates gitignore and readme, after I initialise with git as: git init python ...
Rakib Fiha's user avatar
1 vote
1 answer
4k views

"which" command not work in shell script with #!/bin/bash but work with #!/bin/zsh [duplicate]

I have a sh file: #!/bin/bash echo $PATH date pwd which nano First three lines work with both #!/bin/bash and #!/bin/zsh but I got a ./script.sh: line 5: which: command not found with bash, but zsh ...
Hai Hoang's user avatar
  • 113
1 vote
1 answer
111 views

adding script to which command

I have a script/tool in linux /full/path/here/grabber. I want to know how I will be able to use which on it. So every time i want to use it, I can just execute grabber instead of having to call its ...
niceone99's user avatar
1 vote
1 answer
183 views

Which binary would be run when we have multiple installations?

I wanted to set gsettings as /usr/bin/gsettings so I created an alias. But I am not sure if that works: $ type gsettings gsettings is aliased to `/usr/bin/gsettings' gsettings is /home/linuxbrew/....
Porcupine's user avatar
  • 2,056
0 votes
0 answers
23 views

Why same paths are shown when running `which -a` command [duplicate]

When I run which -a psql the result shows three same paths. /usr/local/bin/psql /usr/local/bin/psql /usr/local/bin/psql I can run the command psql without a problem. I just want to know why this ...
ironsand's user avatar
  • 5,265
1 vote
0 answers
24 views

The command `which` does not show the path of command correctly [duplicate]

My system is RHEL 7.5 and the output of vim --version as below: me@localhost:~/tmp$ vim --version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 9 2019 03:17:15) I want to use vim 8 so I ...
Yves's user avatar
  • 3,331
1 vote
1 answer
1k views

How to map to a different binary for the same program on linux/mac?

Suppose which R returns /opt/anaconda3/bin/R, and suppose I have other R binaries in other locations, and I want a different R binary to run when I type R. How can I make that happen without ...
stevec's user avatar
  • 191
2 votes
0 answers
2k views

whereis Gstreamer - located in two paths - causing issues

Gstreamer doesn't run as expected when executed from the command line. It turns out all the plugins I am installing are defaulting to one location while when I'm running gstreamer its opening from ...
Lewis Morris's user avatar
0 votes
1 answer
234 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/...
Chen Xie's user avatar
  • 103
6 votes
2 answers
2k 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 ...
Onye's user avatar
  • 163
1 vote
1 answer
543 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 ...
temporary_user_name's user avatar
0 votes
1 answer
48 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 ...
kdb's user avatar
  • 209
2 votes
2 answers
128 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-...
tripleee's user avatar
  • 7,808
1 vote
1 answer
80 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 ...
OJFord's user avatar
  • 1,995
0 votes
1 answer
551 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/...
Richard's user avatar
  • 3,503
1 vote
3 answers
154 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. ...
haugstve's user avatar
0 votes
2 answers
447 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 ...
Catfish's user avatar
  • 75
0 votes
2 answers
449 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/...
user977828's user avatar
0 votes
0 answers
693 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/...
Dims's user avatar
  • 3,285
2 votes
1 answer
2k 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 ...
Yves's user avatar
  • 3,331
1 vote
1 answer
175 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 ...
Jethro's user avatar
  • 113
1 vote
1 answer
149 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; ...
Alexander Mills's user avatar
-1 votes
1 answer
691 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@...
yael's user avatar
  • 13.4k
3 votes
1 answer
885 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 ...
jalanb's user avatar
  • 588
0 votes
1 answer
806 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....
Town Tattle's user avatar
4 votes
0 answers
134 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/...
JayMech's user avatar
  • 41
1 vote
0 answers
333 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 ...
Geoffrey Wiseman's user avatar
2 votes
1 answer
1k 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="~/...
Alec's user avatar
  • 507
0 votes
1 answer
106 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 ...
Qwertie's user avatar
  • 1,314
22 votes
2 answers
11k 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 ...
shirish's user avatar
  • 12.5k
1 vote
2 answers
665 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 ...
Ole Tange's user avatar
  • 35.8k
3 votes
2 answers
525 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}`; ...
Marecky's user avatar
  • 247
1 vote
1 answer
1k 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 /...
Richard's user avatar
  • 3,503
1 vote
2 answers
804 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?
joachim's user avatar
  • 7,747