Image

Dos command history

One of the nice things of Linux is the command history – it stores typically the last 1000 commands or so and its saved every time you log out.

DOS does have this through the doskey /history command (but only for current session) and you can relatively easily append this to a file:

The tricky bit is having this done for you on log out.

Via a Stack Overflow question on bash_history you can get close, using doskey macros which appends to a file on exit.

This only works for the current session though so you need to create a shortcut that runs the command each time with the following Target:

Then you just have to remember to type exit each time…

Shortcut target

Shortcut target

Update

I also found three useful commands – but they’re only for your current session. Hat tip to Nifty Computer Tricks:

F3
get last command
F7
current list (use left/right arrow keys to paste to the command line)
F8
auto-complete (type the first few letters)

Update 2 – Some extra love for the DOS prompt…

If you’ve got this working then I’ve added some extra basics. First you need to install Git (and I suggest you do it using the Chocolatey package). This includes the best versions of gnu commands compiled natively for Windows.

Add the Git usr bin directory to the path e.g. C:\Program Files\Git\usr\bin.

Then download my !.bat / history.bat gist:

Put the !.bat and history.bat into the Git usr bin directory too. These assume you are saving the history to %USERPROFILE%\history.log.

Then you’ll be able to do commands like history | grep mysql to list all your mysql commands in history.log with their line numbers. Then call ! 123 to execute the specific line of the history.log file.

Update 3 – Clink love

Martin Ridgers’ Clink is an awesome tool to behold. That adds the correct ! command to the DOS command prompt. Buuuuuuut… it doesn’t include a history command. So save the above history.bat file to C:\Windows\System32\history.bat (it doesn’t have to rely on GNU Tools / Git) and uncomment history_file=%localappdata%\clink\.history.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s