Bash                
            バッシュ履歴の置換
        
        
            
    サーチ…
!$の使用
 !$を使用すると、コマンドラインを使用するときの繰り返しを減らすことができます。 
$ echo ping
ping
$ echo !$
ping
繰り返しに基づいて構築することもできます
$ echo !$ pong
ping pong
$ echo !$, a great game
pong, a great game
最後の例では、前のコマンドに渡された最後の引数がpongなので、 ping pong, a great game得られなかったことに注意してください。この例を続けて、私たちの最後の議論はgameでしgame : 
$ echo "it is !$ time"
it is game time
$ echo "hooray, !$!"
hooray, it is game time!
クイックリファレンス
歴史との相互作用
# List all previous commands
history
# Clear the history, useful if you entered a password by accident
history -c
イベント指定子
# Expands to line n of bash history
!n
# Expands to last command
!!
# Expands to last command starting with "text"
!text
# Expands to last command containing "text"
!?text
# Expands to command n lines ago
!-n
# Expands to last command with first occurrence of "foo" replaced by "bar"
^foo^bar^
# Expands to the current command
!#
ワード指定子
これらはで区切られ:イベント指示から、彼らはを参照してください。単語指定子が数字で始まらない場合は、コロンを省略することができます。 !^は!:^と同じ!:^ 。 
# Expands to the first argument of the most recent command
!^
# Expands to the last argument of the most recent command (short for !!:$)
!$
# Expands to the third argument of the most recent command
!:3
# Expands to arguments x through y (inclusive) of the last command
# x and y can be numbers or the anchor characters ^ $
!:x-y
# Expands to all words of the last command except the 0th
# Equivalent to :^-$
!*
修飾子
これらは、前のイベントまたはワード指定子を変更します。
# Replacement in the expansion using sed syntax
# Allows flags before the s and alternate separators
:s/foo/bar/ #substitutes bar for first occurrence of foo
:gs|foo|bar| #substitutes bar for all foo
# Remove leading path from last argument ("tail")
:t
# Remove trailing path from last argument ("head")
:h
# Remove file extension from last argument
:r
 Bash変数HISTCONTROLにignorespaceまたはignorebothいずれかが含まれている場合(または、 HISTIGNOREにパターン[ ]*が含まれている場合)、コマンドの前にスペースを入れてコマンドをBash履歴に保存できないようにすることができます。 
# This command won't be saved in the history
 foo
# This command will be saved
bar
コマンド履歴でパターン検索
コントロール rを押してパターンを入力します。
たとえば、最近man 5 crontab実行した場合、「crontab」 と入力してすぐに見つけることができます。プロンプトは次のように変わります: 
(reverse-i-search)`cr': man 5 crontab
 `cr'にはこれまでに入力した文字列があります。これは増分検索であるため、入力を続けると、パターンを含む最新のコマンドと一致するように検索結果が更新されます。 
一致するコマンドを実行する前に左右の矢印キーを押すか、コマンドを実行するためにEnterキーを押します。
デフォルトでは、パターンに一致する最も最近実行されたコマンドが検索されます。再び、さらにバック歴史機制御 Rで移動します。目的のコマンドが見つかるまで、繰り返し押すことができます。
!#:Nで新しく作成したディレクトリに切り替える
$ mkdir backup_download_directory && cd !#:1
mkdir backup_download_directory && cd backup_download_directory
これは、現在のコマンドのN番目の引数を置き換えます。この例では、 !#:1が最初の引数、つまりbackup_download_directoryに置き換えられています。 
前のコマンドを置換で繰り返します
$ mplayer Lecture_video_part1.mkv
$ ^1^2^
mplayer Lecture_video_part2.mkv
このコマンドは、前に実行したコマンドの1を2に置き換えます。これは、文字列の最初のオカレンスを置き換えるだけで、 !!:s/1/2/と等価です。 
 すべての出現を置き換えたい場合は、 !!:gs/1/2/または!!:as/1/2/ !!:gs/1/2/として使用する必要があります。 
sudoで前のコマンドを繰り返します
$ apt-get install r-base
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
$ sudo !!
sudo apt-get install r-base
[sudo] password for <user>: