{"id":12621,"date":"2019-03-28T04:05:28","date_gmt":"2019-03-28T04:05:28","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12621"},"modified":"2019-03-28T04:05:28","modified_gmt":"2019-03-28T04:05:28","slug":"fswatch-monitors-files-and-directory-changes-or-modifications-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/fswatch-monitors-files-and-directory-changes-or-modifications-in-linux\/","title":{"rendered":"fswatch \u2013 Monitors Files and Directory Changes or Modifications in Linux"},"content":{"rendered":"<p><strong>fswatch<\/strong>\u00a0is a cross-platform, file change monitor that gets notification alerts when the contents of the specified files or directories are altered or modified.<\/p>\n<p>It executes four types of monitors on different operating systems such as:<\/p>\n<ol>\n<li>A monitor build on the File System Events API of Apple OS X.<\/li>\n<li>A monitor based on\u00a0<strong>kqueue<\/strong>, a notification interface present in FreeBSD 4.1 also supported on many *BSD systems, OS X inclusive.<\/li>\n<li>A monitor based on File Events Notification API of the Solaris kernel plus its spin-offs.<\/li>\n<li>A monitor based on inotify, a kernel subsystem that shows file system modifications to apps.<\/li>\n<li>A monitor based on ReadDirectoryChangesW, a Windows API that records alters to a directory.<\/li>\n<li>A monitor that regularly check that status of file system, keeps file modification times in memory, and manually determine file system changes (which works anywhere, where stat can be used).<\/li>\n<\/ol>\n<h4>Features of fswatch<\/h4>\n<ol>\n<li>Supports several OS-specific APIs<\/li>\n<li>Allows recursive directory monitoring<\/li>\n<li>Performs path filtering using including and excluding regular expressions<\/li>\n<li>Supports customizable record format<\/li>\n<li>Additionally, it supports periodic idle events<\/li>\n<\/ol>\n<h3>How To Install fswatch in Linux Systems<\/h3>\n<p>Unfortunately,\u00a0<strong>fswatch<\/strong>\u00a0package is not available to install from the default system repositories in any Linux distributions. The only way to install the latest version of\u00a0<strong>fswatch<\/strong>\u00a0is to build from source tarball as show in the following installation instructions.<\/p>\n<p>First grab the latest\u00a0<strong>fswatch<\/strong>\u00a0tarball using following\u00a0<a href=\"https:\/\/www.tecmint.com\/10-wget-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">wget command<\/a>\u00a0and install it as shown:<\/p>\n<pre>$ wget https:\/\/github.com\/emcrisostomo\/fswatch\/releases\/download\/1.9.3\/fswatch-1.9.3.tar.gz\r\n$ tar -xvzf fswatch-1.9.3.tar.gz\r\n$ cd fswatch-1.9.3\r\n$ .\/configure\r\n$ make\r\n$ sudo make install<\/pre>\n<p><strong>Important<\/strong>: Make sure you\u2019ve GNU GCC (C and C++ Compiler) and Development Tools (<strong>build-essential<\/strong>\u00a0on\u00a0<strong>Debian\/Ubuntu<\/strong>) installed on the system, before you compile fswatch from source. If not, install it using following command on your respective Linux distributions..<\/p>\n<pre># yum group install 'Development Tools'\t\t[On <strong>CentOS\/RHEL<\/strong>]\r\n# dnf group install 'Development Tools'\t\t[On <strong>Fedora 22+<\/strong> Versions]\r\n$ sudo apt-get install build-essential          [On <strong>Debian\/Ubuntu<\/strong> Versions]\r\n<\/pre>\n<p>On\u00a0<strong>Debian\/Ubuntu<\/strong>\u00a0distributions, you might get following error while executing\u00a0<strong>fswatch<\/strong>\u00a0command..<\/p>\n<pre>fswatch: error while loading shared libraries: libfswatch.so.6: cannot open shared object file: No such file or directory\r\n<\/pre>\n<p>To fix it, you need to execute the command below, this will help refresh the links and cache to the dynamic libraries before you can start using fswatch.<\/p>\n<pre>$ sudo ldconfig\r\n<\/pre>\n<h3>How do I use fswatch on Linux?<\/h3>\n<p>The general syntax for running fswatch is:<\/p>\n<pre>$ fswatch [option] [path]\r\n<\/pre>\n<p>On\u00a0<strong>Linux<\/strong>, it is recommended that you use the default\u00a0<strong>inotify<\/strong>\u00a0monitor, you can list available monitors by employing the\u00a0<code>-M<\/code>\u00a0or\u00a0<code>- list-monitors<\/code>\u00a0option:<\/p>\n<pre>$ fswatch -M\r\n$ fswatch --list-monitors\r\n<\/pre>\n<div id=\"attachment_22954\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/fswatch-list-monitors.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-22954\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/fswatch-list-monitors.png\" alt=\"fswatch - List Monitors\" width=\"502\" height=\"130\" aria-describedby=\"caption-attachment-22954\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p id=\"caption-attachment-22954\" class=\"wp-caption-text\">fswatch \u2013 List Monitors<\/p>\n<\/div>\n<p>The command below enables you to watch the changes in the current directory (<code>\/home\/tecmint<\/code>), with events being delivered to standard output every\u00a0<strong>4<\/strong>\u00a0seconds.<\/p>\n<p>The\u00a0<code>-l<\/code>\u00a0or \u2013<code>-latency<\/code>\u00a0option allows you to set the latency in seconds, the default being\u00a0<strong>1<\/strong>\u00a0second.<\/p>\n<pre>$ fswatch -l 4 . \r\n<\/pre>\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/fswatch-Monitor-Home-Directory-Changes.gif\"><img decoding=\"async\" class=\"size-full wp-image-22956\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/fswatch-Monitor-Home-Directory-Changes.gif\" sizes=\"(max-width: 821px) 100vw, 821px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/fswatch-Monitor-Home-Directory-Changes.gif 821w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2016\/10\/fswatch-Monitor-Home-Directory-Changes-768x716.gif 768w\" alt=\"fswatch - Monitor Home Directory Changes\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p>The next command monitors changes to the\u00a0<strong>\/var\/log\/auth.log<\/strong>\u00a0file every\u00a0<strong>5<\/strong>\u00a0seconds:<\/p>\n<pre>$ fswatch -l 5 \/var\/log\/auth.log\r\n<\/pre>\n<p>Using\u00a0<code>-t<\/code>\u00a0or\u00a0<code>--timestamp<\/code>\u00a0option prints the time stamp for every event, to print the time in\u00a0<strong>UTC<\/strong>\u00a0format, employ\u00a0<code>-u<\/code>\u00a0or\u00a0<code>--utf-time<\/code>\u00a0option. You can as well format time using\u00a0<code>-f<\/code>\u00a0or\u00a0<code>--format-time<\/code>\u00a0format option:<\/p>\n<pre>$ fswatch --timestamp \/var\/log\/auth.log\r\n<\/pre>\n<p>Next,\u00a0<code>-x<\/code>\u00a0or\u00a0<code>--event-flags<\/code>\u00a0tells\u00a0<strong>fswatch<\/strong>\u00a0to print the event flags along side the event path. You can use\u00a0<strong>\u2013event-field-seperator<\/strong>\u00a0option to print events using the particular separator.<\/p>\n<pre>$ fswatch --events-flags ~ \/var\/log\/auth.log\r\n<\/pre>\n<p>To print the numeric value of an event indicating changes in your\u00a0<strong>home<\/strong>\u00a0directory and\u00a0<strong>\/var\/log\/auth.log<\/strong>\u00a0file, use\u00a0<code>-n<\/code>\u00a0or\u00a0<code>--numeric<\/code>\u00a0option as below:<\/p>\n<pre>$ fswatch --numeric ~ \/var\/log\/auth.log \r\n<\/pre>\n<p>Perhaps you can look through the\u00a0<strong>fswatch<\/strong>\u00a0man page for detailed usage options and information:<\/p>\n<pre>$ man fswatch\r\n<\/pre>\n<p>For more information and usage, visit\u00a0<strong>fswatch<\/strong>\u00a0Github repository:\u00a0<a href=\"https:\/\/github.com\/emcrisostomo\/fswatch\" target=\"_blank\" rel=\"nofollow noopener\">https:\/\/github.com\/emcrisostomo\/fswatch<\/a><\/p>\n<p>In this post, we covered a simple command line utility to help Linux users get notified when the contents of specified files or directory hierarchies are modified.<\/p>\n<p>I hope all went well with the installation, if that is not the case for you, make an effort to reach us via the feedback form below. In addition, in case you have used it before, you may want to offer us some thoughts about your experience with\u00a0<strong>fswatch<\/strong>.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/fswatch-monitors-files-and-directory-changes-modifications-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>fswatch\u00a0is a cross-platform, file change monitor that gets notification alerts when the contents of the specified files or directories are altered or modified. It executes four types of monitors on different operating systems such as: A monitor build on the File System Events API of Apple OS X. A monitor based on\u00a0kqueue, a notification interface &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/28\/fswatch-monitors-files-and-directory-changes-or-modifications-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;fswatch \u2013 Monitors Files and Directory Changes or Modifications in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12621","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12621"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12621\/revisions"}],"predecessor-version":[{"id":12622,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12621\/revisions\/12622"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}