“重新应用”先前命令的命令?

“重新应用”先前命令的命令?

有没有一种简单的方法可以将以前的命令重新应用到新的命令行条目?

假设我输入了chmod u+r,g+x file.txt但忘记了 sudo。我可以简单地输入sudo <some easy symbol>'吗?

答案1

你可以做:

sudo !!

另一个好的方法是alt .插入上一个命令的最后一个参数

答案2

up箭头,按ctrl+a,写入sudo,按enter

答案3

有一些基本的 bash 快捷键你应该知道...

Ctrl + A    Go to the beginning of the line you are currently typing on
Ctrl + E    Go to the end of the line you are currently typing on
Ctrl + L    Clears the Screen.
Ctrl + U    Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H    Same as backspace
Ctrl + R    Let’s you search through previously used commands
Ctrl + D    Exit the current shell
Ctrl + W    Delete the word before the cursor
Ctrl + K    Clear the line after the cursor
Ctrl + T    Swap the last two characters before the cursor
Esc + T     Swap the last two words before the cursor
Alt + F     Move cursor forward one word on the current line
Alt + B     Move cursor backward one word on the current line
Tab         Auto-complete files and folder names

在您的具体情况下,我也别名hhistory|grep.

这样:

# mco service sendmail status -F operatingsystemmajrelease=6

我需要在前面添加一些东西......

# h mco

这表明...

  114  07-28-2014 09:33:25  mco package sendmail install -F operatingsystemmajrelease=6
  115  07-28-2014 09:33:25  mco service sendmail status -F operatingsystemmajrelease=6
  116  07-28-2014 09:33:25  mco package sendmail-cf install -F operatingsystemmajrelease=6

我想要第 116 行...所以我输入:

# !115

但如果我需要在它前面放一些东西(例如sudo),我会......

# sudo !115

相关内容