Cmder-CheatSheet

Learn how to grep Cmder command history effectively. This cheatsheet explains the doskey macro and provides solutions for filtering your command history in Cmder.

Cmder Cheatsheet

Cmder Command History Grep Guide

This cheatsheet addresses a common challenge when using Cmder: how to effectively grep command history. Cmder utilizes a doskey macro for its history, which behaves differently from standard shell history when piping commands.

Understanding Cmder's History Alias

Cmder provides a convenient alias for accessing its history file:

history=cat "%CMDER_ROOT%\config\.history"

However, directly piping this alias to a grep command, like so:

history | grep "docker run"

will not work as expected because the output of a doskey macro cannot be directly piped.

Effective Grepping of Cmder History

To successfully filter your Cmder command history, you need to use the actual command that the history alias represents. This involves directly accessing the history file.

In Cmder sessions, history is managed as a doskey macro. To grep its content, you must execute the underlying command that lists the history, rather than piping the macro itself.

The correct method is to use cat with the full path to the history file:

C:\Users\user\cmder
λ cat %CMDER_ROOT%\config\.history | grep cmder

This approach ensures that you are piping the actual content of the history file to the grep command, allowing you to filter it effectively.

External Resources and Further Reading

For more in-depth information and community discussions on Cmder and command-line utilities, refer to the following resources:

  1. Cmder GitHub Issue #1770: Can't Pipe history to grep - A discussion on the GitHub repository addressing this specific problem.
  2. SuperUser Question: Filter command history in Windows using Cmder - A community question and answer providing solutions and explanations.
  3. SS64 DOSKEY Command - Official documentation on the DOSKEY command, which is fundamental to Cmder's macro system.
  4. Microsoft FINDSTR Command - An alternative to grep on Windows, useful for text searching within files.