How can I make command line history persistent in CMD and PowerShell?


MFaklis

Member
Local time
7:29 AM
Posts
5
Location
N 37° 47.932’ W 122° 24.038’
OS
Windows 11 Pro v.24H2 Build 26100.3476
Whenever I open CMD or PowerShell, I would like the command line history to reflect all previous sessions.
 

My Computer My Computer

At a glance

Windows 11 Pro v.24H2 Build 26100.3476Intel Core Ultra Series 132 GB
OS
Windows 11 Pro v.24H2 Build 26100.3476
Computer type
Laptop
Manufacturer/Model
Framework 13
CPU
Intel Core Ultra Series 1
Motherboard
Framework
Memory
32 GB
I've never seen the Command Prompt save previous commands for years, retains in memory only as long as the Command Prompt stays open. Closing the window clears the memory of those commands. Pressing the Up arrow will restore or recall what is still in memory before closing the window.
 

My Computers My Computers

  • At a glance

    Win11 Pro RTM Version 24H2 Build 26100.4202Intel Core i5 11th Gen. 2.40GHz12GB
    OS
    Win11 Pro RTM Version 24H2 Build 26100.4202
    Computer type
    Laptop
    Manufacturer/Model
    Dell Vostro 3400
    CPU
    Intel Core i5 11th Gen. 2.40GHz
    Memory
    12GB
    Hard Drives
    256GB SSD NVMe M.2
  • At a glance

    Win11 Pro RTM Version 24H2 Build 26100.4202Intel Core i5 10th Gen. 2.90GHz16GBOnboard, no VGA, using a DisplayPort-to-VGA a...
    Operating System
    Win11 Pro RTM Version 24H2 Build 26100.4202
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Vostro 5890
    CPU
    Intel Core i5 10th Gen. 2.90GHz
    Memory
    16GB
    Graphics card(s)
    Onboard, no VGA, using a DisplayPort-to-VGA adapter
    Monitor(s) Displays
    24" Dell
    Hard Drives
    512GB SSD NVMe, 4TB Seagate HDD
    Browser
    Firefox, Edge
    Antivirus
    Windows Defender/Microsoft Security
cmd.exe does not save history between sessions, but you can use something like Clink as a replacement/enhancement.


PowerShell has this functionality via the PSReadLine module. There are lots of options related to history, so it's best to read over them yourself, because configuring it is definitely a matter of taste.


 

My Computer My Computer

At a glance

Windows 11 Enterprise 25H2
OS
Windows 11 Enterprise 25H2
To get a persistent command history in CMD, I have been using something called Clink:

Clink combines the native Windows shell cmd.exe with the powerful command line editing features of the GNU Readline library, which provides rich completion, history, and line-editing capabilities. Readline is best known for its use in the well-known Unix shell Bash, the standard shell for Mac OS X and many Linux distributions.

Clink website
 

My Computer My Computer

At a glance

Windows 11Intel(R) Core(TM) i5-10500 CPU @ 3.10GHz 3.10...32.0 GBonboard
OS
Windows 11
Computer type
PC/Desktop
Manufacturer/Model
Lenovo m70s
CPU
Intel(R) Core(TM) i5-10500 CPU @ 3.10GHz 3.10 GHz
Motherboard
Lenovo m70s
Memory
32.0 GB
Graphics Card(s)
onboard
Sound Card
onboard
Monitor(s) Displays
AOC Q27G4X
Readline is best known for its use in the well-known Unix shell Bash, the standard shell for Mac OS X and many Linux distributions
A question for future reference, does that still work in the newer/current macOS?
 

My Computers My Computers

  • At a glance

    Win11 Pro RTM Version 24H2 Build 26100.4202Intel Core i5 11th Gen. 2.40GHz12GB
    OS
    Win11 Pro RTM Version 24H2 Build 26100.4202
    Computer type
    Laptop
    Manufacturer/Model
    Dell Vostro 3400
    CPU
    Intel Core i5 11th Gen. 2.40GHz
    Memory
    12GB
    Hard Drives
    256GB SSD NVMe M.2
  • At a glance

    Win11 Pro RTM Version 24H2 Build 26100.4202Intel Core i5 10th Gen. 2.90GHz16GBOnboard, no VGA, using a DisplayPort-to-VGA a...
    Operating System
    Win11 Pro RTM Version 24H2 Build 26100.4202
    Computer type
    PC/Desktop
    Manufacturer/Model
    Dell Vostro 5890
    CPU
    Intel Core i5 10th Gen. 2.90GHz
    Memory
    16GB
    Graphics card(s)
    Onboard, no VGA, using a DisplayPort-to-VGA adapter
    Monitor(s) Displays
    24" Dell
    Hard Drives
    512GB SSD NVMe, 4TB Seagate HDD
    Browser
    Firefox, Edge
    Antivirus
    Windows Defender/Microsoft Security
Back
Top Bottom