Write a bash script to monitoring directories and files

Update on:
May 17, 2021

inotify is a tool in Linux which is used to report when a file system event occurs. Using inotify, you can monitor individual files or directories.


Make sure you have the inotify tool installed on your system.

How to do it

Create a script called inotify_example.sh:


#! /bin/bash 
cdate=$(date +"%Y-%m-%d-%H:%M") 
inotifywait -m -q -e create -r --format '%:e %w%f' $folder | while read file 
	mv ~/Desktop/abc/output.txt ~/Desktop/Old_abc/${cdate}-output.txt 

How it works

The inotifywait command is mostly used in shell scripting. The main purpose of the inotify tool is to monitor the directories and new files. It also monitors the changes in the files.

Related Posts

Creating a config file and using it in tandem with your scripts

In this article, we are going to create a config file and use it in our shell script.PrerequisitesBesides having a terminal open, you need basic knowledge of creating scripts and config files.Write scriptNow, we are going to create a script and config file. The...

Calculating and reducing the runtime of a script

In this article, we are going to learn how to calculate and reduce the script’s runtime. A simple time command will help in calculating the execution time.PrerequisitesBesides having a terminal open, make sure you have the necessary scripts present in your...

Using Bash to monitor battery life and optimize it

In this article, we will learn about the TLP Linux tool. TLP is a command-line tool; it is used for power management and will optimize the battery life.PrerequisitesBesides having a Terminal open, you need to ensure that you have TLP installed on your system.How to do...

Creating a simple NAT and DMZ firewall using bash script

In this article, we will create a simple NAT firewall with DMZ using iptables.PrerequisitesBesides having a Terminal open, you need to ensure that iptables is installed in your machine.Write scriptWe will write a script to set up a DMZ using iptables. Create...

Follow Us

Our Communities

More on BASH

The Ultimate Managed Hosting Platform
Load WordPress Sites in as fast as 37ms!



Submit a Comment

Your email address will not be published.

three × two =