Open woodongwong opened 1 year ago
我用惯了 bash shell 中的 history 命令,发现 PowerShell 中的 history 只能列出当前会话的,通过 Get-Alias 列出所有的 alias ,发现 history 是 Get-History 的别名。
Get-History 只能列出当前会话的历史记录,想要列出所有会话的历史记录,需要查看 ConsoleHost_history.txt 文件。
ConsoleHost_history.txt 中记录了所有会话的历史记录,可以通过(Get-PSReadlineOption).HistorySavePath获取绝对路径,然后再通过Get-Content获取文件内容。
(Get-PSReadlineOption).HistorySavePath
Get-Content
完整的命令是:Get-Content -Path (Get-PSReadlineOption).HistorySavePath,最后在profile中设置一个别名history-all,可以使用notepad $PROFILE打开 profile,将下面的代码放进去,这样就可以在 PowerShell 中使用history-all列出全部记录啦😄。
Get-Content -Path (Get-PSReadlineOption).HistorySavePath
profile
history-all
notepad $PROFILE
function Get-History-All { Get-Content -Path (Get-PSReadlineOption).HistorySavePath } New-Alias history-all Get-History-All
我用惯了 bash shell 中的 history 命令,发现 PowerShell 中的 history 只能列出当前会话的,通过 Get-Alias 列出所有的 alias ,发现 history 是 Get-History 的别名。
Get-History 只能列出当前会话的历史记录,想要列出所有会话的历史记录,需要查看 ConsoleHost_history.txt 文件。
ConsoleHost_history.txt 中记录了所有会话的历史记录,可以通过
(Get-PSReadlineOption).HistorySavePath
获取绝对路径,然后再通过Get-Content
获取文件内容。完整的命令是:
Get-Content -Path (Get-PSReadlineOption).HistorySavePath
,最后在profile
中设置一个别名history-all
,可以使用notepad $PROFILE
打开 profile,将下面的代码放进去,这样就可以在 PowerShell 中使用history-all
列出全部记录啦😄。