Tuesday, June 02, 2020

Access WSL2 Linux Files from the Windows aka File Explorer

Just trying

$ > explorer.exe .

When your in the linux shell, as some folks suggest, doesn't work. It just opens up a default File Explorer.

But, I got lucky when I watched David Bombal's YT video on WSL2 - he suggests

If you google the thing "access WSL2 files with File Explorer", you get to a github thread that shows you the solution..

In a powershell, do

>  subst Z: \\wsl$\Ubuntu-18.04\home\<user>

And then you can access Z: from your File Explorer. The great question is, how are you supposed to know what to put in for the subst command after teh Z: ? :)

I got lucky watching David Bombal's so-so video on WSL2 (his min req version is incorrect, if you're on an x86 type, you only need 1904). He says to try :

$ > code .

while you're in the WSL2! That is, you did Start > Ubuntu and launched the command-prompt on the Ubuntu instance and now, at that prompt, you do what he suggests... and that launches Visual Studio Code showing you files in that directory. Now, all you have to do is find a subdirectory within your home directory and say "Open in integrated terminal" and it'll launch in VS Code's own version of PowerShell - and you're done!

Pro-tip : Use the Window Terminal Preview from now on - forget command prompt. This is already PowerShell with CTRL+plus/minus to adjust font size! And, did you know you could adjust font size in cmd prompt and PS with just CTRL-scrollwheel? Yes!!

Now, what if you want GUI apps? WSL2 enables that.. This will really help you give Cygwin the finger :) Cygwin is a sad case of permanent adolescence - sad to say since I've personally gotten so much out of it.. It just lacks the feel of a real product. And there's always something broken..

What these guys will have you do is install the X-Server of their choice : VcXsrv - because it's frequently maintained they say (others have successfully used X2Go and David Bombal has used another one). Their post is out of date - you don't get an option to uncheck access control, but per my experience, the default now has that unchecked.

Now, if, like me, you're a fan of letting Windows be your window manager, then, when you actually launch VcXsvr and see this, choose Multiple windows - and you get seamless windowing!

 

 Now, how do you launch a command from WSL2 and get a new window? First, go to the system tray icon for the VcXsrv and the Applications > xclock just to see that stuff does indeed work.

Then, in WSL2, ( I didn't need anything but this).. just do :

$ > export DISPLAY=:0

And stuff works!

Lemme guess - you set it up and now you want to change the username :)

There's really useless time-wasting stuff : https://www.howtogeek.com/261417/how-to-change-your-user-account-in-windows-10s-ubuntu-bash-shell/

And bit-rotten outdated stuff like : https://askubuntu.com/questions/816732/how-to-change-default-user-in-wsl-ubuntu-bash-on-windows-10/1111036

Fact is, with WSL2, ubuntu is not a command.. in cmd..

What works :

exit the Ubunuto (bash) process, else you'll get a complaint saying account <existing name> is being used by process PID#

In cmd prompt or powershell :

$ > sudo usermod -l <newName> -d /home/newName -m oldName

Hope that helps..

Other potentially helpful links - install a useful font : https://gist.github.com/sigoden/d01ad118da677f796bab01781b7eae23

And when that doesn't fly by itself : https://askubuntu.com/questions/1108354/fc-cache-command-not-found


No comments: