{"id":2775,"date":"2024-10-24T04:51:09","date_gmt":"2024-10-24T04:51:09","guid":{"rendered":"https:\/\/codeinsightacademy.com\/blog\/?p=2775"},"modified":"2024-12-19T04:37:14","modified_gmt":"2024-12-19T04:37:14","slug":"inotify","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/linux\/inotify\/","title":{"rendered":"inotify"},"content":{"rendered":"\n<p>You can watch realtime operations happing in directory using inotifywatch and inotifywait command<\/p>\n\n\n\n<p>Install inotify tool<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install inotify-tools<\/code><\/pre>\n\n\n\n<p>Create directory<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p \/tmp\/test<\/code><\/pre>\n\n\n\n<p>Watch action<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>inotifywatch -v -e modify,create,delete \/tmp\/test\n\nCtrl + C\n\n#Then check statistics\n<\/code><\/pre>\n\n\n\n<p>Real time watch action<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>inotifywait -m -e modify,create,delete \/tmp\/test\/<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>inotifywait -m -r -e modify,create,delete \/tmp\/test\/<\/code><\/pre>\n\n\n\n<p>Now try to create modify and delete the file<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch \/tmp\/test\/file1.txt\necho \"Hello\" &gt; \/tmp\/test\/file1.txt\nrm \/tmp\/test\/file1.txt\n\nCtrl + C<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2024\/10\/image.png\"><img loading=\"lazy\" width=\"1451\" height=\"262\" src=\"https:\/\/codeinsightacademy.com\/blog\/http:\/\/codeinsightacademy.com\/blog\/wp-content\/uploads\/2024\/10\/image.png\" alt=\"\" class=\"wp-image-2777\"\/><\/a><figcaption>Left terminal to watch activities and right one to run commands <\/figcaption><\/figure>\n\n\n\n<p>To monitor multiple paths at a time run following commands<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>inotifywatch -e access,modify \/home\/user\/myfolder \/home\/user\/another_folder \/home\/user\/myfile.txt\nOR\ninotifywait -m -e access,modify \/home\/user\/myfolder \/home\/user\/another_folder \/home\/user\/myfile.txt<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You can watch realtime operations happing in directory using inotifywatch and inotifywait command Install inotify tool Create directory Watch action Real time watch action Now try to create modify and delete the file To monitor multiple paths at a time run following commands<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[31],"tags":[],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2775"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=2775"}],"version-history":[{"count":6,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2775\/revisions"}],"predecessor-version":[{"id":2797,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/2775\/revisions\/2797"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=2775"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=2775"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=2775"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}