Emulating *nix Shell with Windows Command Prompt

Ever tried to ls or rm under Windows?

With just a few minor adjustments the Windows Command Prompt (cmd.exe) can emulate the behaviour of your favourite *nix shell. Please note, this isn’t a full emulation method – the existing Windows commands are being manipulated to appear as their *nix shell counterparts.

Note: This is for systems where unauthorized software is not permitted. If you administrate your own system, I highly recommend checking the GnuWin32, in particular the CoreUtils package.

Background

This method involves simple implementation of the doskey macro utility. For convenience, a Windows batch file (*.bat) will be used to wrap calls to doskey. Some small adjustments to the registry are necessary, so it is strongly advised that the registry is backed up before reading further.

Create a Command List Batch File

  1. Open a text editor of your choice (e.g. notepad).
  2. The following are some examples of how to add a *nix command, with the Windows Command Prompt equivalent:
    @ECHO OFF
    doskey sudo=runas /user:administrator $*
    doskey alias=doskey $*
    doskey ls=dir $*
    doskey rm=del $*
    doskey cp=copy $*
    doskey mv=move $*
    doskey clear=cls
    doskey reboot=echo The system is going down for reboot NOW!$T shutdown -r
    doskey restart=reboot
    doskey top=tasklist
    doskey traceroute=tracert $*
    doskey kill=taskkill /F /IM $*
    echo [%USERNAME%@%COMPUTERNAME%]$ *nix commands added
  3. Save as a batch file somewhere on your system, e.g. C:nix-cmd.bat

Please note: Not all commands will behave exactly like their counterpart, however these are some examples from my batch file.

Enabling Batch File and Tab-key Auto-complete

  1. Start->Run->regedit
  2. To add auto-complete for…
    just your username:
    HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor
    all system users:
    HKEY_LOCAL_MACHINESoftwareMicrosoftCommand Processor
  3. Modify the key entries to reflect your system settings, although they should appear somewhat similar to the below:
    *nix cmd registry screen capture
    *nix cmd registry screen capture

If you want to use a different key for auto-complete (i.e. not tab), then change the CompletionChar and PathCompletionChar values to the desired hexadecimal character code.

Footnote

That is all there is to it! I mostly make do with the commands above – its just a nice little tweak to make the command prompt a bit more usable.