如何快速更改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
  • 閱讀 ( 14 )
  • 分類:網際網路

你可能感興趣的文章

如何定製mac終端並使其更有用

...個新手,現在堅持預設的bashshell是可以的。但你應該知道如何在需要的時候切換它們。 ...

  • 發佈於 2021-03-21 20:13
  • 閲讀 ( 49 )

如何使用受限shell來限制linux使用者可以做什麼

...改其目錄,您可以控制他們可以訪問哪些命令。下面介紹如何在Linux上設定受限shell。 受限炮彈 受限shell不是另一個shell。這是標準外殼的另一種模式。Bash、Korn、Fish和其他shell都可以在受限shell模式下啟動。在本文中,我們將...

  • 發佈於 2021-03-31 10:57
  • 閲讀 ( 56 )

如何使用chsh在linux上更改預設shell

Bash不是唯一的Linux shell。很容易嘗試其他的shell,比如非常流行的Zsh。找到一個您喜歡的shell後,使用chsh命令將其設定為預設shell。我們會教你怎麼做。 為什麼貝殼很重要 shell位於您和作業系統之間。它在終端視窗內提供環境...

  • 發佈於 2021-04-02 06:04
  • 閲讀 ( 66 )

如何在linux上的bash中設定環境變數

Linux上有多種型別的環境變數。瞭解如何檢視它們,為本地和遠端登入建立它們,並使它們在重新啟動後仍然有效。 環境變數的工作原理 啟動終端視窗及其內部的shell時,會引用一組變數,以確保shell配置正確。這些變數還確...

  • 發佈於 2021-04-02 06:44
  • 閲讀 ( 57 )

如何在linux上使用sed命令

...命令列使用它來操作檔案和流中的文字。我們將向你展示如何利用它的力量。 sed的力量 sed命令有點像國際象棋:學習基礎知識需要一個小時,掌握它們需要一輩子(或者,至少需要大量的練習)。我們將向您展示sed功能的每...

  • 發佈於 2021-04-02 08:03
  • 閲讀 ( 44 )

如何在linux上使用cd命令

...小又簡單。 在使用Linux計算機的第一個小時內,您將學習如何使用Bash和其他shell附帶的cd命令。也許您以前有在其他作業系統上使用它的經驗,不需要解釋。它會改變當前的工作目錄,對嗎?還有什麼要知道的? 好吧,比你想象...

  • 發佈於 2021-04-02 08:58
  • 閲讀 ( 67 )

如何更改powerpoint中文字的大小寫

...示例中的文本當前都是大寫。讓我們改變這個。 相關:如何防止PowerPoint自動調整文字大小 選中文字後,導航到“主頁”選項卡的“字型”組並選擇“更改案例”選項。 在出現的下拉選單中,有五個選項可供選擇: 句子大小...

  • 發佈於 2021-04-02 13:24
  • 閲讀 ( 38 )

如何在linux上使用history命令

...複您過去執行的命令。一旦您瞭解了Linux history命令以及如何使用它,它就可以顯著地提高您的生產效率。 操縱歷史 正如喬治桑塔亞納(georgestantayana)的一句名言:“那些記不住過去的人註定要重蹈覆轍。”不幸的是,在Linux...

  • 發佈於 2021-04-02 18:17
  • 閲讀 ( 51 )

如何在bash中使用變數

...給它: drink_of-the_Year="$my_boost $this_year" echo drink_of_the-Year 如何在指令碼中使用變數 如果沒有變數,指令碼將完全無法執行。變數提供了靈活性,使指令碼成為通用的解決方案,而不是特定的解決方案。為了說明這一區別,這裡...

  • 發佈於 2021-04-03 02:34
  • 閲讀 ( 59 )

如何在linux上建立別名和shell函式

...才能繼續存在。一旦視窗關閉,別名將消失。 那麼我們如何使我們的別名永久化呢? .bashrc檔案和別名 您可能想知道預打包的別名是在哪裡定義的。它位於主資料夾的“.bashrc”檔案中。當您啟動互動式shell時,將讀取此檔案並...

  • 發佈於 2021-04-03 03:45
  • 閲讀 ( 48 )
rpo4711763
rpo4711763

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