LinuxCommandLibrary

cygpath

Convert between Windows and Cygwin paths

SYNOPSIS

cygpath [OPTION]... [PATH]...

PARAMETERS

-u, --unix
    Output Unix (POSIX) path (default)

-w, --windows
    Output Windows path with backslashes

-d, --dos
    Output DOS-style path (forward slashes)

-m, --mixed
    Output mixed Unix/Windows (/cygdrive/c/...)

-a, --absolute
    Output absolute path

-l, --long-name
    Use long Windows path names

-s, --short-name
    Use short (8.3) Windows path names

-f, --file FILE
    Read paths from FILE

-p, --path
    Input is a path list (space-separated)

-i, --ignore
    Ignore invalid paths

-z, --null
    Separate output paths with nulls

-C, --cwd
    Output current working directory

-H, --hostname
    Output Windows hostname

DESCRIPTION

cygpath is a key utility in the Cygwin environment, which provides a POSIX-compatible layer on Windows. It translates between Windows paths (using drive letters like C:\ and backslashes) and Unix-style paths (using forward slashes and /cygdrive mounts). This is crucial for scripts and tools that must interoperate with both native Windows applications and Unix-like commands in Cygwin.

By default, cygpath assumes input is a Windows path and outputs the Unix equivalent, such as converting C:\Windows\System32 to /cygdrive/c/Windows/System32. Options allow reversing this, specifying formats like DOS (forward slashes), mixed mode (/cygdrive/c/...), or Windows short/long names. It supports processing files of paths, path lists separated by spaces or nulls, absolute paths, and ignoring errors.

Common use cases include shell scripts calling Windows executables, environment variable adjustments, or Makefile adaptations. For instance, cygpath -w "$PWD" converts the current Unix directory to a Windows path for use in batch files. While powerful, it relies on Cygwin's mount table, so paths reflect configured mounts like /cygdrive auto-mounting.

Overall, cygpath bridges the path format gap, enabling seamless hybrid workflows (approx. 180 words).

CAVEATS

Cygwin-specific; unavailable on native Linux. Depends on Cygwin mount configuration. May fail on uncased or network paths.

EXAMPLES

cygpath 'C:\\Users\\foo'/cygdrive/c/Users/foo
cygpath -w /homeC:\cygwin\home
cygpath -p -u "$PATH" → Unix paths list

DEFAULT BEHAVIOR

No options: Windows input → Unix output. Multiple paths supported.

HISTORY

Part of Cygwin since version 1.0 (1997); evolved with Windows path handling improvements in Cygwin 1.5+ (2000s) and NTFS support in later releases.

SEE ALSO

pwd(1), realpath(1), mount(8)

Copied to clipboard