cygpath
Convert between Windows and Cygwin paths
SYNOPSIS
cygpath [options] [path...]
PARAMETERS
--unix, -u
Converts Windows paths to Unix paths (e.g., C:\foo to /cygdrive/c/foo).
--windows, -w
Converts Unix paths to Windows paths (e.g., /cygdrive/c/foo to C:\foo).
--mixed, -m
Converts Unix paths to Windows paths but uses forward slashes (e.g., C:/foo).
--absolute, -a
Forces the output path to be absolute.
--path, -p
Treats the input as a path list (like PATH environment variable) and converts each component.
--dos, -d
Converts to the DOS 8.3 short filename format.
--type, -t
Displays the type of the given path (e.g., unix, windows, mixed, absolute).
--canonical, -C
Canonicalizes the path by resolving . and .. components and removing redundant slashes.
--long-name, -l
Converts to the long Windows filename format.
--short-name, -s
Converts to the short Windows filename format (8.3).
--file, -f
Reads paths to convert from the specified file, one path per line.
--relative, -r
Outputs a path relative to the current working directory.
--volume, -V
Outputs the Windows volume mount point (e.g., C:) for the input path.
--drive, -D
Outputs the Windows drive letter (e.g., c) for a given path.
--list-categories, -L
Lists all known path categories that can be used with --type.
--system, -S
Outputs the Windows system directory path (e.g., C:\Windows\system32).
--programs, -P
Outputs the Windows Program Files directory path.
--home, -H
Outputs the user's home directory path.
--temp, -T
Outputs the temporary files directory path.
--null, -0
Separates output paths with null characters instead of newlines, useful for xargs -0.
--help, -h
Displays a help message and exits.
--version, -v
Displays version information and exits.
DESCRIPTION
cygpath is a crucial utility within the Cygwin environment, a Unix-like compatibility layer for Microsoft Windows. Its primary function is to translate file paths between Windows and Unix conventions. Windows paths typically use backslashes (e.g., C:\Program Files\) and drive letters, while Unix paths use forward slashes (e.g., /cygdrive/c/Program Files/) and a root directory.
This command is indispensable for scripting and applications running in Cygwin that need to interact with native Windows files or programs, or vice-versa. It handles conversions for absolute paths, relative paths, and path lists.
Beyond simple translation, cygpath can also identify the type of a given path, retrieve specific Windows system directory paths (like the Desktop or Program Files), and canonicalize paths. It ensures seamless interoperability between the Unix-like filesystem view of Cygwin and the underlying Windows filesystem.
CAVEATS
- Cygwin Context: cygpath is specifically designed for the Cygwin environment. Its functionality relies on Cygwin's internal path mapping and therefore may not be directly transferable or useful outside of a Cygwin installation.
- UNC Paths: Handling of UNC paths (e.g., \\server\share) can sometimes be complex or behave differently depending on the Cygwin version and configuration.
- Path Delimiters: While cygpath handles conversion, scripts must still be mindful of the path delimiters (/ vs. \) when constructing paths or interacting directly with native Windows commands.
- Performance: For very large numbers of path conversions in a loop, be aware of potential performance overhead, though typically it's negligible for common use cases.
SCRIPTING ESSENTIAL
cygpath is often used in shell scripts to ensure that paths passed to Windows executables or retrieved from Windows programs are in the correct format. For example, a script might convert a Unix-style path to a Windows path before calling explorer.exe or a .NET application.
ENVIRONMENT VARIABLES
When setting environment variables like PATH for use by native Windows applications from within Cygwin, cygpath -p -w (or -m) is frequently employed to convert the Unix-style path list into a Windows-style path list, ensuring Windows programs can correctly locate executables.
HISTORY
cygpath was developed as an integral part of theCygwin project, which began in 1995. Its inception was driven by the fundamental need to bridge the architectural gap between the Unix-like POSIX API and the native Windows operating system.
Early versions of Cygwin provided basic path mapping, but cygpath emerged as a dedicated, robust utility to explicitly manage these translations, becoming a cornerstone for writing portable shell scripts and applications that could seamlessly interact with both Unix-style paths (within Cygwin) and Windows-style paths (for native Windows tools).
Its development has paralleled the evolution of Cygwin itself, with continuous improvements to handle new Windows features, path complexities, and user requirements for cross-platform compatibility.