用bash清理$ PATH

mba*_*ows 8 bash path

我的路径有很多很久以前由脚本添加的条目.他们不是我的.bashrc,.bash_profile.bash_login.

我担心重置我的路径.bashrc会产生不良的长期结果.有没有办法找到添加到我的路径的地方并手动删除它们?事物是总是按文件添加还是路径缓存在某个地方?如果是后者,是否容易清理?

gav*_*koa 14

找到最简单的方法修改了PATH是运行:

  $ bash --login -i -xv 2>&1 | grep ' \. '

比如我得到了:

+ . /etc/profile.d/bash_completion.sh
        . /etc/bash_completion
++ . /etc/bash_completion
+++ . /etc/bash_completion.d/abook
+++ . /etc/bash_completion.d/ant
+ . /etc/profile.d/lapack0.sh
+ . /etc/profile.d/openssl.sh
+ . /etc/profile.d/qt3-devel.sh
+ . /etc/profile.d/tetex-profile.sh
+ . /etc/profile.d/xinit.sh
+ . /etc/bash.bashrc

...


Jen*_*ens 7

你不应该让一些随机的系统管理员决定你的PATH中的内容,你应该将它设置为你需要的PATH.你开始

# POSIX way of getting the system's PATH to POSIX tools:
PATH=$(getconf PATH)   # Or /usr/bin/getconf PATH.
Run Code Online (Sandbox Code Playgroud)

其次是您需要的任何东西,例如

PATH="$PATH:/usr/local/bin"
PATH="$PATH:/usr/local/sbin"
PATH="$PATH:$HOME/bin"
Run Code Online (Sandbox Code Playgroud)

把它放在你的shell .profile或等价物中.请注意,出于安全原因,您希望.PATH中存在全局可写目录.