Write a bash script to monitoring directories and files

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.

Prerequisites

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

How to do it

Create a script called inotify_example.sh:

inotify_example.sh

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

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.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

5 × four =

Related Articles