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


MFaklis

New member
Local time
7:15 PM
Posts
3
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

System One

  • 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

System One System Two

  • 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
  • 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

System One

  • OS
    Windows 11 Pro 24H2 [rev. 4349]
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical with Cherry MX Clears
    Antivirus
    Microsoft Defender
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

System One

  • 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

System One System Two

  • 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
  • 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

Latest Support Threads

Back
Top Bottom