Cygwin: Linux Commands on Windows

Advertisement
Working within Microsoft Windows may not be everyone's cup of tea. Long ago, before windows and scrollbars and maximizing and minimizing, a user could only type commands into a shell to get a computer to do anything.

In some ways, working within a command-line shell can be a lot more efficient than the usual point-and-click of the mouse manipulating windows and pulling down menus. Users that work within a UNIX and Linux environment often need (and want) to control their computer from a command-line prompt (shell).

Cygwin, a collection of libraries that create a Linux-like environment from within Windows, gives you many of your favorite Linux commands and programs, perfect for users that prefer Linux but have to work inside Windows, and ideal for users that are thinking of making the transition from Windows to a Linux distro. Let's install Cygwin (download here), hop inside a shell, and throw some commands at it.

Inside The Cygwin Bash Shell

After installing Cygwin, run the "Cygwin Bash Shell" from the start menu. A black window that resembles a DOS prompt will appear. At the "$" prompt, type in the command "pwd" (without the quotes). This command prints your working directory. By default, you'll be placed inside your Home directory.

Think of this directory as your own private space to do with as you wish. At anytime, if you don't know what directory you're inside of, run the "pwd" command to get your bearings. Now that we know where we are, type the command "ls". This is a common Linux command that lists all files and folders in the current directory.

Your Home directory should be new, so when you execute "ls" it should return nothing, meaning that your Home directory is empty.

To create a new directory use the "mkdir" command like this "mkdir test"; this makes a directory named "test". Now navigate into "test" by executing "cd test". Do a "pwd" to make sure you're inside the correct directory. Let's create a couple of files now. Type in "cat > test1.txt" and hit enter.

Whatever you type next will get input into "test1.txt" until you hit "Ctrl-D", which will save and close the file. The command "cat test1.txt" will output the contents of your text file to the shell.

We've just made a text file. For purposes of demonstration, let's copy it under a different name. Do "cp test1.txt test2.txt", which will copy the contents of "test1.txt" into a text file under a different name. List the contents of the directory with "ls" and you'll see your two new txt files.

Let's pretend that we need to email these two files, but first we'll need to archive them into a single compressed file so that we can attach them easier to an email.

The compressed archive is called a "tarball". Think of tarballs as relatives of zip files. To create a tarball, move back out of your current directory by typing in "cd ..". The ".." will move you back out into your Home directory. To archive your files inside of the "test" directory into a tarball type this: "tar -zcvf new.tar.gz test".

The following command will archive the "test" directory into a tarball (compressed archive) with a .tar.gz extension. Now your tarball is ready to be attached to an email.

Cygwin

Cygwin: Linux-Like Environment

Working within Windows doesn't mean that you're stuck without a powerful shell. Cygwin brings most of the power of a Linux environment shell right into Windows. Most of your favorite Linux commands and utilities are available via Cygwin's Bash Shell. If you're a dedicated Linux user, then Cygwin will make you feel right at home when using Windows.

TOPlist