Cygwin

Cygwin environment

Cygwin environment provides Windows users with Unix-like command-line tools. To access these tools, Cygwin Bash Shell is recommended (available in Start Menu/Programs/Cygwin). The installation procedure and a screenshot of the shell is presented below, together with some basic commands.

Installation

Cygwin is a UNIX environment for Windows. It consists of two parts: a DLL (cygwin1.dll) which acts as a UNIX emulation layer providing substantial UNIX API functionality, and a collection of tools, ported from UNIX, which provide UNIX/Linux look and feel.

The installation procedure for Cygwin described below explains all screen that you will see during the installation.

Step 1:

Press 'Next' to continue the installation.

Step 2:

We are going to download the files from the internet. Press 'Next' to continue.

Step 3:

You must now set the local root directory. You don't have to change the default values, but make sure that the default text file type is Unix. Press 'Next' to continue.

Step 4:

You must now give a temporary directory for the Cygwin installation. The default suggestion can be used.

Step 5:

We use a direct connection for the download.

Step 6:

Select a download location and click next.

Step 7:

Cygwin will now download a small file.

Step 8:

You must now select all packages that must be installed. You can use the default settings, but you must add some extra packages to make the software work. Make sure you select the following packages:
  • Devel/make
  • Devel/gcc

Basic usage

In the prompt, Cygwin displays username and the computer name (green s000000@s000000), followed by the current directory (yellow /cygdrive/d/mmips, or ~ for "home" directory).
The $ character is a part of the prompt

To change directory, you can use cd command with the target directory parameter. The target directory can be expressed in a DOS-like manner (d:/ or d:/mmips). Note that drives in Cygwin are treated as directories, and the usage of forward slash in place of the DOS backslash (d:/mmips instead of d:\mmips).
Instead of DOS-like directory specification, you can use canonic Cygwin directory specification, which maps all system drives to subdirectories in the directory /cygdrive/. I.e. DOS C: drive can be accessed in Cygwin by /cygdrive/c, D: as /cygdrive/d, etc.

To display the contents of the current directory, you can use ls or dir commands. ls -la will provide more details, including file access permissions, size and modification date.
To run Windows Explorer in the current Cygwin directory, you can type

$ explorer .
Note the 'dot' at the end of the line. Dot means 'current directory', while double dot '..' means parent directory.

A useful Bash feature is automatic filename completion. If you start typing a filename (as in the screenshot, we start typing cd gtk to change to gtkwave directory), and press the Tab key, Cygwin will automatically complete the name with the filename from the current directory. If there are more than one files with the same beginning of the name, double Tab will display a list of possible completions.

Program search path

The way Cygwin looks for a program to execute when you type the program name (e.g. explorer) is similar to DOS: it looks for the executable file explorer or explorer.exe in all directories specified in the environment variable $PATH.
To see, which program will be executed, use which command:
$ which explorer
/cygdrive/c/WINNT/explorer
If you are having problems executing a program, e.g.
$ foo -a 1
foo: Command not found
try examining the value of the PATH variable
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/cygdrive/c/PROGRA~1/Borland/CBUILD~1/Projects/Bpl:
/cygdrive/c/PROGRA~1/Borland/CBUILD~1/Bin:/cygdrive/c/WINNT/system32:/cygdrive/c
/WINNT:/cygdrive/c/WINNT/System32/Wbem:/cygdrive/c/matlab6p1/bin/win32:/cygdrive
/c/Program Files/Hummingbird/Connectivity/7.10/Accessories/:/cygdrive/d/mmips/l
cc/lccdir:/cygdrive/c/PROGRA~1/Borland/CBUILD~1/Projects/Bpl:/cygdrive/c/PROGRA~
1/Borland/CBUILD~1/Bin:/cygdrive/c/WINNT/system32:/cygdrive/c/WINNT:/cygdrive/c/
WINNT/System32/Wbem:/cygdrive/c/matlab6p1/bin/win32:/cygdrive/c/Program Files/Hu
mmingbird/Connectivity/7.10/Accessories/
and check if the program you're trying to execute is in any of the directories named there. Note that the Cygwin root directory '/' is where you installed cygwin, e.g. c:\cygwin. E.g. /usr/bin in the default installation is in fact c:\cygwin\usr\bin

Note that by default the current directory (.) is NOT in the PATH. Therefore if you want to call an executable in the current directory, you need to specify the path to it, i.e. instead of

$ foo
use
$ ./foo

Adding new directories to search path

To add a new directory to the path use
$ PATH=/cygdrive/c/new/directory/with/executables:$PATH
This will however only be set for the current Bash session, so if you close Bash window, this change will be lost.
To add a directory to the path permanently, add it to the Windows PATH variable: in Start Menu/Settings/Control Panel/System/Advanced/Environment Variables, Edit the variable PATH, and add c:\new\directory\with\executables, separated by the colon ; from the other path components.
Note, that while in Bash you use Cygwin directory notation (/cygdrive/c/), in Windows you have to use DOS notation (C:\)

Missing programs

If you're missing a program which should be a part of Cygwin installation, you Cygwin installation may be incomplete.
Via the
Cygwin website you can search, which package contains the program you need and then use the setup program to add this package to your installation.
Last updated: Thu, 6 May 2004 09:10:22 +0200