WSL adds inotify & filesystem change notification support

Rich Turner

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.

4 comments

Discussion is closed. Login to edit/delete existing comments.

  • Sarah Haugen 0

    Hello – can inotify be used to subscribe to notifications for when a process starts and stops?  

    • Rich TurnerMicrosoft employee 0

      Hey Sarah – inotify provides a mechanism for monitoring filesystem events, not process events.

      • Sarah Haugen 0

        Thanks Rich.  So is an execute access event on a file (e.g. *.exe) not considered a file system event?  

  • Gaurav Kamath 0

    I’ve tried the demo. And it doesn’t work. Tail -f from WSL does not follow the file (located on the Windows FS).

    I’m on WSL2. On the WSL FS it works fine from both WSL and Windows.

Feedback usabilla icon