输入source ~/.bashrc 报错dircolors\lesspipe: command not found解决方法

问题

输入

source ~/.bashrc

如下报错

Command 'lesspipe' is available in the following places
 * /bin/lesspipe
 * /usr/bin/lesspipe
The command could not be located because '/bin:/usr/bin' is not included in the PATH environment variable.
lesspipe: command not found
Command 'dircolors' is available in '/usr/bin/dircolors'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
dircolors: command not found

解决方法

命令行中输入

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

这种方法能保证你这一个命令行内可以正常使用bin下的命令,比如source、ls等。

永久解决

首先执行上面所说的,命令行中export。

然后修改你用户目录下的.bashrc文件,哪改错了就改回来,不知道错哪了就把上一次的变动取消掉。

vim ~/.bashrc

重点观察export ...$PATH...这种语句是否正确。

比如我之前的错误就是在配置cuda工具时忘了加PATH。

我的.bashrc出问题时是这样的:

...

export PATH=$PATH:/home/zhoug/cuda-10.2/bin/
export PATH=/home/zhoug/cuda-10.2/lib64/

可以看到,我第4行中间是没有加$PATH的,所以产生了错误。

照我之前说的,要么改对:

export PATH=$PATH:/home/zhoug/cuda-10.2/bin/
export PATH=$PATH:/home/zhoug/cuda-10.2/lib64/

要么删除这几行改成最后一次原来的样子

...

# export PATH=$PATH:/home/zhoug/cuda-10.2/bin/
# export PATH=/home/zhoug/cuda-10.2/lib64/

然后,再source该修改好的.bashrc

source ~/.bashrc

你系统命令就恢复正常了。

原因

看到这里你应该也知道了,就是你更新了你的.bashrc再source之后

vim ~/.bashrc
source ~/.bashrc

系统解析你export的路径PATH时,没解析对位置。

那99.99%的可能是因为你修改.bashrc没修改对。

这样的情况下,你要执行系统命令,就只能这样,比如你要ls

/usr/bin/ls

所以你要修改回你的.bashrc文件,得这样用vim:

/usr/bin/vim ~/.bashrc

不过你遇到最棘手的问题应该是,你想用这种方式source时就会报我开头说的错:

/usr/bin/source
Command 'lesspipe' is available in the following places
 * /bin/lesspipe
 * /usr/bin/lesspipe
The command could not be located because '/bin:/usr/bin' is not included in the PATH environment variable.
lesspipe: command not found
Command 'dircolors' is available in '/usr/bin/dircolors'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
dircolors: command not found

可能原因是source是一个组合的命令吧,然后再执行这个组合命令的时候,调用lesspipe和dircolors的时候还是需要正确的PATH路径。

我提到的解决方法可以很好的解决这个问题。

参考

Linux报错:-bash: 路径xx: No such file or directory解决方法

猜你喜欢

转载自blog.csdn.net/m0_46948660/article/details/129702261
今日推荐