inotify 复制粘贴对应的事件
时间: 2024-04-02 19:31:37 浏览: 50
当通过 inotify 监控文件或目录时,可能会触发以下事件:
- IN_ACCESS:文件被读取。
- IN_ATTRIB:文件元数据被修改。
- IN_CLOSE_WRITE:文件被关闭并且可写。
- IN_CLOSE_NOWRITE:文件被关闭但不可写。
- IN_CREATE:一个新的文件或目录被创建。
- IN_DELETE:一个文件或目录被删除。
- IN_DELETE_SELF:被监控的文件或目录被删除。
- IN_MODIFY:文件被修改。
- IN_MOVE_SELF:被监控的文件或目录被移动。
- IN_MOVED_FROM:一个文件或目录从被监控目录中移动。
- IN_MOVED_TO:一个文件或目录移动到被监控目录中。
- IN_OPEN:文件被打开。
相关问题
使用inotify获取usb设备插拔事件,请用C语言写出程序
以下是使用inotify获取USB设备插拔事件的C语言程序:
```c
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/inotify.h>
#define EVENT_SIZE (sizeof (struct inotify_event))
#define BUF_LEN (1024 * (EVENT_SIZE + 16))
int main(int argc, char **argv)
{
int fd, wd;
char buf[BUF_LEN];
int len, i = 0;
char *p;
struct inotify_event *event;
fd = inotify_init();
if (fd < 0) {
perror("inotify_init");
return -1;
}
wd = inotify_add_watch(fd, "/dev/", IN_CREATE | IN_DELETE);
if (wd < 0) {
perror("inotify_add_watch");
return -1;
}
while (1) {
len = read(fd, buf, BUF_LEN);
if (len < 0) {
perror("read");
return -1;
}
i = 0;
while (i < len) {
event = (struct inotify_event *) &buf[i];
if (event->mask & IN_CREATE) {
if (event->mask & IN_ISDIR) {
printf("The directory %s was created.\n", event->name);
} else {
printf("The file %s was created.\n", event->name);
}
} else if (event->mask & IN_DELETE) {
if (event->mask & IN_ISDIR) {
printf("The directory %s was deleted.\n", event->name);
} else {
printf("The file %s was deleted.\n", event->name);
}
}
i += EVENT_SIZE + event->len;
}
}
inotify_rm_watch(fd, wd);
close(fd);
return 0;
}
```
该程序使用inotify机制监听/dev/目录下的IN_CREATE和IN_DELETE事件,当有USB设备插入或拔出时,会打印相应的消息。注意,该程序需要使用root权限运行。
rsync inotify
rsync inotify是一种实时同步工具,可以在文件系统中监视文件的变化,并在文件发生变化时自动进行同步操作。通过使用rsync和inotify结合的方式,可以实现文件的实时备份和同步。引用提供了其中一种使用rsync的命令格式,可以通过rsync命令将远程服务器上的文件同步到本地服务器。引用中的脚本演示了如何使用inotify和rsync结合实现文件的实时同步。在该脚本中,inotify命令用于监视文件的变化,当文件发生变化时触发rsync命令进行同步操作。引用提供了配置Master主机的方法,通过修改rsync源服务器配置文件,关闭只读模式并启动rsync服务,以实现文件的双向同步。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [rsync远程同步](https://blog.csdn.net/yangzhou__/article/details/121319305)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [rsync数据同步+inotify实时同步](https://blog.csdn.net/qxdbb/article/details/124528049)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)