LoginSignup
1
0

Powershellでhistoryコマンドが打ちたい!!

Last updated at Posted at 2023-12-11

はじめに

Powershellのコマンド履歴をコマンドで取得したくないですか?
コマンド履歴をテストファイルとしてWindows上に保持していることはほとんどのユーザが知っていると思いますが、それだと物足りないですよね。
ということであなたのPowershellライフを豊かにしましょうs!!

Powershellでhistoryを打つ。

Powershellの過去の実行コマンド履歴を保持している

下記コマンドを打つ履歴を保持しているテキストのパスを取得できる。

PS C:Users> (Get-PSReadlineOption).HistorySavePath`
C:\Users\hogehoge\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

あいまい検索する

Get-Content -Encoding UTF8 (Get-PSReadlineOption).HistorySavePath  | Where-Object {$_ -like '*git*'}

過去100コマンドを取得する

# 最古の100コマンド取得
Get-Content -Encoding UTF8 (Get-PSReadlineOption).HistorySavePath  | select -first 100

# 最新の100コマンド取得
Get-Content -Encoding UTF8 (Get-PSReadlineOption).HistorySavePath  | select -last 100

組み合わせる

ex) gitコマンドで、最新を100個取得する

Get-Content -Encoding UTF8 (Get-PSReadlineOption).HistorySavePath `
| Where-Object { $_ -like 'git*' } | select -first 100

最後に

あなたのPowershellライフが豊かになること間違いなし。
Powershellしか使えない制約でいかに幸せになれるかを追求していきましょう!!!!

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