Cygwin convert windows path to linux path: Difference between revisions

From LemonWiki共筆
Jump to navigation Jump to search
mNo edit summary
Line 19: Line 19:
remote directory (network drive) e.g. {{kbd | key=<nowiki>\\remote\test path\</nowiki>}}
remote directory (network drive) e.g. {{kbd | key=<nowiki>\\remote\test path\</nowiki>}}
<pre>
<pre>
//method1
$ cygpath -u '\\remote\test path\'
//remote/test path/
//method2
enclose the whole path with single quote symbol
enclose the whole path with single quote symbol
$ path = '\\remote\path\'
$ path = '\\remote\path\'
Line 62: Line 67:


== convert linux path to windows path ==
== convert linux path to windows path ==
local directory
<pre>
<pre>
$ cygpath -w '/cygdrive/c/Program Files/'
$ cygpath -w '/cygdrive/c/Program Files/'
Line 67: Line 73:
</pre>
</pre>


remote directory (network drive)
<pre>
$ cygpath -w '//remote/test path/'
\\remote\test path\
</pre>


== reference ==
== reference ==

Revision as of 14:51, 22 May 2019

Using Cygwin Utilities: cygpath to convert windows path ↔ to linux path


steps

  1. launch cygwin
  2. input the following commands after $ symbol

convert windows path to linux path

local directory e.g. c:\Program Files\

$ cygpath -u 'c:\Users\User\Desktop\'
/cygdrive/c/Users/User/Desktop/

enclose the whole path with single quote symbol if the path contains white space characters
$ cygpath -u 'c:\Program Files\'
/cygdrive/c/Program Files/

remote directory (network drive) e.g. \\remote\test path\

//method1
$ cygpath -u '\\remote\test path\'
//remote/test path/

//method2
enclose the whole path with single quote symbol
$ path = '\\remote\path\'
$ echo "${path//\\//}"
//remote/path/

$ path = '\\remote\test path\'
$ echo "${path//\\//}"
//remote/test path/

switch to the specified local directory

//method1
$ cd "$(cygpath -u 'c:\Program Files\')"
$ pwd
/cygdrive/c/Program Files

//method2
$ cygpath -u 'c:\Program Files\'
/cygdrive/c/Program Files/

copy the above path & paste to the console
$ cd /cygdrive/c/Program Files/

$ pwd
/cygdrive/c/Program Files

troubleshooting

enclose the whole path with single quote symbols ex: cygpath -u 'c:\Program Files\' if the path contains spaces
$ cygpath -u c:\Program Files\
met error, press ctrl+c to escape

enclose with double quote symbols after cd command ex: cd "$(cygpath -u 'c:\Program Files\')" if the path contains spaces
$ cd $(cygpath -u 'c:\Program Files\')
-bash: cd: /cygdrive/c/Program: No such file or directory

$ cd '$(cygpath -u 'c:\Program Files\')'
-bash: syntax error near unexpected token `)'

convert linux path to windows path

local directory

$ cygpath -w '/cygdrive/c/Program Files/'
c:\Program Files\

remote directory (network drive)

$ cygpath -w '//remote/test path/'
\\remote\test path\

reference