Inotify-tools usage

Source: Internet
Author: User

Inotify-tools is a set of C development interface library functions provided for inotify file monitoring tools in Linux. It also provides a series of command line tools, these tools can be used to monitor file system events.
Inotify-tools are written in C. In addition to requiring Kernel support for inotify, they do not depend on others.
Inotify-tools provides two tools: inotifywait, which is used to monitor file or directory changes, and inotifywatch, which is used to count the number of accesses to the file system. Now we will introduce how to use it.

Installation Method

Download link: http://pan.baidu.com/s/1ntr407R


Wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
Tar xzf inotify-tools-3.14.tar.gz
CD inotify-tools-3.14
./Configure -- prefix =/usr
Make
Make install

Example
Inotifywait
1. Real-time Monitoring of all/home events (including file access, writing, modification, and deletion)
Inotifywait-RM/home

Inotifywatch
1. Collect/home File System Events
Inotifywatch-v-e access-e modify-T 10-r/home

Parameter description
Inotifywait
Syntax:
Inotifywait [-hcmrq] [-E] [-T] [-- format] [-- timefmt] [...]
Parameters:
-H, -- Help
Output help information
@
Exclude files that do not need to be monitored. They can be relative paths or absolute paths.
-- Fromfile
Read the files to be monitored or excluded from the file. A row of files starts.
-M, -- Monitor
If a task is received without exiting, it is executed indefinitely. The default action is to exit immediately after receiving a message.
-D, -- daemon
Like -- monitor, except running in the background, you must specify -- OUTFILE to output the event to a file. It also means that syslog is used.
-O, -- OUTFILE
Output a task to a file instead of a standard output.
-S, -- Syslog
Output Error information to system logs
-R, -- Recursive
Monitors all subdirectories in a directory.
-Q, -- quiet
If this parameter is specified once, no detailed information is output. If the parameter is specified twice, no information is output except fatal errors.
-- Exclude
Files to be excluded from regular expression matching are case sensitive.
-- Excludei
The file to be excluded by regular expression matching. case insensitive.
-T, -- timeout
Set the timeout value. If the value is 0, it is executed indefinitely.
-E, -- event
Specifies the event to be monitored.
-C, -- CSV
Output CSV format.
-- Timefmt
Specifies the time format. It is used in % t format in the -- format option.
-- Format
Specify the output format.
% W indicates the directory where the event occurred
% F indicates the file in which the event occurred
% E indicates the event
% Xe events are separated by "X"
% T use the time format defined by -- timefmt

As follows:
Inotifywait-r -- daemon-O/root/inotifywait. log-e create, modify, moved_to, delete -- timefmt '% d/% m/% Y % H: % m' -- format' % T % W-% F-% E '/data/Baidu
In the future daemon mode, the four events "create, modify, moved_to, delete" in the "/data/Baidu" directory are monitored in the loop mode"
Timefmt specifies the time format and format specifies the information output format.

Inotifywatch
Syntax:
Inotifywatch [-hvzrqf] [-E] [-T] [-A] [-D] [...]
Parameters:
-H, -- Help
Output help information
-V, -- verbose
Output details
@
Exclude files that do not need to be monitored. They can be relative paths or absolute paths.
-- Fromfile
Read the files to be monitored or excluded from the file. A row of files starts.
-Z, -- zero
Output table rows and columns, even if the element is empty
-- Exclude
Files to be excluded from regular expression matching are case sensitive.
-- Excludei
The file to be excluded by regular expression matching. case insensitive.
-R, -- Recursive
Monitors all subdirectories in a directory.
-T, -- timeout
Set timeout
-E, -- event
Only listens to specified events.
-A, -- Ascending
Sort events in ascending order.
-D, -- descending
Sort events in descending order.

Event listening
Access File Reading
Modify the modify file.
Attribute changes in the attrib file, such as permissions and timestamps.
Close_write is disabled for a file opened in writable mode, which does not necessarily mean that the file has already written data.
Close_nowrite is disabled for files opened in read-only mode.
Close the file, no matter how it is opened.
Open the file.
Moved_to move a file or directory to the monitored directory. This event is triggered even if it is moved in the same directory.
Moved_from: this event is triggered when a file or directory is removed from the monitored directory, even if it is moved in the same directory.
Move includes moved_to and moved_from.
The move_self file or directory is removed and will not be monitored.
Create file or directory Creation
Delete a file or directory
Delete the delete_self file or directory, and then stop listening to this file or directory.
The unmount File System cancels the mounting and no longer listens to the file system.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.