Cygwin: a Linux-like Environment for Windows®

by (Thomas Hedden)

Many readers have asked for information about free and open-source software that can run on Windows. Such readers should be interested in Cygwin: Cygwin provides a Linux-like environment in a window running on the Windows operating system.

What Cygwin Is Not

It is important to stress that Cygwin is not the same thing as Linux: Cygwin runs on top of the Windows operating system, while Linux is an entirely separate operating system that has a look and feel similar to that of popular proprietary operating systems such as Windows or Mac OS.

Not only is Cygwin not the same thing as Linux, Cygwin is not even a good way to try out Linux. In fact, Cygwin might give you some incorrect impressions about Linux, if you've never been exposed to it before. One common misconception about Linux is that it is only a command-line environment, with no graphical user interface. This used to be true (just as the Windows environment was preceded by the DOS environment), but today Linux provides a GUI (graphical user interface) that is just as easy to use as that of Windows or Mac OS. Although Cygwin can run "X" applications — that is, applications which have graphical windows (see below), for most casual users, Cygwin is primarily a command-line environment, so it will not give users a good idea about what Linux is like today. If you want to try out Linux, read my article Trying Out Linux, which originally appeared in issue 3 of Open Source Update.

What Cygwin Is

Cygwin is a Linux-like environment that runs on Windows. Cygwin runs on all 32-bit versions of Windows, that is all versions since Windows 95, with the exception of Windows CE. The most important things it provides are a shell (command-line environment) and a collection of command-line utilities that are commonly used on Linux (and other flavors of Unix).

If you are a Windows user and are not familiar with Linux or some flavor of Unix, the first thing you will think when you see the Cygwin window is that it resembles a DOS command window. Actually, given their relative chronology, it would be more accurate to say that the DOS command window resembles a Unix terminal window. However, the Cygwin environment is much more powerful than DOS. There are two reasons for this.

The first reason is that it provides more powerful shells. A "shell" is a command-line environment — a program which accepts input commands and executes them or arranges to have them executed. If you are still a little uncertain about what a shell is, you can think of a shell as a flavor of a DOS prompt. Cygwin offers the shells called bash, tcsh, and pdksh, among others. Even by themselves, these shells are inherently much more powerful than the DOS shell.

The second reason why the Cygwin environment is much more powerful than DOS is that it provides command-line utilities which can be run from within these shells and which are not typically present in the Windows environment. Some of the more common of these are grep, sed, gawk (awk), and Perl. There are many others. Before going any farther, it is important to stress that many of the utilities provided with Cygwin — which are also included in all distributions of Linux and all flavors of Unix that I am aware of — are simply absent from Windows. (DOS or Windows versions of some of them do exist, but they are not included with Windows.) It is also important to understand that there is no reason why this should be true. The company that produces Windows simply decided that you either do not want, do not need, would not know how to use, or do not deserve these capabilities.

Getting Cygwin

One of the strengths of free and open source software is that it can run on less powerful hardware than proprietary operating systems. For this reason, I used an older, less powerful computer to demonstrate the downloading and installation process:

The screen shots showing the downloading and installation process were taken on this computer. I timed the entire process of downloading and setting up Cygwin. The total time was about two hours, which included a number of additional packages (see below). The download was performed on Sunday, October 9, 2005, which was the Columbus Day weekend. It is possible that there was less network congestion on that weekend, so the connection speed might have been higher than usual.

To get Cygwin, first go to the Cygwin website. Scroll down to and click on the Cygwin icon (the black letter "C" with a green arrow in it). This will download a Setup program that will automatically download and install all the packages you ask for. Make sure to put the Setup program in a place where you can find it again, in case you want to download additional packages later. (Of course you can download the Setup program again, if you forget where you put it or delete it.) Once you have downloaded the Setup program, double-click on it to run it, as you would any others Windows program. This will launch an installation program which is typical of installation programs on the Windows platform.

