北屋教程网

专注编程知识分享,从入门到精通的编程学习平台

Windows下获取历史命令,类似 linux 下的 history

环境

Windows Terminal + Power Shell (Power Shell Core)

实现

默认情况下,Power Shell 的 history 这个命令是获取当前session下的历史命令(打开这个窗口执行过的操作),与linux下的history行为不一样。


Power shell可以通过下面这个API获取到历史执行命令。

PS C:\Users\Administrator> Get-Content (Get-PSReadlineOption).HistorySavePath

可以配合管道进行处理,如进行搜索 ssh 相关的历史命令:

PS C:\Users\Administrator> Get-Content (Get-PSReadlineOption).HistorySavePath | findstr ssh



参考

官方文档:

  • Get-PSReadlineOption: https://docs.microsoft.com/en-us/powershell/module/psreadline/get-psreadlineoption?view=powershell-7.2
  • Alias: https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_aliases?view=powershell-7.2
  • Get-Content: https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-content?view=powershell-7.2
控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言