Allow WSL to recognize Windows path names?
A useful feature of the windows command prompt is to be able to copy and paste the path from the file explorer into the command prompt and then change directories using cd. Right now, there doesn't seem to be a way to do this in WSL, besides manual entering. Could you maybe consider adding a feature for WSL to recognize windows paths and convert them to linux paths?
Definitely an interesting idea, I agree it'd be nice if there was a tool inside WSL that could translate a windows path. I'd suggest filing a request on our User Voice page for this.
If anyone wants a workaround, here's a quick hack that achieves this purpose:
https://gist.github.com/aseering/a06219e74c7f96ccea5ec65d5b2483b5
Use as, for example:
$ ls "$(winpath.sh $'C:\Program Files\Windows NT')"
Accessories TableTextService
The script treats the Windows path as case-sensitive; that wouldn't be especially hard to fix, but it'd take more than a simple sed one-liner :-)
hi @aseering I have very basic skills: how to apply your workaround and have the auto conversion from "C:\Users\me\Documents\GitHub" to "/mnt/c/Users/me/Documents/GitHub".
Thank you
Babun shell has such a helper built in, though it uses a different prefix (/cygdrive/). One can paste a windows path into Babun terminal and it is converted to Cygwin-style mount compatible path. The path has to be quoted before when it contains space characters.
Don't do this. It is one of my main issues with cygwin. Sometimes it works, sometimes it does not. Maybe some programm you are calling does not understand the unix or windows path format and you are never quite sure which one works. Stay consistent. Stay with Ubuntu userland. Unix paths. Don't do some half baked compatibility layer in between that translates Windows paths.
I agree, don't make the terminal recognize Windows paths by default.
Instead I'd like to see a tool like cypath that can be used to convert Windows paths into the correct WSL counterparts. Maybe a fork of cygpath?
Using regular expression to replace slashes with backslashes and /mnt/x with x: won't be enough though. You also need to handle the special directories that are mounted within lxss:
LXSS = C:\Users\<WINUSER>\AppData\Local\lxss
/mnt/d -> D:
/mnt/D -> <LXSS>\mnt\D
/home/<NIXUSER> -> <LXSS>\home\<NIXUSER>
/root -> <LXSS>\root
/usr -> <LXSS>\rootfs\usr
Update:
Here's a shell script that should handle all the above mentioned cases: https://gist.github.com/darealshinji/61d97abf462c1dff9c582f3d94e16c58
Having a standard tool that always does the correct mapping would be the best option here. Then it can be used in a subshell to convert Windows path to WSL (or back) in the middle of the command, if and when needed.
Although a convert utility like cygpath.exe would be handsome, I'd like it much better if the WSL kernel functions (exec..., chdir, ...) could just accept valid windows paths (if there is no directory named C:, etc. in the current location) - cygwin allows this.
This also seems to be, what "Anjan" suggests at uservoice.
With this, at least bash should be able to cd into a windows directory - a quick strace shows chdir("C:\\Windows") = -1 ENOENT (No such file or directory) if I try to cd 'C:\Windows' in bash.
As this feature might add an ambiguity, it should be possible to enable or disable this behavior. (Cygwin only allows to warn about Windows-style paths ((no)dosfilewarning), but I think it should be possible to disable the feature completely.)
This bugs for quite some time now. Strange that this is still open. I just tried out the new VS 2017 build linux command line tools feature using WSL itself as gdbserver and compiled this: https://gist.github.com/larsonmars/bf9b691c359bbd4be31e1e1e36277bbf worked for me, but there should be a better option...
An equivalent of cygpath is suggested on uservoice. Vote for it there! https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/19380883-small-collection-of-official-wsl-utilities-akin-to
Windows Insider Build 17046 contains new 'wslpath' functionality that supports path translations. See the release notes for more details.
Can someone close this issue?
how use wslpath to make WSL to recognize Windows path names?
Thank you
@aborruso , from the release notes mentioned above:
wslpath usage:
-a force result to absolute path format
-u translate from a Windows path to a WSL path (default)
-w translate from a WSL path to a Windows path
-m translate from a WSL path to a Windows path, with ‘/’ instead of ‘\\’
EX: wslpath 'c:\users'
@aaccioly thank you.
Is there a way (an helper) to drag & drop a windows path on WSL and to have it automatically converted in Linux path (in babun it works in this way)?
@aborruso, AFAIK there is no such utility yet. Issue #1501 may be of interest.
I know that issue, but it's closed.
Thank you for all
No, it's not closed sorry and thank you again
Hi @aaccioly seems lots of people hope wsl can support this feature: drag a file into wsl bash terminal (maybe it is running tmux), for example: c:\test\test.py, then wsl will automatically show /mnt/c/test/test.py
that is very helpful!
moreover, I want to remind as a security researcher. do not let wsl bash terminal support c:\test\test.py, that could cause unknown security issue!
If you want to change to a directory using a #Windows10 style path in a #WSL console, you can define the following alias in your ~/.bashrc file:
alias cdw='f(){ cd wslpath $1; unset -f f; }; f'
After restarting your terminal, you can do:
$ cdw "c:\the\windows\target\path"