How To: Get Linux Power on Your Windows PC with Cygwin

jamor

We believe that everyone who considers themselves a computer enthusiast should have at least some experience with a Linux environment, but it can be daunting to just jump into the deep end of a completely unfamiliar operating system. One way to get your feet wet is with Cygwin, a free program that provides you with a Unix-like command line, without having to leave Windows. Cygwin is not a Unix emulator (it cannot run native Unix programs, although it does contain the tools needed to compile and run a program from source code), but it does have a wide array of optional packages that let you use most of the tools and utilities that you would commonly use in Unix, in Windows. In this guide, we’ll show you how to get Cygwin set up, the basics of how to navigate a Unix file system, and how to find more information as you need it.

1. Install Cygwin

To get started with Cygwin, go to www.cygwin.com and click the link that says “Install or update now.” Run the setup.exe program that gets downloaded, and when asked, select the Install from Internet radial button. The location that you choose to install Cygwin to is important, because that same folder will (by default) act as the root of your simulated Unix file system. In other words, pick somewhere with a little extra disk space. You’ll be asked where to store the downloaded installation files (anywhere’s fine, as long as you have enough room to handle what can be a gig or two of optional packages) and what kind of connection type you use. For most people, the Direct Connection setting will be fine.


(Image A)

You’ll also be asked to choose a mirror to download Cygwin from (image A). You can choose one at random if you want, but since the download might be pretty sizeable (depending on what components you choose to install) it could be worth your time to check out the official mirror list at www.cygwin.com/mirrors.html and select one that’s located close to you. You can copy-paste mirror addresses to the User URL field at the bottom of the window.

There will be a short download, then you’ll get to the meatiest part of the installation process—the package selector (image B). Here, you’ll select which packages you want to download with Cygwin. These packages define what functionality Cygwin will have once installed, and there are a lot of them. If your goal right now is to just get your toes wet and see what this whole thing’s about, you can leave only the defaults selected, which will provide basic command-line functionality. We’ll also show you how you can add any of these packages at any time, so don’t worry that you’re passing up something you’ll need later.


(Image B)

Click through the rest of the installer, and wait for Cygwin to download and install the files it needs. Save the setup.exe file somewhere, because you’ll need it if you want to install more packages in the future.

2. Run Cygwin

Now that you’ve installed Cygwin, run it by clicking its entry in the Start menu. You’ll see a window with the bash shell running—the same shell used by GNU Linux (image C). You should see some configuration files, your Windows user name (which is also your Cygwin username, by default), and a dollar sign, which is the start of the command line. The ~ after your user name shows that your current directory is the home directory—think of it as C:\ in Windows.


(Image C)

That said, the home directory that you’re looking at in Cygwin is not C:\, but a folder in your Cygwin directory. By default, your home directory is located in C:\Cygwin\home\[your user name] in the Windows directory tree, and all folders and files you create will be in there. To test this, type mkdir test into the command line, then hit Enter. This is the Linux equivalent of the Windows mk command, and creates a directory in the current active folder, using the argument as a name.

To see the directory you just created, type ls . This displays the contents of the current folder—the equivalent of the Windows dir command. You should see your test directory. To switch to that directory, type cd test just like you would in Windows. To return to your home directory, type cd ~ at any time.

Here are some other basic commands you’ll need to navigate Cygwin (and Linux):

del [file] – Delete [file]
cp [file] [directory] – Make a copy of [file] and put it in [directory]
mv [file] [directory] – Move [file] to [directory].

3. Learn Your Way Around New Programs


(Image D)

So, that’s the basics of navigating around the Cygwin file structure. Of course, if you want to do anything more than shuffle file structures around, you’ll need to install more packages. For instance, if you want a more powerful text/code editor, you might do a search and find out there’s a very well-regarded program called Emacs available. To download the package, just run the setup.exe program that you used to install Cygwin, and click through to the package selection screen. Packages you downloaded the first time around will be marked Keep (image D) and everything else will say Skip. Find the Emacs package, and click Skip, so that it changes to a version number to download. Finish the setup.exe program, and you’ll now have a new text editor for Cygwin. To test it out, type emacs test.txt —the Emacs editor will open (image E). But getting around Emacs is pretty tough at first—there are tons of hotkeys to memorize. So how do you use it? For that matter, how do you use any of these programs?


(Image E)

Obviously, we can’t tell you how to use every command—even a thorough walkthrough of a single complicated command wouldn’t fit into this article. Instead, we’ll give you a quick primer on how to educate yourself. If you’ve got a command that you think you’d like to use, but you aren’t sure how, entering the command man followed by that command (for instance: man emacs ) will show you the manual page for the command (image F), including a description of what it does, what sort of syntax it takes, and which flags it can accept. In the manual display, scroll down through the document with the space or E key, and scroll up with W or Y. If you want information about a certain topic, but don’t know the name of the specific command, use man -K [search term] to search through all manual pages.


(Image F)

Around the web

by CPMStar (Sponsored) Free to play

Comments