Cygwin for Windows

 

I’ve been a fan of Cygwin for a long time, it gives me access to some of my favorite tools from UNIX. I’ve been using it for years to get open source packages that work on Windows without much fuss.

What is Cygwin?

Cygwin is a UNIX layer on top of Windows, allowing many tools for UNIX to be ported to Windows. It’s very common for open source projects to include a port to Cygwin which is pretty similar to porting over to another version of UNIX. To make matters even easier, the Cygwin distribution includes most of the popular open source programs pre-compiled and easy to install.

Cygwin installer and a small handful of its available packages.

Here’s a quick rundown of the tools in Cygwin that I use on a regular basis. I’m sure I can get versions of all of these native for Windows, but it’s just too easy to install and update them with Cygwin.

ssh

I use SSH all of the time to connect to my servers over the Internet. Using its 
port forwarding
 to create secure tunnels that I can use for remote desktop or pretty much anything else I want, such as database connections. I wouldn’t be caught on the Internet without it.

rsync

Rsync is, without a doubt, the best way to copy files over a slow WAN connection. I use Robocopy whenever I’m on my fast LAN, but rsync is my tool of choice when the link is slow because of the amazing way it sends only differences within a file. I can copy massive database backups in only a few seconds as it seeks out only the changed 20 MB in a 10 GB file.

grep

Whenever I need to find some text in file on my disk, I fall back on grep. I find it to be much more reliable and accurate than the Windows Explorer search, and it’s very fast to boot.

bzip2/zip

I use these two compression tools depending on what I want to do with the file. I use zip in scripts to create files to send to others or to make public on our site (when I’m doing it one-off I typically use Windows Explorer’s Send to Compressed folder.) I use bzip2 when I’m archiving for myself, since it compresses so much better than the standard zip. I hear good things about 7zip, though, and it may one day replace bzip2 in my toolbox.

Can’t be beat for viewing text files on a command line.

tail

I quite often have to deal with text log files, usually as debugging output from a program. Using tail to see the last few lines or with the –follow option to watch the file as it changes is invaluable.

bash

I used to use bash all the time to make up for the scripting deficiencies of CMD.EXE, but I’ve switched over toPowerShell now.

Paths, the caveat.

One thing to be aware of is how paths work in Cygwin. Since it’s essentially a UNIX clone on Windows it uses the UNIX path conventions. There are no drive letters and the path separator is / instead of \. This doesn’t often come up much with the tools I use, but it can bite you occasionally if you’re not aware. To get around the drive letter incompatibility Cygwin creates directories for the root of each of your drives under /cygdrive. So, using grep on your whole D: drive would look like this:

grep -rli "cygwin rocks!" /cygdrive/d