WSL adds inotify & filesystem change notification support


inotify example

Over the last few weeks, the Windows Subsystem for Linux team have been cranking away, fixing lots of issues, completing several scenarios that we were unable to complete before shipping Windows 10 Anniversary Update, and adding support for new capabilities that light-up additional tools and scenarios.

A key capability that many developer have been waiting for is “inotify support”.

Inotify is a feature built-in to the Linux kernel, which also has analogues in most other operating systems: In Windows, filesystem changes are exposed via the Win32 Directory Change Notifications API or the .NET FileSystemWatcher() API. Such mechanisms allow tools to be aware of changes made to directories and/or files they’re interested in.

For example, the Linux tail -f ... or PowerShell cat ... -wait commands will display the contents of a specified file if it is updated, which is useful when watching logs and traces for activity.

Similarly, tools like nodemon will automatically restart a node.js service application whenever a source file’s content is changed, dramatically increasing developer productivity (think of it as edit & continue for node.js).

So, if both Linux and Windows support filesystem change notifications, wouldn’t it be awesome if they could be plugged together so that, for example, if a file is changed in Windows, then Bash, and any other file-change-aware Windows applications could receive the update notifications and display the updated content?

Well, that’s exactly what’s just arrived in Windows 10 Insiders build #14942.

To demo this capability, follow these steps – you should see results similar to the image above:

  1. In Windows, create c:\temp (if it doesn’t already exist)
  2. Open Notepad and type “Hello”. Save this text file to c:\temp\hello.txt
  3. Open a bash shell and change to the temp folder above: cd /mnt/c/temp/
  4. In Bash, type tail -f hello.txt
  5. Open a PowerShell shell and navigate to the temp folder above: cd c:\temp\
  6. In PowerShell, type cat hello.txt -wait
  7. Back in Notepad type in some text. Every time you hit save, you should see both the Bash and PowerShell consoles display the newly saved text.

Notes:

  1. You’ll need to be running Windows 10 Insiders build #14942 to get inotify support
  2. You can safely ignore the following error reported in Bash: “tail: unrecognized file system type 0x53464846 for ‘hello.txt’. please report this to bug-coreutils@gnu.org. reverting to polling”

We look forward to seeing what you can do with inotify support in Bash on Windows, and encourage you to share your experiences in blogs, on Twitter (be sure to ping me @richturn_ms), etc.

Comments (12)

  1. Adriano says:

    Hi, I am o fast ring and still am not getting this build as it updated recently to an older build still instead of #14942. How can I install it manually?
    It is frustrating as I have work to be done waiting for this build fixes.

    Thank you.

    1. The Build 14951 only released yesterday. It can take a day or two to achieve broad deployment.

  2. YES, YES, YES!!!
    Thank you so much guys!

    Unfortunately I am not using the Insider version at work and not at home, because I am in the middle of some projects, but I’m looking forward to the release of the stable version.

    Again, thank you.
    This will help a lot.

  3. Fredrik says:

    When will Insider Build 14951 be released for normal windows?

    1. Never – 14951 is an Insider build: Insider builds are essentially weekly (ish) builds containing what we intend to ship in the next big release. In this case, it’s Windows 10 Creator Update (CU) which is due Spring 2017.

  4. Udesh Kumar says:

    I am still not able to use gulp.. is it released for normal users?

    1. Gulp had issues running on WSL in the Anniversary Update since it needed to enumerate the available network connections’ IP addresses. This issue was fixed several months ago & released in Insider builds, and will be released publicly when Creators Update ships in the spring.

  5. tdifilippo says:

    Hi,
    I am new to Windows 10 Insiders, just turned it on today and love WSL/bash. When I installed this today, it installed 14.04 of Ubuntu. I need to get up and running on Ubuntu 16.04, for among other things the correct version of Python (some python packages), network support and all of the bug fixes. I tried to uninstall / install with lxrun, and also tried do-release-upgrade, and it get 2 upgrade tools then just gets a screen terminating error. Can anyone help me?

    1. You need to be on Insider builds to run 16.04.

      Build 14393 is the Anniversary Update from July 2016 which lacked many of the features required to support 16.04 and lacked many of the features required to run tools like node, npm, Java, etc.

      My recommendation would be to get your machine onto the latest Insider Fast Ring build, destroy your existing WSL instance (using `lxrun /uninstall /full`) and then re-create a new WSL instance (using `lxrun /install`). This process will create you a fresh 16.04 instance, and will prompt you to create a standard UNIX user & password on first-run, so that you can run protected most of the time, and `sudo` to elevate when necessary.

      1. NoSubstitute says:

        Hi, Rich!
        Do you really feel it’s necessary to completely re-install Xenial after upgrading to an Insider build?
        I have, after following a guide on WSL github, managed to upgrade my 14393 AU to Xenial, and am quite happy with it.
        Now, of course, it’s lacking inotify support, as well as network devices and other new things, but I’d like to not have to re-install all tools I have.

        1. You should not need to reinstall Xenial if you’re able to upgrade in-place.

          HOWEVER, note that we don’t support 16.04 on 14393 (AU) since 14393 lacked several important SYSCALL’s that 16.04 requires.

          If you do upgrade to an Insider build or Creators Update (when it ships this spring), you *may* need to nuke your /etc/hosts file if you see network connectivity issues.

          1. NoSubstitute says:

            Ok, good.

            Yeah, I noticed. 🙂

            Oh yeah? My hosts file is fairly empty, so I don’t see what could mess things up in there.

Skip to main content