We may earn a commission if you make a purchase through the links on our website.

Cygwin Cheat Sheet

Cygwin Cheat Sheet

Hitesh J UPDATED: February 7, 2023

What is Cygwin?

Cygwin is a free and open-source software that provides a Unix-like environment and software tool set to the users using any modern version of the Windows operating system.

Cygwin consists of Unix system emulation library, cygwin1.dll, together with GNU and other free software applications organized into a large number of optional packages. Cygwin is a POSIX compliant that means it shares a standard APT with other compliant operating systems.

Why Need Cygwin?

Cygwin is a tool for users who regularly use Windows and Linux and want the power of Linux shell running within Windows. It is a very good alternative to Windows PowerShell and Windows Command Prompt. For example, Hadoop runs in the Linux operating system and most of the users have Windows-based laptops. In this case, Cygwin provides a convenient way to install Hadoop, configuration, or development in an emulated environment in a Windows-based operating system.

If you are new to Linux, it is very difficult for you to understand Cygwin. If you are an experienced Linux user and missing a powerful command-line environment then Cygwin is the best tool for you. Cygwin provides a set of utilities to developers who are coming from a Unix background. Cygwin also provides a library to port Unix packages to the Windows system.

Pros and Cons of Cygwin

Pros of Cygwin

  • It requires fewer resources like, CPU, RAM, Disk space compared to running Virtual Machine.
  • Cygwin applications are native Windows applications. So they can easily access the same files and directories as any other Windows application.
  • Cygwin allow you to run the binaries natively without the overhead of Linux VM.
  • You can run Gnome terminal and xterm with Cygwin. You don't need to ssh to VM or even worse switch to VM window.

Cons of Cygwin

  • You will need to tweak Cygwin to get a better user experience and the updates are terrible.
  • Behavior may not be exactly the same as Linux.
  • You will need to recompile each Linux application as Cygwin applications.
  • Linux tools that depend on the Linux kernel cannot be recompiled as Cygwin applications.

Install Cygwin

First, visit the Cygwin official website at https://cygwin.com/install.html and download the latest version of Cygwin to your system.

Cygwin setup.exe file is a Windows-based package manager. It will download and install the minimal version of Cygwin to your system. You can add new packages to your Cygwin software as per your need in future.

After downloading the Cygwin installer package, double click to start the installation. You should see the following page:

cygwin run page

Click on the Run button. You should see the Cygwin installation page:

cygwin setup page

Click on the Next button to start the installation. You should see the following page:

cygwin installation

Select “Install from internet” and click on the Next button. You should see the following page:

cygwin select root directory

Select your root directory or leave it default and click on the Next button. You should see the following page:

cygwin select package directory

Select your local package directory and click on the Next button. You should see the following page:

cygwin select direct connection

Select the direct connection or select proxy if you connect the internet through a proxy and click on the Next button. You should see a list of Cygwin mirrors in the following page:

cygwin select mirror

Select your desired mirrors and click on the Next button. You will see a long list of packages as shown below.

cygwin select package

If you are new to Cygwin then continue with the default and click on the Next button. You should see the following page:

cygwin review changes

Review all the packages and click on the Next button. You should see the following page:

cygwin create icons

Select your desired action and click on the Finish button to finish the installation.

Start Cygwin

Cygwin creates a shortcut icon on the Desktop as shown below:

cygwin desktop

Double click on the Cygwin icon to launch the Cygwin. You should see the Cygwin interface in the following page:

cygwin interface

After starting Cygwin, you will be redirected to the Cygwin how directory which corresponds to your Windows username. You can find your home directory using the following command:

pwd

You should see your current home directory in the following screen:

cygwin current directory

Cygwin Directory Structure

Cygwin creates a directory structure of a Linux system within the directory “c:\cygwin”. You can check it with the following command:

ls /

You should see the following output:

Cygwin-Terminal.ico  Cygwin.ico  cygdrive  etc   lib   sbin  usr
Cygwin.bat           bin         dev       home  proc  tmp   var

cygwin directory structure

How to Use Cygwin Command-line

In this section, we will show you how to use some basic Cygwin commands.

Working with Files

To create a new file named file1.txt, run the following command:

touch file1.txt

To create multiple files named file2.txt, file3.txt, run the following command:

touch file2.txt file3.txt

Not, copy all files to the /etc directory run the following command:

cp file1.txt file2.txt file3.txt /etc/

To rename the file1.txt to file4.txt, run the following command:

mv /etc/file1.txt /etc/file4.txt

To remove file2.txt, run the following command:

rm /etc/file2.txt

cygwin working with files

Working with Directory

To create a new directory named dir1, run the following command:

mkdir dir1

To copy dir1 to the /etc/ directory, run the following command:

cp -r dir1 /etc/

To change the directory to /etc, run the following command:

cd /etc

To check the path of your current working directory, run the following command:

pwd

cygwin working with directory

To list all files and directories located inside /etc, run the following command:

ls /etc/

You should see the following screen:

cygwin list files

Compress and Uncompress Files and Directories

By default, the tar package comes pre-installed with Cygwin. You can use the tar command to compress and uncompress files and directories.

To compress the /etc directory, run the following command:

tar -cvf etc.tar /etc

cygwin compress files

To uncompress the etc.tar to the dir1 directory, run the following command:

tar -xvf etc.tar -C dir1/

You should see the following screen:

cygwin uncompress files

Working with File Permissions

You can use chmod command to set file permission on files and directories.

For example, to set the 774 permission on file1.txt, run the following command:

chmod 774 file1.txt

cygwin set permission

To change the ownership of the dir1 to the administrator, run the following command:

chown.exe -R Administrator dir1

cygwin set ownership

Cygwin vs Windows Basic Commands

Some of the basic commands used in the Windows and their corresponding command in Cygwin are listed in the below table:

ActionWindows CommandCygwin Command
list directorydirls
clear consoleclsclear
copy file(s)copycp
move file(s)movemv
delete file(s)delrm
create directorymdmkdir
remove directoryrdrm -rf
change current directorycdcd
current directorychdirpwd
searchfindgrep
concatenatecatcat
permissionschmodchmod
display/output testechoecho

Conclusion

In the above guide, we learned how to install Cygwin on Windows operating system. We also learned some basic Cygwin commands and their usage. I hope this guide will help you to use Linux commands in Windows environment.

Cygwin Cheat Sheet FAQs

Is Cygwin free?

Cygwin is open source software and is free to use.

Can Cygwin be installed on a server?

Yes, Cygwin can be installed on a server and used for server administration tasks.

How does Cygwin differ from other Windows Linux emulators?

Cygwin differs from other Windows Linux emulators in that it provides a complete Linux-like environment with all of the standard Linux utilities and tools.

What are the system requirements for Cygwin?

The system requirements for Cygwin are: Windows XP or later, a Pentium processor, and at least 64 MB of RAM.

How do you install Cygwin?

To install Cygwin, you need to download the Cygwin setup executable, run the setup program, and select the packages you want to install.

Can you use the Windows command prompt with Cygwin?

Yes, you can use the Windows command prompt with Cygwin, and you can also use the Cygwin shell to run Linux commands.

What are some common uses for Cygwin?

Some common uses for Cygwin include: server administration, software development, and scripting.