Cygwin convert windows path to linux path: Difference between revisions
Jump to navigation
Jump to search
(Created page with "Using [http://cygwin-lite.sourceforge.net/html/cygpath.html Cygwin Utilities: cygpath] to convert windows path ↔ to linux path == convert windows path to linux path == <pre...") |
m (Text replacement - "== reference ==" to "== References ==") |
||
| (16 intermediate revisions by one other user not shown) | |||
| Line 1: | Line 1: | ||
Using [http://cygwin-lite.sourceforge.net/html/cygpath.html Cygwin Utilities: cygpath] to convert windows path ↔ to linux path | Using [http://cygwin-lite.sourceforge.net/html/cygpath.html Cygwin Utilities: cygpath] to convert windows path ↔ to linux path | ||
== steps == | |||
# launch [https://www.cygwin.com/ cygwin] | |||
# input the following commands after $ symbol | |||
== convert windows path to linux path == | == convert windows path to linux path == | ||
local directory e.g. {{kbd | key=<nowiki>c:\Program Files\</nowiki>}} | |||
<pre> | <pre> | ||
enclose the whole path with single quote symbol | |||
$ cygpath -u 'c:\Users\User\Desktop\' | $ cygpath -u 'c:\Users\User\Desktop\' | ||
/cygdrive/c/Users/User/Desktop/ | /cygdrive/c/Users/User/Desktop/ | ||
$ cygpath -u 'c:\Program Files\' | $ cygpath -u 'c:\Program Files\' | ||
/cygdrive/c/Program Files/ | /cygdrive/c/Program Files/ | ||
</pre> | </pre> | ||
switch to the specified | remote directory (network drive) e.g. {{kbd | key=<nowiki>\\remote\test path\</nowiki>}} | ||
<pre> | |||
enclose the whole path with single quote symbol | |||
//method1 | |||
$ cygpath -u '\\remote\test path\' | |||
//remote/test path/ | |||
//method2: replace backward slash with forward slash | |||
$ path = '\\remote\path\' | |||
$ echo "${path//\\//}" | |||
//remote/path/ | |||
$ path = '\\remote\test path\' | |||
$ echo "${path//\\//}" | |||
//remote/test path/ | |||
</pre> | |||
switch to the specified local directory | |||
<pre> | <pre> | ||
//method1 | |||
$ cd "$(cygpath -u 'c:\Program Files\')" | $ cd "$(cygpath -u 'c:\Program Files\')" | ||
$ pwd | $ pwd | ||
/cygdrive/c/Program Files | /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 | |||
</pre> | |||
=== troubleshooting === | |||
<pre> | |||
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 `)' | |||
</pre> | </pre> | ||
== 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 26: | Line 73: | ||
</pre> | </pre> | ||
remote directory (network drive) | |||
<pre> | |||
$ cygpath -w '//remote/test path/' | |||
\\remote\test path\ | |||
</pre> | |||
== References == | |||
* [http://cygwin-lite.sourceforge.net/html/cygpath.html Cygwin Utilities: cygpath] | |||
* [http://superuser.com/questions/885700/cygwin-convert-windows-path-to-unix-then-change-dir/1068015#1068015 Cygwin convert windows path to unix then change dir - Super User] | |||
* [https://superuser.com/questions/102233/how-to-go-to-remote-directory-in-cygwin windows - How to go to remote directory in Cygwin? - Super User] | |||
* [https://superuser.com/questions/1068031/replace-backslash-with-forward-slash-in-a-variable-in-bash Replace backslash("\") with forward slash("/") in a variable in bash - Super User] | |||
[[Category:Software]] [[Category:Windows]] | [[Category:Software]] [[Category:Windows]] [[Category:Linux]] [[Category:Cygwin]] | ||
Latest revision as of 17:10, 10 July 2022
Using Cygwin Utilities: cygpath to convert windows path ↔ to linux path
steps[edit]
- launch cygwin
- input the following commands after $ symbol
convert windows path to linux path[edit]
local directory e.g. c:\Program Files\
enclose the whole path with single quote symbol $ cygpath -u 'c:\Users\User\Desktop\' /cygdrive/c/Users/User/Desktop/ $ cygpath -u 'c:\Program Files\' /cygdrive/c/Program Files/
remote directory (network drive) e.g. \\remote\test path\
enclose the whole path with single quote symbol
//method1
$ cygpath -u '\\remote\test path\'
//remote/test path/
//method2: replace backward slash with forward slash
$ 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[edit]
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[edit]
local directory
$ cygpath -w '/cygdrive/c/Program Files/' c:\Program Files\
remote directory (network drive)
$ cygpath -w '//remote/test path/' \\remote\test path\