[Linux] 文件 Modified/Created Data 修改

touch -m YYYYMMDDhhmm /File/Address/...	#  修改modified date
touch -t YYYYMMDDhhmm /File/Address/...	#  修改created date

touch -t YYYYMMDDhhmm /File/Address/...	#  同时修改两者

e.g.
YYYY --> 2020
MM --> 01
DD --> 01
hh --> 23
mm --> 59

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux C/C中,可以使用inotify API来监控文件系统的事件。inotify API提供了一种异步的、高效的文件系统事件监控机制,可以监控文件或目录的创建、删除、修改、移动等操作。 使用inotify API需要先创建一个inotify实例,并使用inotify_add_watch函数添加要监控的文件或目录。当文件系统中发生对应的事件时,inotify会通知应用程序。 下面是一个简单的例子,演示如何使用inotify API监控文件变化: ```c #include <stdio.h> #include <stdlib.h> #include <unistd.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 length, i = 0; int fd; int wd; char buffer[BUF_LEN]; fd = inotify_init(); if ( fd < 0 ) { perror( "inotify_init" ); } wd = inotify_add_watch( fd, "/tmp", IN_MODIFY | IN_CREATE | IN_DELETE ); while ( 1 ) { i = 0; length = read( fd, buffer, BUF_LEN ); if ( length < 0 ) { perror( "read" ); } while ( i < length ) { struct inotify_event *event = ( struct inotify_event * ) &buffer[ i ]; if ( event->len ) { 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 ); } } else if ( event->mask & IN_MODIFY ) { if ( event->mask & IN_ISDIR ) { printf( "The directory %s was modified.\n", event->name ); } else { printf( "The file %s was modified.\n", event->name ); } } } i += EVENT_SIZE + event->len; } } ( void ) inotify_rm_watch( fd, wd ); ( void ) close( fd ); exit( 0 ); } ``` 上面的代码中,先使用inotify_init函数创建一个inotify实例,然后使用inotify_add_watch函数添加要监控的目录。在while循环中,使用read函数读取inotify实例中的事件,然后根据事件类型进行相应的处理。最后使用inotify_rm_watch函数移除监控项,关闭inotify实例。 需要注意的是,inotify API只能用于Linux系统,其他操作系统需要使用不同的机制来监控文件系统事件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值