I use windows 7 64bit. I found both cmd.exe and powershell cannot keep history. It means it lost my command history when I quit the shell.
Is there a tools can help cmd.exe or powershell to remember the history? I try to use console 2. Console 2 is tiny and has a tab interface. But console 2 can't remember the history too. Maybe there is another front end can do this.
PowerShell automatically maintains a history of each session. The number of entries in the session history is determined by the value of the $MaximumHistoryCount preference variable. Beginning in Windows PowerShell 3.0, the default value is 4096 .
Launch the Command Prompt from the Start menu and type the following the pop-up window: “ doskey /history “ Press “Enter.” The commands you've executed in the active session will appear in the Command Prompt window.
Its saved under your appdata folder. So use Cat (Get-PSReadlineOption). HistorySavePath to get all historical commands ran.
Using the F8 key, you can find the command in history that matches the text on the current command line. For example, enter get- and press F8 . The last entry in the command history matching this text will be found. To go to the next command in history, press F8 again.
The answer below is from Keith Hill (PowerShell Microsoft MVP) in his answer to the question powershell history: how do you prevent duplicate commands:
BTW if you want to automatically save this on exit you can do this on 2.0 like so:
Register-EngineEvent PowerShell.Exiting {
Get-History -Count 32767 | Group CommandLine |
Foreach {$_.Group[0]} | Export-CliXml "$home\pshist.xml" } -SupportEvent
Then to restore upon load all you need is:
Import-CliXml "$home\pshist.xml" | Add-History
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With