Unix tools on Windows for fun and profit

By | January 14, 2011

So, your workplace or customers requires you to use Windows on your desktop. You’re a Linux-guy. How do you get by? Or maybe you are not familiar with Unix and Linux and want to try out some new tools on Windows, to make your life easier?
I used Linux exclusively (home, work, school) for eight years until I had to change to the Windows Vista environment at work.

Read on for some tips based on my experiences:

Improving I/O performance

File operations are slow on Vista, and this can be annoying, for example when you are creating and deleting many files regularly as part of your work, for example when you are building a large software product. This is fixed in Windows 7 and Windows 2008.R2. Upgrading my machine to Windows Server 2008.R2, and using it as a workstation helped make Windows quicker and more responsive, and was a good improvement in general.

I also recommend disabling indexing of all drives. Indexing is used for quicker file searches and to maintain the index degrades performance. If you are like me, you don’t use the built-in search function of Windows at all, anyway.

Install Cygwin 1.7 or later

Previous versions of Cygwin didn’t work well with Vista and later Windows-versions, but with Cygwin 1.7, it works nicely.

Get the Cygwin installer from http://cygwin.org. Install it, and make sure to include the ‘mintty’ package when installing.
After Cygwin has installed, create a link to C:cygwinbinmintty.exe -e /usr/bin/bash --login to get a nice Xterm-like terminal that supports resizing and other nifty features.

Cygwin console on Windows screenshot

To get correct the file permissions on files created using Cygwin, you’ll need to fetch group and user information from the local machine and from Active Directory (if using Active Directory, of course).
Cygwin’s ‘mkpasswd’ and ‘mkgroup’ does this job for you.

First add the local groups and users:

mkpasswd -l > /etc/passwd
mkgroup -l > /etc/groups

Then add the network groups and users (this may take long time, depending on how many users and groups there are):

mkpasswd -d >> /etc/passwd
mkgroup -d >> /etc/groups

Command line power to the people

The Unix command line is awesome and can help you save time on a number of tasks. Here are some common use-cases:

Replaces text in files using regular expressions:

> find . -name "*.xml" -exec sed 's/testDataSource/prodDataSource/' {} ;

To detect encoding and content type of text files:

> file Person.java
Person.java: UTF-8 Unicode Java program text

Using ‘find’ to find files and directories:

> find /some/path -name "*I.java"

To find the errors in that xml file, or verify that it is well-formed:

> xmlwf myfile.xml

To change the end of line encoding in text files from Windows to UNIX:

> fromdos MyFileWithWindowsLineEndings.java

and correspondingly, use todos for converting files the other way.

Printing code out on paper:

> a2ps FileOne.java FileTwo.java -o printMe.ps

You can include line numbers, highlight keywords for multiple programming languages, use multiple pages per sheet etc. Send the .ps file to your printer.

Using ‘find’ to find files and directories, combined with ‘grep’ to look inside the files:

> find /some/path -name "*.java" -exec grep -il demo {} ;

Change the encoding of a text file:

> iconv -f ISO-8859-1 -t UTF-8 someFile.xml > newFile.xml

For-loops are your friend! Now changing the encoding of multiple files:

for file in $(find . -name "*.xml");
iconv -f ISO-8859-1 -t UTF-8 ${file} ${file}.new;
mv ${file}.new ${file};

Install KDE

Yes, KDE is available on Windows!
Get the installer from http://windows.kde.org, make sure to run it “as administrator”, and choose to install the latest stable version.

I like to install these packages:

  • kdeapps-base
  • kdebase-workspace
  • kdenetwork
  • kdesdk
  • kdeutils

This gives me (among other things):

  • Kate, a super editor with highlight-support for many languages
  • Okular, the quick and light PDF reader
  • kompare, a powerful tool for showing differences between text files
  • Umbrello, the UML diagram tool

KDE on Windows screenshot

KDE on Windows screenshot

Replace MS Office Communicator

I don’t particularly like the user-interface of MS Communicator. Also, it crashed pretty often for me.
You can replace it with Pidgin, the multi IM-client. Make sure to install the SIPE plugin, to support the protocol MS Communicator (and MS Live Communicator) uses.

Starting programs without clicking the menus

A simple way of supporting the behavior of “alt-f2” or “alt-space” on Linux (KDE, gnome, others) to run a program, is to add the programs to Windows’ PATH and press ‘win-key r ‘ to run an application, like for example ‘kate’.

Install python

Python is great for text-processing and -generation and also as a calculator.
Get it from http://python.org.
I’ve had good use for python to build test-sets in XML based on data from a SQL database.

Leave a Reply

Your email address will not be published. Required fields are marked *