Watcherd is a tool for Linux that helps to monitor directory changes and print whatever changes are done like adding and deleting for a particular directory and execute commands and shell scripts according to a particular event.
Installing Watcherd on Linux
Step 1: Downloading watcherd.
Since watcherd is a Github repository you can use wget command to download its zip and extract it. To do so execute the command:
Step 2: Unzipping and extracting.
After downloading unzip the file using the command:
In case you do not have to unzip installed then you can install it by using:
sudo apt-get install unzip
Step 3: Copy to the bin location.
Once unzipping is finished now you need to copy the files to the bin directory, to do so use the command:
sudo cp watcherd-master/watcherd /usr/bin/
Step 4: Check the tool is installed properly or not.
You can check the user manual by using the help command:
Or you can check with –version
Step 1: Create a directory.
Make a directory named test in your current working directory
Step 2: Now start watcherd.
Now deploy watcherd using the following parameters:
watcherd -v -p ~/sample -a "echo added %n" -d "echo deleted %n" -t "ls -l ~/sample" &
- -v stands for verbose which will verbosify the output of the command
- -p stands for the path to directory, and we have used test for the subject
- -a stands for executing the command if any directory path is created , we have used echo for printing but you can also add any other way of scripting and make the best use out of it.
- -d stands for executing the command if any directory path is deleted and vice versa.
- %n will be substituted with directory name or you can use %p to get a full path to the created or deleted directory
- -t “ls -l ~/test” execute command after triggering
- & run in background
Step 3: After executing the command check if it’s running by using the command:
ps ax | grep watcherd
Now let’s do some adding and deleting directory in our test folder and see what happens, directory can be named anything, for instance we are using anon.
After executing the command you will be able to see an output generated by watcherd.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.