bash sudo_使用“ !!”将Sudo添加到您的最后一个Bash命令中 句法

bash sudo_使用“ !!”将Sudo添加到您的最后一个Bash命令中 句法

bash sudo

How often have you typed in a command in your linux shell, and then realized that you forgot to type sudo, so you end up with an error or editing the dreaded read-only file? This happens to me much more than I’d like to admit, so I’m writing about it.

您多久在linux shell中键入一个命令,然后才意识到您忘记键入sudo了,所以最终会遇到错误或编辑可怕的只读文件? 这件事对我来说比我想承认的要多得多,所以我正在写。

You have a couple of options, the easiest one is to just use !! to tell bash to use the last command.

您有几种选择,最简单的选择就是使用!! 告诉bash使用最后一个命令。

For instance, if you tried to type this, you’d get an error that you are editing a read-only file:

例如,如果您尝试键入此内容,则会在编辑只读文件时收到错误消息:

vi /etc/apt/sources.list

vi /etc/apt/sources.list

Once that happens, then you can just use this command:

一旦发生这种情况,您就可以使用以下命令:

sudo !!

须藤!!

Which bash will then expand into this command:

然后哪个bash会扩展为以下命令:

sudo vi /etc/apt/sources.list

须藤vi /etc/apt/sources.list

Screenshot of this in action:

此操作的屏幕截图:

bash sudo_使用“ !!”将Sudo添加到您的最后一个Bash命令中 句法

An alternative method would be to just hit the up arrow key, hit either the Home key or Ctrl+A, and then type sudo.

另一种方法是直接按下向上箭头键,再按下Home键或Ctrl + A,然后键入sudo。

翻译自: https://www.howtogeek.com/howto/linux/add-sudo-to-your-last-bash-command-with-syntax/

bash sudo