如何快速更改bash命令中的第一个单词?

如果你的工作流程中充斥着大量重复的动作,那么寻找改进和简化工作流程的方法是没有坏处的。今天的超级用户问答文章为读者提供了一些有用的建议,以帮助他们改进自己的工作流程。...

如何快速更改bash命令中的第一个单词?

如果你的工作流程中充斥着大量重复的动作,那么寻找改进和简化工作流程的方法是没有坏处的。今天的超级用户问答文章为读者提供了一些有用的建议,以帮助他们改进自己的工作流程。

今天的问答环节是由SuperUser提供的,SuperUser是Stack Exchange的一个分支,是一个由社区驱动的问答网站分组。

由马特·乔伊斯(Flickr)提供的屏幕截图。

问题

超级用户读者coin想知道如何快速更改bash命令中的第一个单词:

I would like to improve my workflow in bash and realized that I often want to execute the same command to a different executable.

Some Examples

1.) Git

007Ys3FFgy1gpf5w57i3aj30hd02m3yd

2.) Bash

007Ys3FFgy1gpf5w6bsgzj30hd02n747

I know that I can hit Ctrl+a then Del to remove the first word, but I am wondering if there is a quicker way to do it.

coin有没有更快的方法来更改bash命令中的第一个单词?

答案

超级用户贡献者Spiff,Hastur,jjlin。Gustavo Giraldez给了我们答案。首先,斯皮夫:

!$ expands to the last word of your previous command. So you could do:

007Ys3FFgy1gpf5w74ta9j30hd029q2s

Or

007Ys3FFgy1gpf5w818klj30hd02a3yd

Your examples happened to only repeat the last word, so !$ worked fine. If you actually had a lot of arguments that you wanted to repeat, and you just wanted to change the first word, you could use !*, which expands to all words of the previous command except the zeroth.

See the “HISTORY EXPANSION” section of the bash man page. There is a lot of flexibility there.

接着是哈斯特的回答:

I would like to add a warning (see the answer from Spiff above). With !$, you do not have full visual control of the line you are running. The results can be harmful sometimes, especially if you incur a misprint. It takes what it needs from the history to expand on.

So if you write the last command with a blank space at the beginning, then this command will probably not finish from the history. When you execute your new command with !$, the shell will not take the parameters from the last command line typed, but only from the last part of the history.

Here are some more helpful words and commands.

jjlin的回答是:

Ctrl+a to go to the beginning of the line, then Alt+d to delete the first word.

古斯塔沃·吉拉德兹最后的回答是:

The delete word shortcut is actually Meta+d, and Meta is usually mapped to Alt on Linux machines. On platforms where this is not the case, an alternative to get the Meta modifier is to use Esc as a prefix. You can read more about the Meta Key here.


有什么要补充的解释吗?在评论中发出声音。想从其他精通技术的Stack Exchange用户那里了解更多答案吗?在这里查看完整的讨论主题。

  • 发表于 2021-04-11 01:28
  • 阅读 ( 194 )
  • 分类:互联网

你可能感兴趣的文章

Windows10中LinuxBashShell快速指南

...更多的特性。了解更多关于Bash-on-Windows的信息,从您应该如何以及为什么安装它,到您可能不知道的隐藏特性。 ...

  • 发布于 2021-03-17 01:06
  • 阅读 ( 194 )

如何使用applescript将bash脚本转换为可单击的应用程序

...为输入运行它。这些特殊的应用程序被称为水滴。下面是如何创建一个: ...

  • 发布于 2021-03-21 09:39
  • 阅读 ( 249 )

如何定制mac终端并使其更有用

...个新手,现在坚持默认的bashshell是可以的。但你应该知道如何在需要的时候切换它们。 ...

  • 发布于 2021-03-21 20:13
  • 阅读 ( 272 )

如何使用受限shell来限制linux用户可以做什么

...改其目录,您可以控制他们可以访问哪些命令。下面介绍如何在Linux上设置受限shell。 受限炮弹 受限shell不是另一个shell。这是标准外壳的另一种模式。Bash、Korn、Fish和其他shell都可以在受限shell模式下启动。在本文中,我们将...

  • 发布于 2021-03-31 10:57
  • 阅读 ( 387 )

如何使用shopt定制bashshell

...shshell的行为,您可以控制超过50个设置。我们将向您展示如何按照您喜欢的方式定制您的Linux系统。 shopt内置 shopt内置是bashshell所有版本的一部分,因此不需要安装任何东西。多年来,shopt提供的选项数量稳步增加。所以,Bash...

  • 发布于 2021-04-01 12:30
  • 阅读 ( 175 )

如何使用chsh在linux上更改默认shell

Bash不是唯一的Linux shell。很容易尝试其他的shell,比如非常流行的Zsh。找到一个您喜欢的shell后,使用chsh命令将其设置为默认shell。我们会教你怎么做。 为什么贝壳很重要 shell位于您和操作系统之间。它在终端窗口内提供环境...

  • 发布于 2021-04-02 06:04
  • 阅读 ( 338 )

如何在linux上的bash中设置环境变量

Linux上有多种类型的环境变量。了解如何查看它们,为本地和远程登录创建它们,并使它们在重新启动后仍然有效。 环境变量的工作原理 启动终端窗口及其内部的shell时,会引用一组变量,以确保shell配置正确。这些变量还确...

  • 发布于 2021-04-02 06:44
  • 阅读 ( 221 )

如何在linux上使用sed命令

...命令行使用它来操作文件和流中的文本。我们将向你展示如何利用它的力量。 sed的力量 sed命令有点像国际象棋:学习基础知识需要一个小时,掌握它们需要一辈子(或者,至少需要大量的练习)。我们将向您展示sed功能的每...

  • 发布于 2021-04-02 08:03
  • 阅读 ( 155 )

如何在linux上使用cd命令

...小又简单。 在使用Linux计算机的第一个小时内,您将学习如何使用Bash和其他shell附带的cd命令。也许您以前有在其他操作系统上使用它的经验,不需要解释。它会改变当前的工作目录,对吗?还有什么要知道的? 好吧,比你想象...

  • 发布于 2021-04-02 08:58
  • 阅读 ( 173 )

如何在linux上使用history命令

...复您过去运行的命令。一旦您了解了Linux history命令以及如何使用它,它就可以显著地提高您的生产效率。 操纵历史 正如乔治桑塔亚纳(georgestantayana)的一句名言:“那些记不住过去的人注定要重蹈覆辙。”不幸的是,在Linux...

  • 发布于 2021-04-02 18:17
  • 阅读 ( 203 )
rpo4711763
rpo4711763

0 篇文章

相关推荐