Catalog / Cygwin Cheatsheet

Cygwin Cheatsheet

A comprehensive cheat sheet for using Cygwin, a Unix-like environment and command-line interface for Windows. This guide covers installation, basic commands, package management, and configuration tips to help you leverage the power of Cygwin efficiently.

Installation and Setup

Installing Cygwin

Download the Cygwin installer:

  • Visit the official Cygwin website (https://www.cygwin.com/) and download setup-x86_64.exe for 64-bit systems or setup-x86.exe for 32-bit systems.

Run the installer:

  • Execute the downloaded file.
  • Choose ‘Install from Internet’.
  • Select an installation directory (e.g., C:\cygwin64).
  • Choose a local package directory.

Select packages:

  • This is a crucial step. Search and select essential packages such as:
    • gcc-core: C compiler
    • make: Build automation tool
    • gdb: GNU Debugger
    • vim or nano: Text editors
    • openssh: Secure Shell
    • curl or wget: Web download utilities
    • git: Version control system
  • Click ‘Next’ to resolve dependencies and install the selected packages.

Create desktop icon:

  • The installer can create a desktop and start menu icon for Cygwin.

Add Cygwin to the Windows PATH:

  • Add the Cygwin bin directory (e.g., C:\cygwin64\bin) to your Windows PATH environment variable. This allows you to run Cygwin commands from the Windows command prompt or PowerShell.

Basic Configuration

~/.bashrc

Configuration file for bash shell. Customize your shell environment, aliases, and functions here. This is executed for interactive non-login shells.

~/.bash_profile

Executed for login shells. It is commonly used to set environment variables and execute programs that should only be run once at login.

~/.inputrc

Configuration file for readline, the library used for command-line input. Customize key bindings and other input-related settings.

Set the default editor. Example: export EDITOR=/usr/bin/vim in ~/.bashrc.

Ensure necessary directories are in your PATH. Example: export PATH=$PATH:/opt/my_tools/bin

Essential Cygwin Commands

Basic Navigation

pwd

Print working directory.

ls

List directory contents. Use ls -l for detailed listing, ls -a to show hidden files.

cd directory

Change directory. Use cd .. to go up one level, cd ~ to go to the home directory.

mkdir directory

Create a new directory.

rmdir directory

Remove an empty directory.

File Operations

touch file

Create an empty file or update the timestamp of an existing file.

cp source destination

Copy a file or directory.

mv source destination

Move or rename a file or directory.

rm file

Remove a file. Use rm -r directory to remove a directory and its contents recursively.

cat file

Display the contents of a file.

less file

View file contents one page at a time. Use space to scroll, q to quit.

System Information

uname -a

Display system information.

df -h

Show disk space usage.

free -m

Display memory usage in megabytes.

ps

List running processes.

top

Display dynamic real-time view of running processes.

Package Management with `apt-cyg`

Installing `apt-cyg`

apt-cyg is a command-line package manager for Cygwin. It simplifies package installation and removal.

Installation:

download apt-cyg from:
http://apt-cyg.github.io/

# install it (as administrator!)
install apt-cyg /bin

Note: You may need to adjust permissions to allow execution. Also, ensure wget is installed before attempting to download apt-cyg.

Basic `apt-cyg` Commands

apt-cyg update

Update the package list.

apt-cyg install package_name

Install a package.

apt-cyg remove package_name

Remove a package.

apt-cyg search package_name

Search for a package.

apt-cyg show package_name

Show information about a package.

apt-cyg upgrade

Upgrade all installed packages.

Advanced Usage and Tips

Working with Windows Paths

Cygwin uses a Unix-like file system structure, while Windows uses drive letters (e.g., C:\). Cygwin automatically mounts Windows drives under /cygdrive/.

  • C:\ in Windows is equivalent to /cygdrive/c/ in Cygwin.
  • You can navigate to Windows directories using Cygwin paths.

Example:

cd /cygdrive/c/Users/YourName/Documents

Running Windows Executables

You can run Windows executables directly from the Cygwin terminal.

Examples:

/cygdrive/c/Windows/System32/notepad.exe  #Runs notepad
notepad.exe #if C:\Windows\System32 is in your PATH

Mounting Network Drives

You can mount network drives in Cygwin using the mount command.

Example:

mount -f //network/share /mnt/network_share

Replace //network/share with the actual network path.

Troubleshooting

Permissions Issues:

  • Cygwin may have issues with file permissions, especially when accessing files created by Windows.
  • Use chmod and chown to adjust permissions if necessary.

Path Issues:

  • Ensure that the Cygwin bin directory is correctly added to the Windows PATH.
  • Verify that the necessary environment variables are set in ~/.bashrc or ~/.bash_profile.