一、在linux的普通用户下,要使用root权限的命令需要使用sudo
[dev@dev1 client_api]# sudo git pull origin developsudo: git: command not found
但是发现git命令找不到
二、使用whereis找git的绝对路径
[dev@dev1 client_api]$ whereis gitgit: /usr/local/git
再次尝试
[dev@dev1 client_api]$ sudo /usr/local/git pull origin developsudo: /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 developFrom IP地址:client_api* branch develop -> FETCH_HEADUpdating 81608e5..815cbbberror: Your local changes to the following files would be overwritten by merge:app/Models/OrderMaster.phpapp/Services/OrderService.phpconfig/params.phpPlease, 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 developremote: 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_HEAD815cbbb..a93dc24 develop -> origin/developUpdating 81608e5..a93dc24error: Your local changes to the following files would be overwritten by merge:app/Models/OrderMaster.phpapp/Services/OrderService.phpconfig/params.phproutes/api.phpPlease, commit your changes or stash them before you can merge.Aborting
好了 完美
如果觉得《如何解决普通用户使用sudo找不到命令》对你有帮助,请点赞、收藏,并留下你的观点哦!