如何解决普通用户使用sudo找不到命令

一、在linux的普通用户下,要使用root权限的命令需要使用sudo

[dev@dev1 client_api]# sudo git pull origin develop
sudo: git: command not found

但是发现git命令找不到

二、使用whereis找git的绝对路径

[dev@dev1 client_api]$ whereis git
git: /usr/local/git

再次尝试

[dev@dev1 client_api]$ sudo /usr/local/git pull origin develop
sudo: /usr/local/git: command not found

还是不对的 换成which试试

[dev@dev1 client_api]$ which git
/usr/local/git/bin/git

这次找到的位置是截然不同的
再次尝试

[dev@dev1 client_api]$ sudo /usr/local/git/bin/git pull origin develop
From IP地址:client_api
 * branch            develop    -> FETCH_HEAD
Updating 81608e5..815cbbb
error: Your local changes to the following files would be overwritten by merge:
    app/Models/OrderMaster.php
    app/Services/OrderService.php
    config/params.php
Please, commit your changes or stash them before you can merge.
Aborting

很明显成功了 

三、寻找原因

因为sudo默认的配置文件下只是指定三个命令位置,如下

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

所以采用软连接的方式

ln -s /usr/local/git/bin/git /usr/bin/git

这次再尝试直接使用命令

[dev@dev1 client_api]$ sudo git pull origin develop
remote: Counting objects: 34, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 21 (delta 13), reused 0 (delta 0)
Unpacking objects: 100% (21/21), done.
From IP地址:018_client_api
 * branch            develop    -> FETCH_HEAD
   815cbbb..a93dc24  develop    -> origin/develop
Updating 81608e5..a93dc24
error: Your local changes to the following files would be overwritten by merge:
    app/Models/OrderMaster.php
    app/Services/OrderService.php
    config/params.php
    routes/api.php
Please, commit your changes or stash them before you can merge.
Aborting

好了 完美

 

转载于:https://www.cnblogs.com/murry/p/8717151.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值