Linux Fu: WSL Tricks Blur The Windows/Linux Line

We have to admit, we have an odd fascination with WSL — the Windows subsystem for Linux. On the one hand, it gives us more options on Windows 10 for running the software we love. On the other hand, we wonder why we aren’t just running Linux. Sometimes it is because our cool laptop doesn’t work well on Linux. Other times we are using someone else’s computer that we aren’t allowed to reload or dual boot. Still, as long as we have to use Windows, we are glad to have WSL. A recent blog post by [Hanselman] shows some very cool tricks for using WSL that make it even better.

Exploring WSL

Did you know you can use WSL to run Linux commands in a Windows command shell? For example, you have a long directory and you want to run grep:

dir c:\archive\* | wsl grep -i hackaday

Of course, from bash you could access the same directory:

ls /mnt/c/archive | grep -i hackaday

Extensions

Many of the tricks rely on the fact that bash doesn’t assume any executable file extension. If you try to run explorer, for example, from a bash shell, nothing happens. But if you append the .exe extensions, Windows programs will run and, by default, the usual Windows directories are in the path.

You do need to watch out for path name conversion. For example, if you provide “.” as an argument to explorer, you will open up a network share //wsl$/Ubuntu/home/user_name, for example. Of course, that’s another trick. You can access your WSL directories from windows using that notation (obviously, Ubuntu and user_name may be different for your installation). However, ordinary paths do not work.

Path Conversion

You can, however, use the wslpath utility to convert paths in both directions:

$ 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 '\'

For example:

$ explorer.exe `wslpath -w /bin`

X11 and More

[Hanselman] discusses a number of tips, including some about using development tools and git. You can also install multiple WSL flavors and export them to other Windows machines. He also mentions running X11 using paid tools Pengwin and X410. We say just use Swan.

Speaking of Swan, it is a great alternative to WSL on any Windows version, not just Windows 10. In truth, it is just Cygwin with X11 preconfigured, but it is much easier than trying to get X11 running on a bare Cygwin install. On the one hand, this is a much more desktop Linux solution than WSL. On the other hand, WSL loads real distributions and integrates nicely with Windows 10. But if you load both, you can get the advantages of both, too.

Sell Out?

Given the choice, we’ll just use Linux. Honestly, if your workflow is mostly Web-based, it hardly matters anymore. You load Chrome or your choice of browser and everything works. Of course, our Linux boxes tend to be way more efficient and also stay running better than Windows.

However, if you find yourself using Windows, Cygwin has long been a big help. Now WSL is another tool to get your Linux tools on a Microsoft-controlled box.

