Introduction to who? If that's what you thought when you saw the title of this article, then it's written for you.

Here's the deal, Windows users [2]: the command line is your friend. But the Windows command line? It's a really bad friend. You know, the kind that would ditch you in a minute if he got an offer to hang out with someone cooler, the kind who re-gifted that Chia pet from Cousin Jeb for your birthday, the kind who sticks you with the bill every time. With friends like that, who needs enemies? If you want to overclock your computing experience at a command prompt on your Windows PC, you need Cygwin.

Cygwin is a Windows command line on steroids which runs tons of well-known, age-old, useful Linux Unix commands. But Cygwin, like much open source software, seems scary, inexplicable and nearly unusable until you've had some sort of "Ah-HA!" moment after hours of bleary-eyed digging through pages of cryptic documentation. Let me save you the work.

Advertisement

Today we'll step through Cygwin installation and execute a few basic commands to usher you along to the "Ah." Next week's part two will get into some more advanced Cygwinnery and hopefully get you to that "HA!"

Ready? Let's get started.

Installation

First download Cygwin's setup.exe, using the "Install or update now!" link on the front page of Cygwin.com. The important thing to understand about Cygwin is that there are tons of optional programs ("packages") that you can install - or choose not to install. Setup.exe does double duty: it gets the Cygwin prompt installed, and can add packages on after the fact.

For now we're just going to get Cygwin going and go back later to add packages as needed. Launch setup.exe to start up the installation wizard, and choose "Install from Internet." Hit Next. Then choose your installation directory (you're ok to leave it the default "c:\cygwin\") and other settings (also fine at the default.) Next choose a temporary directory where Cygwin will store the packages it downloads. I always delete these after I'm done, so any temp directory will work. Choose to download via a "Direct Connection," then you'll be presented with a list of Cygwin mirrors. Keep the default (or randomly choose another) and hit Next.

Sometimes the mirror that you choose will be really slow. You should flip to the "Select packages" screen pretty quickly. If not, go back and choose another mirror that's more available.

Now you're at the Select Packages screen, which is the most confounding part of the installation for newbies. Why? Well, just look at the screenshot (click to enlarge):

Yeah, I know. How about a package called "WTF"? What you're looking at here is a list of Unix programs (most of which look like alien hieroglyphs to Windows folks) all grouped together under certain categories. If you expand the "Base" category by clicking on the plus sign, for instance, you'll get a list that contains such mystery meat items as "bash," "gawk," "grep" and "man." Don't let this list scare you off. If you're curious, you can toggle the "View" button to see the full list sans categories. I don't recommend doing this your first time. It just might make you question every computer skill you thought you had.

Cygwin virgins, just accept the default packages and hit Next, where you'll face the download progress bar. Finally! Something familiar. Seems like a whole lot of steps just to get software installed, eh? When things are all done you'll get the option to create the trusty Cygwin icon on the Desktop or on the Start menu.

Basic Commands

Now you're ready to rock the command line like the Unix badass you're destined to be. Double-click on that new Cygwin icon to get yourself to a "shell" prompt, which will look like this (click to enlarge):

The first few lines ("Copying skeleton files...", etc) will only appear your first time. From here on in, when you launch Cygwin you'll get the standard green yourusername@yourcomputername~ $ greeting.

The dollar sign is the Cygwin prompt where you can unleash all sorts of command line power. We're going to start with some very basic commands to get you going. These will feel and sound strange at first, but once you get used to them, they'll be second nature.

First, we want to see where in the filesystem we are. When Cygwin launches, you start in your home directory, but where's that? We'll use the Unix "pwd" (print working directory) command to see:

penelope@scully ~ $ pwd /home/penelope

Great, but where is this "/home/" directory? It's the Cygwin base directory which you set during installation - "c:\cygwin\" by default. So in my case, I'm in the "c:\cygwin\home\penelope\" directory. Let's make sure. To create an empty file in Unix, use the "touch" command:

penelope@scully ~ $ touch honey-im-home.txt

In Windows Expolorer, if I browse to c:\cygwin\home\penelope\, I see a file created there called "honey-im-home.txt." Ok, good. But what if I have to switch to another disk drive, like D: or H:? Cygwin's a Unix emulator, see, and Unix doesn't know Microsoft's drive letter, colon, slash notation. So to change to (cd) the D:\data\ directory in Cygwin, you'd do:

That /cygdrive/d/ represents the D: drive in Cygwin. Update: Reader Bojan points out you can just type cd d: to switch to the d drive! I stand corrected. Thanks, Bojan!

Notice above that the path of the current directory is listed next to the user@computer notation. It was listed there before as well, with the tilde (~), which in Unix, represents your home directory. So, to change directory (cd) back to your home directory from anywhere in the file tree, you'd type:

If you'd like to see a listing (ls) of all the files in your home directory, just type "ls":

penelope@scully /cygdrive/d/data $ ls honey-im-home.txt

Still with me? Good.

Now, Cygwin enables you to do all sorts of neat text manipulation, search, and networking fun, but I'm going to get into that in part two. For now I want to tackle the most frequent Cygwin question that's appeared in the Lifehacker inbox:

Now, in Windows Explorer, browse to c:\cygwin\home\yrname\ and unzip the todo.zip files. Using a text editor like Notepad, open the .todo file. Edit the 4th line to read TODO_DIR="c:/cygwin/home/username" but replace username with your, you guessed it, username.

Finally, make the todo script executable by changing its mode (chmod). At the Cygwin command line in your home directory, type:

penelope@scully ~ $ chmod 755 todo.sh

You're good to go todo.txt'ing now. Type ./todo.sh and get the todo usage message, as shown (truncated for space reasons.) Keep in mind that dot slash ./ before the todo script tells Cygwin, "Hey, run this here executable script."

Next week: we'll cover appending text to files, grep'ing to your heart's content, wgetting it on, daisy-chaining commands and other Cygwin shenanigans. Hit me up with questions - or share your Unixy Cygwin tricks - in the comments or in an email to tips at lifehacker.com.

[1] Sorry current Cygwin users, this article'll bore you to tears. But we'll enlist your expertise anyway: what commands do you use most in Cygwin? Let me know in the comments and I'll write it up in part two. [back to top]

[2] Mac users have access to all these commands out of the box, those shiny bastards. [back to top]

Gina Trapani, the editor of Lifehacker, is forever indebted to the Cygwin developers. Her semi-weekly feature, Geek to Live, appears every Wednesday and Friday on Lifehacker. Subscribe to the Geek to Live feed to get new installments in your newsreader.