0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

historyコマンドで履歴番号から実行する方法

Posted at

コマンド実行履歴を見れるhistoryコマンドで意外と知られていない使い方があったのでご紹介します。

historyコマンドで以下のような結果になったとします

$ history

 1110  ll
 1111  ps
 1112  pwd

この時、左の列の番号を実行すると、そのコマンドを実行出来ます。

試しに ll コマンドでやってみましょう。

通常実行

$ ll 

-rw-r--r--@ 〜 4 18 15:31 01.txt
-rw-r--r--@ 〜 4 18 15:31 02.txt
-rw-r--r--@ 〜 4 18 15:31 03.txt
-rw-r--r--@ 〜 4 18 15:31 04.txt
-rw-r--r--@ 〜 4 18 15:31 05.txt

履歴番号から実行

$ !1110 

-rw-r--r--@ 〜 4 18 15:31 01.txt
-rw-r--r--@ 〜 4 18 15:31 02.txt
-rw-r--r--@ 〜 4 18 15:31 03.txt
-rw-r--r--@ 〜 4 18 15:31 04.txt
-rw-r--r--@ 〜 4 18 15:31 05.txt

先頭に「!」をつけます。

うん、同じコマンドですね。

キーボードの↑を押してコマンドを探す人もいますし便利なのかは不明ですが、こんな実行方法あったんだなあと。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?