Follow the instructions. If you are uncertain about what to do, you can generally accept the defaults and merely click on the "Next" button. After a few steps, the Setup program will present you with a list of "mirror sites" and ask you to choose one. ("Mirror sites" are websites spread out over the Internet which contain mirror images of the files, to prevent any one server from getting too many download requests.) The one you choose is the website from which you will download the actual Cygwin packages. (So far you have only downloaded the Setup program.) Browse through the list to find one that is close to the place where you are downloading the packages. The screen show shows an ftp site in Germany selected. Of course you should not choose this one, unless you live there, but rather one that is close to the place where you are downloading the packages. Also note that you can download using either the ftp or http protocol, in case that is important to you. Since the sites are listed alphabetically, the http sites are listed after the ftp sites.

Screen shot of "Choose Download Site(s)" window of Cygwin Setup program showing the site selected.

The next step is to choose which packages you want to install. The following screen shot shows how the packages are presented. The number of packages that you can select from is truly mind-boggling. It is highly unlikely that any reader of this article would want anywhere near all of them. The easiest thing to do here is to stick with the defaults (the "base" packages) and simply click the "Next" button. This will probably include what you want, and you can always go back later and run the Setup program again to add any packages that you want but did not get.

Screen shot of "Select Packages" window of Cygwin Setup program showing the Archive packages tree expanded and the binaries selected for the packages cabextract, sharutils, tar, and zip, but not unzip, and with none of the source packages selected.

If you do want to explore the packages and add or remove some, here is how to do it. The plus and minus signs in the "Category" column expand and collapse the "tree" to show or hide detail, respectively. The boxes in the middle columns labeled "Bin?" and "Src?" (which may be abbreviated as "B..." and "S...", respectively), indicate whether or not a package is selected (an "x" indicates that it is selected). To toggle the selection, that is whether or not the package is selected, click on the little circles with the two arrows pointing around the circle in the clockwise direction. Note that you can download either the program itself or its source code or both. The column labeled "Bin?" indicates the binary files (the compiled program that is ready to use), and the column labeled "Src?" indicates the source code. Most readers of the article would not be interested in the source code, which is what a programmer would want if s/he wanted to change and/or recompile the program. Unless you plan to do this, there is no need to download the source code.

I wanted to have some packages in addition to the base packages, so I also selected and downloaded the following:

(Of course the additional packages made the download take longer than it would have without them.) Please note that for the purposes of this article I did not download any "development" (programming) packages. However, they are freely available to anyone who wants them: For example, a C++ compiler is available (called "g++"). I may discuss some of these packages in more detail in some future article(s).

Once you have selected all packages that you want, click on the "Next" button to begin the downloading and installation process. A dialog box indicates the progress. Note that if the downloading process is interrupted, it can be resumed where it left off, and that the Setup program will "remember" what packages you requested and which ones are already installed. The packages I selected, which are more than most casual users would need, took up 572 MB of disk space.

Once the download is complete, you can launch Cygwin by double-clicking on its icon on the desktop. The first time you do this, some additional configuration may be done. (This is fully automatic.) Once this configuration is finished, the Cygwin window will appear on the desktop.

Screen shot of blank Cygwin window on Windows 2000 desktop.

What Cygwin Can Do

Perhaps the best way to illustrate the power of the utilities provided by Cygwin is to use a couple of them them to perform a task that translators might find useful in their everyday work.

Let us say I want to modify the word count file produced by the satellite (free) version of Déjà Vu to make it easier to work with. The task at hand is to remove some unwanted columns from these files. The utility to use is called "sed" (short for "stream editor"). The following screen shots were taken on a more powerful computer than were those showing the downloading and installation process. The reason for this is not that Cygwin requires a more powerful computer, but that Déjà Vu does.

Here is the word count file produced by Déjà Vu, which is referred to in the command below as "wc_all.txt":

Screen shot of raw Déjà Vu word count file including the column "Lines", and the columns "Words", "Chars", and "Codes" for both German and English.

