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:
- In Windows, create c:\temp (if it doesn't already exist)
- Open Notepad and type "Hello". Save this text file to c:\temp\hello.txt
- Open a bash shell and change to the temp folder above: cd /mnt/c/temp/
- In Bash, type
tail -f hello.txt
- Open a PowerShell shell and navigate to the temp folder above:
- In PowerShell, type
cat hello.txt -wait
- 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.
- You'll need to be running Windows 10 Insiders build #14942 to get inotify support
- You can safely ignore the following error reported in Bash: "tail: unrecognized file system type 0x53464846 for ‘hello.txt’. please report this to firstname.lastname@example.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.