Rutgers, The State University of New Jersey

Windows Unix compatibility

This page describes various possibilities for people who want to setup Windows for compatibility with Unix. I'm currently using Windows 7, but the same instructions should work for Vista, and with minor changes for XP.

Caps lock key

One of the first things I fix on Windows is the caps lock key. Because I use Emacs a lot, I want the caps lock key to act like a control. (The caps lock key is in a much more convenient location than the real control key, the same place as it is located in traditional Unix keyboards.)

Here is a page with a Registry change to swap caps lock and control as well as other related changes. You will need to log out and log back in for this to take effect. The scan map isn't that complex. It's possible to change it manually using regedit. They show the technique. But I've used the .reg file, and it's a lot easier.

Unix commands

There are two approaches to getting a reasonable set of Unix command-line tools: Cygwin and building up your own collection.


Cygwin is a port of most of a Linux distribution to Windows. It uses a compatibility library that implements a Unix API on top of Windows. Recent versions of Windows have all the necessary facilities in the kernel, so the implementation is fairly clean. Given the Cygwin library, you can treat Windows like any other Unix implementation, and port pretty much any software. Cygwin includes a full set of Gnu compilers and tools.

The primary location for Cygwin is the Cygwin web site. At the upper right of the main page you'll see an icon that lets you download the installer. The installer will install the library, and then let you choose what other tools you want. The core is a minimal set of command-line tools. I always add at least emacs, and usually others as well.

Cygwin gives you a fairly coherent Unix installation, with its own /usr, /etc, etc. You can even set things up to run Unix daemons, so you can ssh in. There is an X11 server, and a fairly complete Gnome implementation.

Cygwin installs in c:\Cygwin. In that directory is the Cygwin.bat, which is the command file used to start bash when you click the Cygwin desktop icon. You will probably want to edit it to add an option, and possibly to change the default shell. I recommend using notepad. I had odd permission problems otherwise.

I recommend adding the following to Cygwin.bat, before the call to the shell:

set CYGWIN=tty title
If you're going to use cygwin commands from a normal Windows command prompt (and you may well want to do that), go into Control Panel, System, Advanced, Environment Variables, and add a new enviornment variable CYGWIN with the value "tty" (without the quotes). I also recommmend modifying PATH to include c:\cygwin\bin. (I know it appears as /usr/bin within Cygwin, but that's where it really is.)

CYGWIN=tty is most useful only if you're going to use emacs. Without it, Windows intercepts ^C, which makes it really difficult to get out of emacs. CYGWIN=tty causes Cygwin to run its programs in a mode with a fairly complete Unix terminal implementation, so ^C can be processed.

You may also want to create a command to let you run Windows GUI programs and open things like Word files. I recommend creating open.cmd in /usr/bin. It just needs one line

start %1
Although you can also pass additional arguments. Once you've created it, make a symlink to it so you can invoke "open" and don't have to use "open.cmd"
ln -s open.cmd open
I also like to make Cygwin use my normal Windows home directory as its home directory. So I edit /etc/passwd, which is c:\cygwin\etc\passwd, changing my entry to have the home directory as /cygdrive/c/users/hedrick, rather than the original /home/hedrick. /cygdrive/c is one way to refer to C: from withing Cygwin. You can actually use C:, but since /etc/passwd uses colons as delimiters, that won't work.

Terminal colors

The Cygwin shell is a slightly tailored version of the normal Windows command prompt. It uses the same colors. I normally like to change to a light colored background with black text. I recommend making that change in the normal command prompt, pulling down the menu from the icon at the upper level of the menu, choosing "Defaults" and then Color. Be careful, because Unix utilities often use multiple colors, e.g. "ls" will show executables in bright green. I recommend changing foreground and background to black and white, and then adjusting white to be whatever pastel you want. I found the bright green almost unreadable against list blue, so I darkened it.

Building an eclectic collection

The other approach is to build up a collection of separate Unix-like programs and collections. This is a matter of philosophy. Do you prefer your "ls" ,"mv", etc. to be native Windows programs that use Windows file names, or do you want a whole Unix environment that feels more like Unix, and has a full set of man pages, files in /etc to administer them, etc. From my point of view the major disadvantage of Cygwin is that at times it feels more like an emulation than fully integrated Unix commands. However the integration has gotten much better in the last few years, and at this point I'm inclined to prefer Cygwin.

If you want to build a collection, a good place to start is Unxutils. You'll want to put usr/local/wbin into your path in Control Panel, System, Advanced, Environment Variables. I normally create a c:\bin where I put all my Unix stuff and put that in the path.

In windows 7, I found it necessary to do chmod +x *.exe to make them executable. Since there's a bootstrapping problem, you can use the File Explorer to set executable permissions for chmod.exe and then do that command.

With Google, you can find several different Windows versions of emacs. I normally search for "win32 emacs."

Another high priority is SSH and friends. Most people seem to use putty. I typically put them in the same directory as my Unix commands, and rename putty.exe to ssh.exe, pscp.exe to scp.exe.

Emacs editing in Firefox and Thunderbird

I really like to use the Emacs editing keys, particularly when composing email, because it lets me avoid removing my hands from the keyboard. To do this, you need to do two things:

By default, control is the normal accelerator for copy, paste, etc. You want to move that function to ALT. To do that, in Firefox go to "about:config". In Thunderbird in Tools, Options, in the Advanced tab, there a configuration editor. In both cases, change ui.key.menuAccessKey from 18 to 0, and change ui.key.accelKey from 17 to 18.

That lets you type control commands, but it doesn't define them. To do that take a look at the Mozillazine article on Emacs keybindings.

You're supposed to be able to create a file in your home directory that overrides the builtin bindings. But it doesn't work, and hasn't for years. I'm guessing it's never going to be fixed. So you need to find toolkit.jar and modify it. There are two of them:

Of course the (x86) appears only on 64-bit Windows. I recommend copying the jar file to a new folder someplace else. Jar files are actually just ZIP file, so you can do
unzip toolkit.jar
emacs content/global/platformHTMLBindings.xml
rm toolkit.jar
zip -r toolkit.jar content
Of course you can use any editor in place of emacs. The Mozillazine article will tell you want change to make to the file. Once you've created the new toolkit.jar, put it back in the original place. For reasons of permissions, you will probably have to use Windows Explorer for that. I recommend renaming the original so you don't lose it.

For more information, contact
Last updated: Sunday, 11-Oct-2009 22:43:27 EDT
© 2009 Rutgers, The State University of New Jersey. All rights reserved.