LoginSignup
1
1

More than 1 year has passed since last update.

historyで簡単に過去のコマンドを実行する

Posted at

zennでも同じ記事を投稿しています📮
zennではフロントエンドのことも含め、いろいろ投稿しているのでぜひご覧ください👋

用法

一つ前に実行したコマンドであれば"↑"を押せば実行できますが、
少し前に実行したコマンドとなると、"↑"を押し続けることになるので遡ることが大変です。
そのようなときに history コマンドを使うと過去に入力したコマンドを一覧で表示することができます。
どのコマンドを使ったか覚えている場合は grep で絞ると見やすくなります。

history | grep <search_word>

実行すると、行番号とで絞ったコマンドが表示されるので

!<行番号>

を入力すると実行されます。

実例

"php artisan migrate" コマンドを実行したいとします。

# artisanに絞って履歴を出力する
[username@foo]$ history | grep artisan

# 実行結果
989 php artisan list
991 php artisan route:list
992 php artisan route:list
998 php artisan migrate
1012 php artisan list

# 998行目を実行
[username@foo]$ !998
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1