I noticed the Linux shell command 'which' does NOT show an executable file although it is alredy on the search path.

More specifically, my $PATH includes '~/.local/bin'; an executable file is ~/.local/bin/charm. 'which charm' returns nothing although I can run 'charm' with no problem. I am using Ubuntu 16.04 and bash

The issue depends on Linux distribution. If I log on to another machine of RHEL 6.10, the command 'which charm' works fine for the same executable.

The issue may also relate to nfs mount. On Ubuntu 16.04, the command 'which' seems to work fine for executables on local disks, for example, 'which which' shows '/usr/bin/which', but it does NOT find execuatables on nfs paths, which is the case for my '~/.local/bin'.

I searched online but couldn't find exaplaination. Is there a way to make the command 'which' under Ubuntu show all mached executables on path including nfs mounts?



Your $PATH includes ~/.local/bin where tilde hasn't been expanded. bash will expand it on the fly each time, but which (at least on Ubuntu) or sh won't.

If you want which to see the executables in ~/.local/bin you need to make sure tilde is expanded before the PATH variable gets it. The string ~/.local/bin is probably added to your PATH by one of the startup scripts. Find the relevant line and fix it according to the examples below.

Note: first run each of the following examples in a fresh shell, so you can observe (echo "$PATH") how it changes the variable each time independently.

This won't expand tilde character (because of quoting):


This will:


Or this:


Rules of tilde expansion are somewhat complicated. Consider using $HOME. Examples:


To fix an already established PATH variable, replace ~ in it with the content of $HOME:

  • Thank you Kamil! Either removing the quotation mark or manually expanding the tilde solved the problem. Great explaination! so this has nothing to do with nfs, but does have some dependency on the Linux distribution. – Lin May 13 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.