linux极简小知识:1、同时执行多个命令时每个都有添加sudo权限

616 阅读1分钟

小知识,大挑战!本文正在参与“程序员必备小知识”创作活动。

在CentOS下,如果使用 &&|| 等符号同时执行多个命令时,而每个(或后面)的命令需要 sudo 管理员权限的话,则 && 符号前后的每个命令,都要添加 sudo 命令,提升权限。

如下,第二个命令不使用 sudo 时

$ sudo yum clean all && yum update curl
Loaded plugins: fastestmirror, langpacks
Repository mariadb is listed more than once in the configuration
Cleaning repos: CityFan epel extras google-chrome mariadb os
              : packages-microsoft-com-prod updates
Cleaning up everything
Cleaning up list of fastest mirrors
Loaded plugins: fastestmirror, langpacks
Repository mariadb is listed more than once in the configuration
You need to be root to perform this command.

正确的做法,所有命令使用 sudu :

$ sudo yum clean all && sudo yum update curl