Something adds an undesired path to my PATH
environment variable.
How can I find the culprit?
I've already looked at:
- ~/.bashrc
- ~/.bash_profile
- /etc/bashrc
- /etc/profile
- /etc/environment
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: memory exhausted
. That's funny bash/terminal/terminator isn't able to list all scripts it loads.
*
to \{0,100\}
in regex?
Try:
grep -rF --binary-files=without-match ':/the/undesired/path' / 2> /dev/null
If /the/undesired/path
is $UNKNOWN_VARIABLE_NAME_FOR_THE_UNDESIRED_PATH
or , this will obviously not work.
Note that /home/user/undesired/path
will often be assigned as $HOME/undesired/path
.
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 find
and xargs
, see 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.
/etc/profile.d
? Is there any other software on the system that edits environment variables such as this: github.com/cea-hpc/modules?yum/rpm
.