Something adds an undesired path to my
PATH environment variable.
How can I find the culprit?
I've already looked at:
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
This maybe an overkill, and you should (of course) attempt to find it by tracing the order of running scripts, but there are times when that tree becomes way to difficult to parse. So it is possible to simply grep for it:
grep --regexp='PATH=.*/path/that/you/try/to/find' --binary-files=without-match -r /
Please note, that this is a very long process, and your harddrive will be going wild throughout (you are basically reading every text file that you have).
grep -rF --binary-files=without-match ':/the/undesired/path' / 2> /dev/null
$UNKNOWN_VARIABLE_NAME_FOR_THE_UNDESIRED_PATH or , this will obviously not work.
/home/user/undesired/path will often be assigned as
Run the same without
: to also get variable assignments:
grep -rF --binary-files=without-match '/the/undesired/path' / 2> /dev/null
If that doesn't work, find all
PATH assignments and filter manually:
grep -rwF --binary-files=without-match 'PATH=' / 2> /dev/null
Separate file finding and searching with
man pages for each.
sudo find / -type f -print0 | \ xargs -0 --no-run-if-empty \ grep -l 'PATH'
to list all filenames that mention PATH. Append
| xargs less
to look at the files.
One can't search for
/some/deep/path/bin, because it could be expressed as
$SDP/bin, for all we know.