51 thoughts on “Linux Fu: WSL Tricks Blur The Windows/Linux Line

    1. My windows 10 gaming desktop only crashes due to crappy games and has stayed powered on for months. My debian server will similarly crash due badly configured software but will otherwise stay online for months. You’re right in the lines being blurry between the two

        1. or really any Console>PC port.

          things like unity have made game publishers lazy, and more often than not

          “thats a unity bug , deal with it”

          is the only bugfix roadmap we’ll ever see.

      1. Since Vista, Windows has got a lot better at not crashing (because they forced drivers to stop stomping all over memory). Since then, the only full OS level crashes I’ve had have been from faulty hardware.

      1. systemd’s problem is that it’s a very different approach, and people are still getting used to it. It is a much more opinionated init system than most people are used to, which doesn’t help its case IMO. Probably closer to Apple’s launchd than Windows.

        I have several machines that run it, and so far, if I’ve had problems it hasn’t been with systemd. I have to refer to the documentation more with systemd, that is an issue of familiarity… not systemd’s fault.

    1. You say that like it’s unusual that you can’t reload the os on your corporate laptop but you wrangle admin or limited admin access. I have the latter and manged wsl+vcxsrv working nicely.

    1. I’d just like to interject for a moment. What you’re referring to as WSL,
      is in fact, GNU/Windows, or as I’ve recently taken to calling it, GNU plus Windows.
      WSLis not an operating system unto itself, but rather another free component
      of a fully functioning GNU system made useful by the GNU corelibs, shell
      utilities and vital system components comprising a full OS as defined by POSIX.

      Many computer users run a modified version of the GNU system every day,
      without realizing it. Through a peculiar turn of events, the version of GNU
      which is widely used today is often called “WSL”, and many of its users are
      not aware that it is basically the GNU system, developed by the GNU Project.

      There really is a Windows, and these people are using it, but it is just a
      part of the system they use. Windows is the kernel: the program in the system
      that allocates the machine’s resources to the other programs that you run.
      The kernel is an essential part of an operating system, but useless by itself;
      it can only function in the context of a complete operating system. Windows is
      normally used in combination with the GNU operating system: the whole system
      is basically GNU with Windows added, or GNU/Windows. All the so-called “Windows”
      versions are really a distribution of GNU/Windows.

  1. I think we will see the Windows code-base replaced with some sort of Linux distribution.

    Don’t get me wrong, Windows will still exist, but as an open-source project. The “closed” part of Windows will be the Window manager, and of course, office, telemetry, etc.

    Telemetry will not go away, it will increase.

    Consumers will get to experience the benefits of telemetry, in the form of a system that can be left on continuously.

    The power button will also go away. Systems instead will enter standby, so that the telemetry, microphones, webcams, and other essential updates and telemetry services can still run.

    There will be no need to reboot, since Linux can be patched on the fly. There will be no need to turn off a system.

    1. I found the WSL I downloaded about 6 months ago to be pretty useless, I couldn’t “apt get” much to run on it, and it’s got itself into an upgrade jail which I suspect I’ll have to delete the whole thing and reinstall to get out of. The noobs* on the support forums weren’t much help either…

      So is this “wsl2” a significant improvement? Maybe time to give it another go.

      [* my UNIX credentials: system III, BSD4.2, 4.3, system V, Ultrix, Minix, Linux, Android….]

    1. Depending on the use case wsl1 was pretty dang fast for me. It ended up being way faster than the same simulation, optimization and analysis tools recompiled for cygwin, but my tools have very little disk interaction. I know that was a huge issue for most people. What has been your use case comparison with respect to speed for wsl1 and wsl2? I’ve not yet used wsl2.

  2. I just want to be able to install software on Windows that’s only available for Linux and have it work seamlessly with Windows like any other Windows program. Like how OS/2 Warp had seamless support for 16 bit Windows software.

    1. I’ve rather enjoyed VirtualBox’s seamless mode. I run Windows XP and Lubuntu VMs on my Windows 10 PC and can pop their applications out onto discrete windows as if they were running directly on Win10.

  3. Wonderful… so you can now use X11 applications with one of the shittiest window managers still in active development: Microsoft Windows.

    No thank-you… I’ll stick to FVWM thanks.

    1. Happy to hear FVWM does it for you, honest. Me and the other 93% of the world’s desktop computer users will stick to the most popular shittiest window manager.

      Your comment is a perfect example of why *nix will never win over the desktop. You probably won’t believe this, but your shit stinks just as badly as ours does.

      1. The difference is that the Linux can be “unstunk”, and you have the choice to do so. Windows 10 sucks, and there’s no way around that. You have no choice. Nothing you do to it makes Windows 10 anything other than what it is: hot garbage wrapped in a privacy nightmare. Use it if you want, that’s your prerogative. But don’t pretend *nix and Windows are one and the same.

        1. oh there are several options do drastically modify how the windows desktop works with 3rd party programs (changing how windowssss order themselves, get stuck at borders, use the win10 or any of the previus start menus, and so on).

          IMHO the one-desktop-manager policy of windows is an advantage.
          I cant stand GNU/Linux because all good software is written by hyper-nerds stuck on an ancient system of interactions with the system barely better then punch-cards (not to mention everything is text so it can be piped). And all GUI options look like they were made for brain-dead dummies (an ubuntu vm of mine didn’t want to update and do you think the stupid gui shop/sysupdate software could properly tell me that there was a problem, not to mention what the problem was? no of course not).

          1. Go back to one classic X-Windows design scheme that all GUI programs follow and that works good over ssh (all programs need to transmit is the text and positions where sth. is displayed NOT a differrnt f*ckn whole colorscheme with images for every program).
          2. make proper GUI tools for all important shell tolls that show/teach the user how to shell version works. Nmap-GUI is an example. I’m missing that for htop, iftop, and many more I don’t remember or even know. On that not ALL console base partition programs are retarded – It’s like doing your presentation with pie-charts only with ASCII characters.
          3. get rid off all those ridiculous key-combination restrictions with your CUI programs, convert them to GUI and stick to one scheme. Had to use tmux recently and wanted to use a function I couldn’t invoke with ctrl+b+ because it required “M+”. That’s even worse when using some GUI terminals programs that steal keys from the shell like F10 for there own menu.
          4. got some more points (file extensions, config-files, case sensitive filesystem,

          1. Changing a UX (or how the UX is used) isn’t exactly the kinds of customization I was referring to…

            Can you change any fundamental way your system behaves to suit your use cases or preference? No, you can’t.

            Let’s go down your list, though:

            > IMHO the one-desktop-manager policy of windows is an advantage.

            I don’t see how an absolute lack of choice is an advantage, but OK.

            > I cant stand GNU/Linux because all good software is written by hyper-nerds stuck on an ancient system of interactions with the system barely better then punch-cards (not to mention everything is text so it can be piped).

            This reads like opinion based on little more than conjecture and preference. None of that is objectively true.

            > And all GUI options look like they were made for brain-dead dummies (an ubuntu vm of mine didn’t want to update and do you think the stupid gui shop/sysupdate software could properly tell me that there was a problem, not to mention what the problem was? no of course not).

            Yes, because Ubuntu and its update mechanism = everything Linux, ever.

            > 1. Go back to one classic X-Windows design scheme that all GUI programs follow and that works good over ssh (all programs need to transmit is the text and positions where sth. is displayed NOT a differrnt f*ckn whole colorscheme with images for every program).

            Again, you’re complaining about one DE as though it is representative of everything available. GNOME != KDE != i3/Sway != Fluxbox.

            > 2. make proper GUI tools for all important shell tolls that show/teach the user how to shell version works. Nmap-GUI is an example. I’m missing that for htop, iftop, and many more I don’t remember or even know. On that not ALL console base partition programs are retarded – It’s like doing your presentation with pie-charts only with ASCII characters.

            Read the manpages. GNOME and KDE both include system monitoring suites by default. You’re blaming the ecosystem for your lack of knowledge and inexperience.

            > 3. get rid off all those ridiculous key-combination restrictions with your CUI programs, convert them to GUI and stick to one scheme. Had to use tmux recently and wanted to use a function I couldn’t invoke with ctrl+b+ because it required “M+”. That’s even worse when using some GUI terminals programs that steal keys from the shell like F10 for there own menu.

            How about – you know – changing your keybinds, or binding your meta-key to something else?

            > 4. got some more points (file extensions, config-files, case sensitive filesystem,

            RTFM.

            Seriously, your contentions are nothing more than preferences.

            Have fun, though!

          2. Every single one of your points are matters of preference. You’re blaming your difficulties on inexperience and lack of knowledge.

            For the record, Ubuntu’s shell/DE is not representative of the Linux ecosystem at large. That’s what I meant by choice… You don’t like the way a distribution behaves? Change it. You don’t like how a DE looks? Change it. You don’t like the default key binds? Change them. You don’t like how a particular filesystem imposes restrictions or limits? Use a different one. Don’t like telemetry or data farming? Turn it off. Unhappy with a software license that you feel is morally reprehensible? Don’t accept it.

            You can’t do any of those things (with the exception of key binds, sort of… and making superficial changes to your UI… within Microsoft’s parameters) with Windows. You’re stuck with what Microsoft tells you is good enough, and you just have to deal with it and convince yourself that it’s not a problem.

            Preference is great… use what you want. Just don’t equate the two, as they’re fundamentally different principles.

      2. > but your shit stinks just as badly as ours does

        At least I can change my “shit” to make it more pleasant for me to live with (don’t care if it still stinks for you).

        My “shit” didn’t cost me anything to acquire. Time spent getting it working is minimal too.

        My “shit” doesn’t call me a pirate or stop working when I change my hardware.

        My “shit” doesn’t force updates on me. I call the shots on when and what gets updated.

        My “shit” doesn’t tell me to ‘not unplug or turn off your computer’ because it is ‘installing updates’.

        My “shit” doesn’t spy on me. No telemetry of any kind.

        My “shit” works just fine (and fast) on desktops from the late 90s as well as on the latest desktops. (Using it right now on a Samsung N150 Plus which used to run slow as molasses on Windows 7 “starter”. The desktop I have now was originally configured on a Pentium II laptop, and still works there just fine.)

        My “shit” doesn’t reserve 7GB of disk space all for itself.

        My “shit” also doesn’t care about kernels, it works just fine on OpenBSD as well as Linux. Much of the software I use will work on MacOS X, other variants of BSD, etc. Critical portions of it don’t work on Windows, not even under WSL/Cygwin/mingw/SFU.

        My “shit” doesn’t have to worry about whether it is pretending to emulate VMS, CP/M or Linux, as it just gets on with the job at hand.

        Microsoft Windows is a legacy OS. Its use case is running that piece of software that won’t run on anything else because the maker no longer supports it, or lives in the echo chamber where only Windows-based computers exist. In terms of cross-platform compatibility, it’s the pariah.

        Write something for Linux, there’s a good chance it’ll work on MacOS X and BSD with minimal changes, but you can expect to be peppering your code with #ifdefs and special case code to support Windows.

        Many of us write software for a living. In my case, supporting open-source systems has netted me hundreds times more paid working hours than anything involving a proprietary OS. Projects get started, finished in a timely manner, and the support burden has been minimal… they’ve kept trucking along for literally years. Sometimes decades.

        People come back to my workplace because we “get shit done”, and we “get shit done” because we don’t have to jump through Microsoft’s hoops.

        Market share is a non-issue for me. I use what works for my use case. You could compare a given platform to the durian… some love them, others can’t get away from them fast enough.

        Microsoft wouldn’t bother with WSL if they didn’t think it was a good idea. They’re going that way because in “the cloud”, they are getting their arses kicked big time. In mobile they are getting their arses kicked big time. They’re also getting their arses kicked in embedded.

        And on desktop… that 93% used to be a _lot_ bigger. Internet Explorer used to have 95% market share back in 2003 — almost all of those being by extension a Windows user (Solaris/HP-UX version of IE was dropped in 2001, IE for Mac dropped that same year, users there going to Safari). Again, they are getting their arses kicked.

        They’re losing to mobile, they’re losing to Linux too. Users that haven’t switched to MacOS X or iOS, have generally gone to Linux, either GNU/Linux or more commonly, Android.

        My point being: Microsoft are doing this to try and “win” Linux users back. Most of us are jaded from literally decades of crap from this company. We see through their token gestures, having seen the “embrace, extend, break” philosophy played out many times before.

        They’re also trying to win us over, using the worst imaginable carrot one could think of. “Come bring your toys and play in our walled garden. No you can’t re-arrange the furniture for your comfort, and we reserve to re-arrange that furniture at any time.”

        Based on this, why would anyone waste their time with this expensive Jeckyll-and-Hyde OS when good quality free alternatives exist?

        1. ^ This, tbh. Argumentum ad populum isn’t a very convincing sales pitch. Just because 93% of desktop users use Windows (mostly because they don’t know any better) doesn’t mean it is better than other offerings.

        2. Rude and arrogant is a poor way to make your case …. And the main reason Linux has never been able to capture a wider audience …..

          People like you turn them off and they decide it’s just not worth it

          1. Hey, I don’t live on “One Microsoft Way”… few companies are arrogant enough to make their physical address “One ${COMPANYNAME} Way”. Only one on Earth I know of, and they’re headquartered in Redmond, USA.

            We’re talking about the company that made their flag-ship product incompatible with other company’s implementations of DOS. (Ever tried Microsoft Windows on DR-DOS?)

            We’re talking about the company that said they weren’t interested in the Internet and instead wanted to pursue “The Microsoft Network”. (Remember that? It was their “Compuserve” wannabe.)

            We’re talking about the company that introduced ActiveX Controls for web development. (Remember those?)

            We’re talking about the company that thought it was job done on Internet Explorer at version 6 and only reversed that decision when Google started kicking their arse with Chrome.

            We’re talking the company that called Linux a “cancer”. (Remember that quote?)

            We’re talking the company that replaced the “start menu” with a “start screen”. (Then had to backflip on that the very next release.)

            We’re talking the company that makes an OS that actively decides to uninstall software *it* thinks is incompatible. (Colleagues fight this one with Cisco VPN software on a regular basis.)

            Fact is, you’ve never actually met me… so I find it interesting you can judge my personality. If I “turn people off” … geez. What would they think of Steve “I’ll f***ing kill Google” Ballmer? No wonder he got the sack!

            If I come across as arrogant, it’s only a reflection of the complete arrogance that Microsoft has shown me in the past 31 years of computer use as a customer, as a software developer and a network administrator. Years of having to make “special case allowances” for the OS that can’t get along with anybody else.

            My argument was that Microsoft, in their own arrogance, completely overlook why many of us are drawn to Linux. I couldn’t give a rats if I was the only person on Earth using Linux. Wouldn’t be the first time I’ve been the only person on earth running a particular hardware/kernel/userland combo. It’s one of the perks of using a source-based Linux distribution: you can make your own choices. You control your destiny.

            The fact is, Microsoft are trying to market Windows to us as “Hey, we do Linux stuff too, come do it OUR way”. Not, “sure, bring your applications and desktop over here and let us share our applications with you”.

            If you could use a Linux-based window manager and desktop environment to manage Windows applications, maybe they’d have something half-compelling.

            i.e. you log into Windows 10, it starts your .xsession file, you’re brought into whatever desktop environment you choose (XFCE, KDE, Gnome, FVWM, AfterStep, whatever)… then from that window manager, launch native Windows applications and have them managed like the Linux ones, that could be half-tempting.

            There’s still the forced updates and telemetry to contend with, and the fact that its a proprietary soup of conflicting software packages… but it might *start* to move in the right direction.

            Rude and arrogant might be a bad way to make your case, but it’s been Microsoft modus operandi ever since IBM knocked on their door back in 1980, and was also how IBM worked back then. (The IBM PC was deliberately hobbled because they didn’t want to cannibalise their existing computer business.)

            Had Microsoft been better sales people, they’d have sold IBM a license for the Xenix operating system, and wouldn’t be trying to beat a path back from the wilderness they have found themselves in today.

          2. The reasons why it would be considered good are the same if you use it or not.

            Perhaps there is no reason to presume just because people explain it, that their goal must be to get you to adopt it.

            Linux isn’t a company, it doesn’t need new sales to survive and continue getting updates, there is absolutely no benefit to existing users if more new users fill the forums with questions.

            Please don’t use Linux. It is better in every way, but it is mostly only popular with nerds. So don’t bother. New users are toxic to the culture. Everybody involved is worse off if you use it. Even though it is better.

  4. We have to use Windows at work ( unless you can convince your manager to buy you Mac) Wsl is one of the few things that make it usable I have the Cygwin that comes with git installed too and it’s almost too slow to use for me but it does add a few things like Ls to cmd that I miss if they aren’t there. I am interested in trying powershell now they open sourced it though. I had to write a script to to set up npm for my team and I used powershell instead of a .bat script and it was pretty nice .
    I am cautiously optimistic that Microsoft is at least trying to make the appearance of changing.

  5. For over 25 years I’ve been hearing how Linux was going to kill Windows forever ……

    Still isn’t even REMOTELY close to making that happen and it can’t even grab a double digit share of the Desktop Market after over 25 years of trying …..

    Why? Well basically because support sucks and a lot of people on help forum are rude because some of us don’
    t have the time to go through a 300 page thread with answers from people whose skill levels are suspect at best. Ask a simple question and you’ll either get 20 different answers or someone will tell you to RTFM

    1. GNU/Linux pretty much killed Windows on the server market already. On smartphones, Windows could barely get a foothold. Everything iOS or Android there, with Android being a Linux distro. GNU/Linux has also a 100% stronghold on high performance computing (TOP500).

      Much closer to the truth is: desktops are the last stronghold for Windows, and even this one got brittle.

  6. REALITY CHECK

    Windows 10 is LOADED with “telimentary” A.K.A. exfiltration A.K.A. spying services.. Use their Linux sandbox knowing they are likely spying on you. Same reason you only do air gapped Windows dev

    1. Really, you like getting error messages because you didn’t type a filename exactly the way you did the first time? Do you really want to have both foo.txt and Foo.txt on your disk?

      Don’t get me wrong, I use Linux and macos every day and like them a lot. But case sensitivity has always struck me as a convenience for the OS author, not the human user.

      I heard Ken Thompson speak last year, but forgot to ask him why it’s this way.

Leave a Reply to Jim ShortzCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.