Cygwin offers a collection of UNIX-compatible utilities that can be run on Windows, and offers a convenient means of connecting to remote servers via ssh. One of the differences between Cygwin and a comparable utility, PuTTY, is that Cygwin can be used on both local and remote hosts, whereas PuTTY can only be used to connect to and execute commands on the remote machine.

When running on Windows, Cygwin transforms Windows file paths, such as C:\Users\user123\Desktop, to the equivalent UNIX-like representation, /cygdrive/c/Users/user123/Desktop. By running the mount command from Cygwin (the actual terminal application is called MinTTY), you can see how Cygwin represents all available drives. For example, on my computer has C & E drives. Here’s the result of running mount:

$ mount
C: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)
E: on /cygdrive/e type ntfs (binary,posix=0,user,noumount,auto)


As you can see, each drive is prefixed with /cygdrive, and having to type this every time when switch directories gets to be a pain. Fortunately, it’s possible to change this temporarily and permanently. We’ll demonstrate how to replace /cygdrive with / using both approaches.

First Approach: Temporary Path Prefix Modification

Referring to the mount command’s help menu, notice the --change-cygdrive-prefix option and description:

$ mount --help
Usage: mount [OPTION] [<win32path> <posixpath>]
       mount -a
       mount <posixpath>

Display information about mounted filesystems, or mount a filesystem

  -a, --all                     mount all filesystems mentioned in fstab
  -c, --change-cygdrive-prefix  change the cygdrive path prefix to <posixpath>
  -f, --force                   force mount, don't warn about missing mount
                                point directories
  -h, --help                    output usage information and exit
  -m, --mount-entries           write fstab entries to replicate mount points
                                and cygdrive prefixes
  -o, --options X[,X...]        specify mount options
  -p, --show-cygdrive-prefix    show user and/or system cygdrive path prefix
  -V, --version                 output version information and exit


We can use --change-cygdrive-prefix from an active Cygwin session to replace /cygdrive with /. Once it has been changed, we can switch to our C: drive by running cd /c instead of cd /cygdrive/c. Note that after executing the command, running mount with no arguments will list of drives with the new prefix:

$ mount --change-cygdrive-prefix /
$ mount
C: on /c type ntfs (binary,user,noumount,auto)
E: on /e type ntfs (binary,user,noumount,auto)


Note that modifying path prefix in this manner will only last the duration of the session in which it was explicitly altered. Any new sessions will revert back to the original path prefix of /cygdrive. Fortunately, it’s possible to make the change so that it persists across sessions.

Second Approach: Permanent Path Prefix Modification

If you navigate to the top-level of your Cygwin installation, there exists a folder named etc. Within that folder is a file named fstab, which stands for File System Table, which, on Linux machines is a configuration file that tells the host which devices (or virtual devices) to use on boot. For Cygwin versions <1.7, changing the prefix with the mount command automatically became permanent by updating the relevant registry entry. In Cygwin >=1.7, mount points are no longer stored in the registry but are instead read from /etc/fstab.

If you open the file into a text editor, you’ll see something similar to the following (lines beginning with # are comments and do not represent file system table configuration commands:

# /etc/fstab
#
#    This file is read once by the first process in a Cygwin process tree.
#    To pick up changes, restart all Cygwin processes.  For a description
#    see https://cygwin.com/cygwin-ug-net/using.html#mount-table

# This is default anyway:
none /cygdrive cygdrive binary,posix=0,user 0 0


We need to replace the /cygdrive component in the line starting with none above with the new path prefix. The best approach is to copy the line starting with none, paste it below, then comment out the original. Then on the copied line, update /cygdrive with the desired path prefix. Here’s my updated /etc/fstab after setting the prefix to /:

# /etc/fstab
#
#    This file is read once by the first process in a Cygwin process tree.
#    To pick up changes, restart all Cygwin processes.  For a description
#    see https://cygwin.com/cygwin-ug-net/using.html#mount-table

# This is default anyway:
# none /cygdrive cygdrive binary,posix=0,user 0 0
none / cygdrive binary,posix=0,user 0 0

Be sure to update the cygdrive starting with /, not the standalone cygdrive.

After a restart, all subsequent Cygwin sessions will use the newly specified path prefix. If you need to revert back to the /cygdrive prefix for any reason, delete the new line and uncomment the original.

Note that if you have references to the original /cygdrive path prefix in your .bashrc, .bash_login or .bash_profile, they will not be updated when you make this change, so it is important to go through and update any references that have become invalid.

One final word of caution: If you make the change to /etc/fstab in a text editor that doesn’t allow explicitly setting the newline character, after making the change, you might get an error indicating that \r is an invalid character, and as a result, the changes you made the /etc/fstab will not be recognized. This is because Cygwin expects files with UNIX/Linux-style line endings, \n (line feed), as opposed to the Windows native carriage return and line feed (\r\n). Many text editors allow you to set the end of line mode directly, so be sure to set it to “line feed” or \n or LF.

As a quick summary, here are the end of line characters and various aliases:

  • \r, Carriage Return, CR, 0x0D: Moves cursor to the beginning of the line without advancing to the next line.

  • \n, Line Feed, LF, 0x0A: Moves cursor down to the next line without returning to the beginning of the line. Line Feed is used as a newline character in UNIX based systems.

  • \r\n, Cariage Return Line Feed, CRLF, EOL, 0x0D0A: Moves cursor down to the beginning of the next line. This character is used as a new line character in Windows operating systems.

I’ve found that making this change has really improved my overall Cygwin experience, which important given that it is one of the few applications I use each and everyday.