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
0answers
16 views

Find a file in XDG directories

Today I was looking for all the mimeapps.list files in my system. Essentially one should test the following files: $XDG_CONFIG_HOME/mimeapps.list $XDG_CONFIG_DIRS/mimeapps.list $XDG_DATA_DIRS/...
1
vote
1answer
28 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 ...
1
vote
1answer
37 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/....
0
votes
0answers
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 ...
1
vote
0answers
19 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 ...
0
votes
1answer
26 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 ...
2
votes
0answers
60 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 ...
0
votes
1answer
36 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
33 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
40 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 ...
2
votes
2answers
108 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
33 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
99 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
62 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
344 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
242 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
494 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
698 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
47 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
68 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
410 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
181 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
141 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
91 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
104 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
71 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
66 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 ...
9
votes
2answers
3k 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
463 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
323 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
221 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 /...
1
vote
2answers
317 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
44 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
97 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
1answer
644 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
83 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 $...
34
votes
1answer
5k 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
786 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
52 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
70 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
4k 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
336 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
705 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?
2
votes
4answers
441 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
89 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
4k 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 ...