24

I use Linux subsystem of windows 10(windows 10 version 1803)

I can use command line:

user@laptop:~$ wslpath -w /c/
C:\

But when I try to use

user@laptop:~$ wslpath -w ~
wslpath: /home/user: Result not representable

Even I use:

user@laptop:~$ wslpath -w /home/user
wslpath: /home/user: Result not representable

why? how to translate the /home/user to windows path?

my home folder path in windows is C:\Users\winuser\AppData\Local\lxss\home

I expect some command line can give me return that string.

user504909
  • 9,119
  • 12
  • 60
  • 109
  • Here is an alternate way to do it using sed command. ` echo "/home/user" | sed 's#/#\\#g'`. This may not help with the drive letter c/d/etc. – Robert Ranjan Nov 26 '18 at 04:00
  • this is my window path for /home/ folder : "C:\Users\winuser\AppData\Local\lxss\home", I do not only want to change Linux path format to windows format. I need the whole path string of window. @RobertRanjan – user504909 Nov 26 '18 at 04:16

3 Answers3

31

Updated guidance for users of Windows 10 1809 or later:

In Windows 10 1809, we (finally) shipped filesystem integration allowing you to access the files in your WSL distros from Windows via the \\wsl$ UNC path:

enter image description here

If you're interested in the details behind how this works, please visit this blog post: https://devblogs.microsoft.com/commandline/a-deep-dive-into-how-wsl-allows-windows-to-access-linux-files/

This now allows wslpath to provide a Windows-accessible path to files within your distro's filesystem:

enter image description here

In the up-coming Windows 10 May 2020 Update (2004), you won't have to remember the somewhat obscure \\wsl$\ UNC path - instead you'll just click on the Tux (Linux penguin) icon in your File Explorer:

enter image description here

Warning for WSL1 users:

Do not try to spelunk to the %localappdata%\lxss\... folders containing your WSL1 Linux files from Windows - there be dragons!

Please read this post: https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/

This guidance has not, and will not change, though it will become less important over time: In particular, WSL2 does not use %localappdata%\lxss - instead it stores your linux files within EXT4 formatted VHDX files delivering near-native IO performance for the distro's local filesystem.

Rich Turner
  • 10,800
  • 1
  • 51
  • 68
  • Hey, you really shouldn't assume the reasons people want to do things. I need to convert linux paths to windows paths in order to mount them through Docker for Windows. The files are on Windows and typically accessed the way you mentioned. Yet, the way Docker is designed, it needs Windows paths. – Chad Bernier May 06 '20 at 03:04
  • 2
    Chad. If you do spelunk directly into the Windows folders containing the WSL (1) distro files, it is very likely you'll end up with corrupted files and/or data loss. This is not a frivolous warning. That's why there's a big red banner across the top of the blog post. This said, since you can now access WSL's files via the new filesystem integration in 1809 or later, I've updated the guidance above. – Rich Turner May 15 '20 at 18:53
  • Yes Rich, thanks for the update, but I do already know this, and you are making more assumptions. I already have known about this risk from the very beginning. That's why the files are actually stored on the Windows side in the first place, as recommended. Ok, the OP was trying to get those linux files, and you are replying to that scenario, but it isn't the only scenario. I said this part in my comment. Let's do any example. I have my files in C:\Users\chad\data for example. On wsl, that would show up as /c/Users/chad/data. – Chad Bernier May 21 '20 at 02:01
  • You might have even symlinked this folder to somewhere else, like /home/chad/data. So now you write a bash script that detects the directory it is in is /home/chad/data/repos/project1/src. And you want to figure out how to get from there to C:\Users\chad\data\repos\project1\config. You want to generalize this so it works for any project and any user without requiring people to edit the script each time. And you need to pass this path to Docker. That is the scenario I am trying to solve. I should write my own question probably. – Chad Bernier May 21 '20 at 02:09
  • I also discovered this \\wsl$\ thing and I appreciate you updating your answer. However, that doesn't help me either. This path is accessible from Explorer, but Docker doesn't recognize it, AFAIK. Have you successfully gotten Docker to use one of these UNC paths, because I failed to do so? So how do I write a bash script to solve this scenario that isn't more complicated to use than it's worth? Also, the same script should work on OSX! Because there's a 50/50 chance the next person who runs your script will be using a Mac, and you want to keep this process as parallel as possible? – Chad Bernier May 21 '20 at 02:26
  • And many of the intended recipients of your script are not actually professional Software Engineers, so there's gaps in their knowledge and experience. They are Data Scientists, Statisticians, Molecular Biologists who aspire to be Data Scientists, etc. Their background might be writing notebooks that only themselves ever run, but now they are trying to learn how to write enterprise level APIs with all the security and other "engineering" stuff that comes along with that. So you don't want to overwhelm the beginners to the point that they get discouraged and give up. – Chad Bernier May 21 '20 at 02:31
  • 1
    Trying to turn Scientists into Engineers is no easy task. This is the use case I'm trying to solve, and it's the use case of the future. More and more companies are eventually going to catch on to AI technology and want to integrate Data Scientists into Product Development teams. Thank you for all the wonderful work you've been doing at Microsoft lately. They've made major progress, but still not perfect for people like me. It's getting there though. – Chad Bernier May 21 '20 at 02:40
  • Also, I know that WSL2 is going to solve several of my problems and make life easier, but it's still not out. I've been waiting over a year for it. It's not a good idea to but Window's Insider Builds on your corporate owned production machine, right? How long after the actual release will it be before enterprise machines actually get the update? How long until I can stop "supporting" WSL1 in the tools and documentation I build? So the rest of us have been both enjoying yet suffering through the problems of WSL1 in the meantime. Better than nothing. Wish we didn't have to wait for new windows. – Chad Bernier May 21 '20 at 02:46
  • The scenario I'm describing doesn't sound all that uncommon to me. I can't be the only one who wants to do this. If you want to use a Windows machine to write enterprise non-JVM type, (aka, python, R), Linux software, then you will need WSL and Docker. This is a very common scenario. You need Docker volume mounts so you can mount in stuff like certificates, passwords, api keys, aka, stuff you don't want in git! My team can't be the only ones trying to do this? Thanks though. WSL/ Windows Terminal / VSCode, is great stuff. – Chad Bernier May 21 '20 at 03:14
  • 4
    @Chad. With respect, these comments are not a sensible place to have this kind of conversation. As you point out some way through your 7-part response you should likely post your own question, and/or reach out to me on Twitter – Rich Turner Jun 16 '20 at 00:08
  • I have winver 20_04, but do not see the linux icon in explorer. – Timo Jan 03 '21 at 12:12
  • 1
    @timo Have you enabled WSL? – Rich Turner Jan 11 '21 at 17:38
  • I am Timo with big T;) That's why I just got your message. Well, I can use debian, and the wsl command, so probably is enabled. My cmd /c ver shows `Microsoft Windows [Version 10.0.19041.685]`. Maybe it is 2004 but not the updated one? – Timo Jan 25 '21 at 12:26
17

To convert a WSL Linux path to a Windows path use wlspath -w. For example:

$ wslpath -w /mnt/c/Users
C:\Users
$ wslpath -w /usr/bin
\\wsl$\Debian\usr\bin

(Yep, the answer is in the question, but some people, like me, are going to skip straight to the answers without reading the question.) The problem reported by the OP doesn't exist in WSL2.

Samuel
  • 8,063
  • 8
  • 45
  • 41
0

In your wsl you can execute $ explorer.exe . This will open a window. You can copy the path.