1
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?

【Linux】historyコマンドが便利だ!! 開発効率化

Posted at

概要

historyコマンドは、過去に実行したコマンドの履歴を表示するLinux/Unixの標準コマンドです。開発作業において、特に以下の場面で非常に便利です。

主な用途

1. 作業の順序を確認したい時

  • npm iで何をインストールしたか(package.jsonを見るだけでも分かりますが)
  • どんな順番で作業したかをすぐに確認したい時
history 20  # 最近の20個のコマンドを表示

2. 特定のコマンドを検索したい時

「あのコマンド打ったっけな?」と思った時に、grepと組み合わせてすぐに検索できます。

# npm install関連のコマンドを検索
history | grep "npm i"

# node関連のコマンドを検索
history | grep "node"

# git関連のコマンドを検索
history | grep "git"

# 特定のファイル名を含むコマンドを検索
history | grep "supabase.js"

便利なオプション

最近のコマンドのみ表示

history 10   # 最近の10個
history 50   # 最近の50個

タイムスタンプ付きで表示

history -i   # 実行時刻も表示

コマンド履歴をファイルに保存

history > command_history.txt

実際の使用例

開発作業の流れを確認

$ history 15
  100  npm init -y
  101  npm install @supabase/supabase-js
  102  npm install dotenv
  103  mkdir src
  104  touch src/supabase.js
  105  echo 'SUPABASE_URL=your_url' > .env
  106  echo 'SUPABASE_KEY=your_key' >> .env
  107  node src/supabase.js
  108  history | grep "npm i"
  109  history 10

特定のコマンドを探す

$ history | grep "npm i"
  101  npm install @supabase/supabase-js
  102  npm install dotenv

まとめ

historyコマンドは、開発作業の記録を残し、後から振り返る際に非常に便利なツールです。特にgrepとの組み合わせで、過去のコマンドを素早く検索できるのが大きなメリットです。

1
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
1
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?