How To Monitor Changes in Linux Folders with Pynotify
If you're a Linux user, it's likely that you've come across the need to monitor changes in your Ubuntu directories. Luckily, the Pyinotify package is here to help. In fact, since version 2.6.13 of Linux, inotify has been incorporated as a security functionality, allowing system monitoring programs to open a single file descriptor and gain access to events occurring in a directory or file. This means that you can keep centralized control over your directories and files, accessing attributes such as open, create, close, move/rename, delete, change, and more.
What is Pyinotify?
Overall, Pyinotify is a powerful tool that allows for precise monitoring and management of your Ubuntu directories on Linux systems. With its comprehensive features and easy-to-use interface, it's an essential tool for system administrators and home users alike.
Pyinotify takes things one step further by providing tools like variables, signals, and conditions that make directory management even more specific. Variables contain Python objects, signals are lists of handles that are activated when a signal is issued, and conditions are Boolean variables linked to a signal that is emitted when its status changes.
To use Pyinotify on your Ubuntu 22.04 system, you'll need to meet a few requirements. You must have a Linux kernel version of 2.6.13 or higher and Python 2.4 or higher installed.
To know what version we have of each of these requirements we will execute the following commands:
uname -r (Kernel version) python -V (Python version)
Install Pyinotify on Linux
To install the application we will use pip, and for this, we will execute the following commands depending on the Linux distro used:
sudo yum install python-pip
Debian / Ubuntu
sudo apt install python-pip
sudo dnf install python-pip
Now we execute the following command for the installation of the application:
sudo pip install pyinotify
There we will install the most recent application in the repository. If you wish to have the latest version of Pyinotify, we will execute the following commands in their order:
git clone https://github.com/seb-m/pyinotify.git cd pyinotify / ls python setup.py install
How To Use Pyinotify in Ubuntu 22.04
To use pyinotify in the monitoring of a certain directory, we will execute the following command:
python -m pyinotify -v /home/augusto/TheLinuxCode
With this, we will analyze the changes in the /TheLinuxCode directory.
We have created a new folder in /TheLinuxCode called Test and we can see how in real time pyinotify detects the change and registers it with its respective event:
The structure of pyinotify is:
- Date and time of the event.
- Size of the event
- Event type.
- Route where the event occurred.
To exit pyinotify monitoring, we will use the following key combination Ctrl + C. If we do not specify a directory to analyze the tool, use the /tmp directory by default.
Pyinotify is a valuable tool as administrators that will allow us to take a specific control over the events that occurred in real time in a Linux directory and in this way know in detail what type of event happened and take the necessary measures.
It might be interesting
Apple will allow the iPhone to be used as a payment terminal
Apple is working on a new service that would allow small businesses to accept plastic card payments directly from the iPhone without the use of additional terminals. It was reported by Bloomberg, citing "people familiar with the issue.
LG BL40 New Chocolate Preview
The Black Label of this exclusively beautiful model is coming out in limited editions. This is a new way of aligning great stylistics and design with great technology with the sort of beauty with brains association.
The Chromium OS Open Source
The Chromium open source project is one of the greatest open sourcing projects that have been going really great. This is one of the greatest users that work with Google Chrome OS along with new systems being introduced web.
AMD introduced Ryzen 7000 5nm "Zen 4" processors for desktops
AMD today unveiled the new generation Ryzen 7000 processors for desktops, based on the Socket AM5 platform. The new Ryzen 7000 series processors introduce the new "Zen 4" microarchitecture, with the company claiming a 15 percent improvement in single-threaded performance over "Zen 3" (the 16-core/32-thread prototype Zen 4 processor over the Ryzen 9 5950X).