Here is the modified word count file, which is referred to in the command below as "wc_eng.txt":

Screen shot of modified Déjà Vu word count file in which the column "Lines" and the columns "Words", "Chars", and "Codes" have been removed for German, but with those for English remaining.

Note that it would be very difficult to do this using the tools provided with Windows, and it would not even be possible with a single command: A number of search-and-replace operations would be required, and probably conversion to a table or a spreadsheet and then back again. Here is the command that converted the file in Cygwin:

$ cat wc_all.txt | sed 's/\(.\{25\}\).\{55\}\(.*\)$/\1\2/' | unix2dos > wc_eng.txt

This command may seem incomprehensible to you. I will not try to explain it here, however, before throwing up your hands in despair, please remember that if you are a translator, you know at least one foreign language very well, and that most people you know find this foreign language incomprehensible. If you can learn a foreign language well, you are equally capable of learning scripting languages like sed.

If you are determined not to learn how to write such scripts yourself, please do remember that you can still run scripts that other people have written, such as the one shown above. It would be easy for someone such as myself to keep a "ready reference" web page of such scripts and explanations of how to use them, and anyone could then simply copy what they needed when they needed it.

If you do wish to familiarize yourself with the Unix command line, there are a number of free tutorials available on the web, which can easily be found by searching the web for the key words "Linux", "Unix", "shell", and "tutorial". There are also many good books on this subject. Here are three, listed in order of increasing geekiness:

  1. Learning the Unix Operating System, 5th edition, by Jerry Peek, Grace Todino, and John Strang
  2. Shell Programming in Unix, Linux and OS X: The Fourth Edition of Unix Shell Programming, 4th edition, by Stephen Kochan and Patrick Wood
  3. The UNIX Operating System, 3rd edition, by Kaare Christian and Susan Richter

If you are already familiar with the Unix shell and want to begin exploring your computer using the "cd" command, note that Cygwin establishes its own home directory, which is within the Cygwin directory. If you want to change to your Windows home directory, you should issue the following commands:

$ cd c:                 change to root directory of C: drive, i.e., C:\
$ cd 'My Documents'     note capitalization and quotation marks

(The italic text on the right is only there to explain the commands: It is not part of the commands.) Note that the shell is case-sensitive and also that folders that contain spaces must be enclosed in single or double quotation marks. Also note that the shell uses forward slashes, as in the Unix world, rather than backslashes, as in DOS or Windows, even though you are navigating on a Windows computer. So, if I now want to navigate to the folder "Translations\2005" within the "My Documents" folder, I will now issue the following command:

$ cd Translations/2005  note capital letter "T" and forward slash instead of backslash

To remind yourself where you are, you can use the "pwd" command:

$ pwd
/cygdrive/c/My Documents/Translations/2005

To list the contents of a directory, the proper command to use is "ls"; for more details use the "-l" option:

$ ls -l                 list files in current directory (detailed list)

If you forget the "ls" command, Cygwin also allows the DOS command "dir", which gives an undetailed listing. To return to your Cygwin home directory, simply issue the "cd" command by itself:

$ cd
$ pwd

To close the Cygwin window, type "exit".

Running X Applications on Cygwin

As mentioned above, it is possible to launch "X" (graphical" applications from Cygwin. This requires downloading more packages, which would take longer and take up more disk space. For the casual user, there is no reason to do this, and this will not be covered in this article. The following screen shot shows a few X applications which can be launched from Cygwin:

Screen shot showing 3 "X" applications — a calculator, NEdit, and Ghostview — launched from Cygwin running on Windows 2000; Ghostview is displaying a pdf file of a German-Language international patent application.

It's time to start downloading from the the Cygwin website!

Click here to return to Thomas Hedden's home page.

Copyright © 1995-2024 Thomas Hedden

This page is viewable with any browser.

W3C browser

Valid XHTML 1.1

Valid CSS!