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.
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:
Click on the Run button. You should see the Cygwin installation page:
Click on the Next button to start the installation. You should see the following page:
Select “Install from internet” and click on the Next button. You should see the following page:
Select your root directory or leave it default and click on the Next button. You should see the following page:
Select your local package directory and click on the Next button. You should see the following page:
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:
Select your desired mirrors and click on the Next button. You will see a long list of packages as shown below.
If you are new to Cygwin then continue with the default and click on the Next button. You should see the following page:
Review all the packages and click on the Next button. You should see the following page:
Select your desired action and click on the Finish button to finish the installation.
Cygwin creates a shortcut icon on the Desktop as shown below:
Double click on the Cygwin icon to launch the Cygwin. You should see the Cygwin interface in the following page:
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:
You should see your current home directory in the following screen:
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:
You should see the following output:
Cygwin-Terminal.ico Cygwin.ico cygdrive etc lib sbin usr Cygwin.bat bin dev home proc tmp var
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:
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:
Working with Directory
To create a new directory named dir1, run the following command:
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:
To check the path of your current working directory, run the following command:
To list all files and directories located inside /etc, run the following command:
You should see the following screen:
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
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:
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
To change the ownership of the dir1 to the administrator, run the following command:
chown.exe -R Administrator dir1
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:
|Action||Windows Command||Cygwin Command|
|remove directory||rd||rm -rf|
|change current directory||cd||cd|
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.