[LINUX]警告:检测到时钟错误。您的创建可能是不完整的。

 
原因:
    如果上一次编译时为20071001,你把系统时间改成20070901后再编译就会报这样的错误.
解决:
    把时间改了或运行一下下面的命令再make
 
    find . -type f -exec touch {} \;

============================

linux批量修改文件时间的两种方法

 
创建文件我们可以通过touch来创建。同样,我们也可以使用touch来修改文件时间。touch的相关参数如下:
 
-a : 仅修改access time。-c : 仅修改时间,而不建立文件。
-d : 后面可以接日期,也可以使用 --date="日期或时间"
-m : 仅修改mtime。
-t : 后面可以接时间,格式为 [YYMMDDhhmm]
 
下面只有两个参数存在差别,d与f,d表示文件夹,f表示文件。
查找当前目录下,所有的文件夹以及子文件夹,并把所有的文件夹及子文件夹设置成755,包括当前目录
find ./ -type d -exec touch {} \;
查找当前目录下,所有的文件以及子文件夹下的文件,并把所有的文件设置成644
find ./ -type f -exec touch {} \;
修改单个文件的时间为
touch 文件名
 
1、批量修改为当前系统时间
touch `find ./* -name '*'`
 
2、批量修改为指定时间
touch -t 201412261313.30 `find ./* -name '*'`
-t后面的时间格式为 [[CC]YY]MMDDhhmm[.ss] 

atime、mtime、ctime

============
 

Linux系统文件有三个主要的时间属性,分别是ctime(change time, 而不是create time), atime(access time), mtime(modify time)。后来为了解决atime的性能问题,还引入了一个relatime的属性,下面一一解释。

ctime, 很多朋友把它理解成create time,包括很多误导人的书籍也是这么写。实际上ctime是指change time。

mtime, 就是modify time。

mtime和ctime的区别在于,只有修改了文件的内容,才会更新文件的mtime,而对文件更名,修改文件的属主等操作,只会更新ctime。

举例说明: 对文件进行mv操作,mtime不变,ctime更新;编辑文件内容,mtime和ctime同时修改。其他操作的影响,可以自己试验。但是我发现对文件执行touch操作,会同时修改mtime和ctime,所以具体修改哪个时间,还取决于不同命令自己的实现;

atime, 这个就是每次查看文件内容的时候会更新。比如cat操作,而ls操作是不会更新的。

你可以通过stat来查看文件的mtime,ctime,atime等属性,也可以通过ls命令来查看,具体如下:

ls -lc filename 列出文件的 ctime

ls -lu filename 列出文件的 atime

ls -l filename 列出文件的 mtime

从kernel2.6.29开,还默认集成了一个relatime的属性。这个功能我个人理解是为了解决atime的兼容性问题。因为在文件读操作很频繁的系统中,atime更新所带来的开销很大,所以很多SA都在挂装文件系统的时候使用noatime属性来停止更新atime。但是有些程序需要根据atime进行一些判断和操作,所以Linux就推出了一个relatime特性。

使用这个特性来挂装文件系统后,只有当mtime比atime更新的时候,才会更新atime。事实上,这个时候atime和mtime已经是同一个东西了。所以这个选项就是为了实现对atime的兼容才推出的。并不是一个新的时间属性。使用方法就是通过mount -o relatime /dir来挂装目录。

在网上找到了一个表,列出了常见的系统调用对这几个时间的影响,包括对父目录的影响,很清晰。

On Thu, Oct 05, 2006 at 12:33:57PM -0700, Dmitri V. Ivanov wrote:

> *********************************************************************
> Due to deletion of content types excluded from this list by policy,
> this multipart message was reduced to a single part, and from there
> to a plain text message.
> ********************************************************************* It seems I've failed to send html version... There is a my opinion about 'Why' and 'How' and next to it my script.
It seems to me too slow. It sorts all files with directory whereas to
sort directories is sufficient. But to sort all files seems to be
usefull to get list of deleted files like uniq. Why and How:
========= First of all about file timestamps and their update [1]in common and table
with details: +-------------------------------------------------+
| | timestamps marked for update |
| syscall |---------------------------------|
| | file | parent dir |
|---------------+-------------------+-------------|
| [2]chdir | | |
|---------------| - | - |
| [3]fchdir | | |
|---------------+-------------------+-------------|
| [4]chmod | | |
|---------------| ctime | - |
| [5]fchmod | | |
|---------------+-------------------+-------------|
| [6]chown | | |
|---------------| | |
| [7]fchown | ctime | - |
|---------------| | |
| [8]lchown | | |
|---------------+-------------------+-------------|
| [9]close | - | - |
|---------------+-------------------+-------------|
| [10]creat | atime,ctime,mtime | ctime,mtime |
|---------------+-------------------+-------------|
| [11]execve | atime | - |
|---------------+-------------------+-------------|
| [12]fcntl | - | - |
|---------------+-------------------+-------------|
| [13]ftruncate | | |
|---------------| ctime,mtime | - |
| [14]truncate | | |
|---------------+-------------------+-------------|
| [15]fstat | | |
|---------------| | |
| [16]stat | - | - |
|---------------| | |
| [17]lstat | | |
|---------------+-------------------+-------------|
| [18]fsync | | |
|---------------| - | - |
| [19]fdatasync | | |
|---------------+-------------------+-------------|
| [20]link | ctime | ctime,mtime |
|---------------+-------------------+-------------|
| [21]lseek | - | - |
|---------------+-------------------+-------------|
| [22]mknod | atime,ctime,mtime | ctime,mtime |
|---------------+-------------------+-------------|
| [23]mkdir | atime,ctime,mtime | ctime,mtime |
|---------------+-------------------+-------------|
| [24]mmap | * | - |
|---------------+-------------------+-------------|
| [25]munmap | - | - |
|---------------+-------------------+-------------|
| [26]msync | * | - |
|---------------+-------------------+-------------|
| [27]open | * | * |
|---------------+-------------------+-------------|
| [28]pread | | |
|---------------| | |
| [29]read | atime | - |
|---------------| | |
| [30]readv | | |
|---------------+-------------------+-------------|
| [31]pwrite | | |
|---------------| | |
| [32]write | ctime,mtime | - |
|---------------| | |
| [33]writev | | |
|---------------+-------------------+-------------|
| [34]rename | implementation | ctime,mtime |
|---------------+-------------------+-------------|
| [35]rmdir | - | ctime,mtime |
|---------------+-------------------+-------------|
| [36]readlink | * | - |
|---------------+-------------------+-------------|
| [37]readdir | atime | - |
|---------------+-------------------+-------------|
| readahead | ? | ? |
|---------------+-------------------+-------------|
| [38]symlink | * | * |
|---------------+-------------------+-------------|
| sendfile | ? | ? |
|---------------+-------------------+-------------|
| [39]unlink | - | ctime,mtime |
|---------------+-------------------+-------------|
| [40]utime | ctime | - |
   |---------------+-------------------+-------------|
 
linux下查看和修改文件时间
 

一、查看文件时间及相关命令

1、stat查看文件时间

[root@web10 ~]# stat install.logFile: “install.log”Size: 33386           Blocks: 80         IO Block: 4096   一般文件Device: fd00h/64768d    Inode: 7692962     Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)Access: 2012-07-13 16:02:34.000000000 +0800Modify: 2011-11-29 16:03:06.000000000 +0800Change: 2011-11-29 16:03:08.000000000 +0800

说明:Access访问时间。Modify修改时间。Change状态改变时间。可以stat *查看这个目录所有文件的状态。

而我们想要查看某文件的三个时间中的具体某个时间,并以年月日时分秒的格式保存。我们可以使用下面的命令:

[root@web10 ~]# stat install.log|grep -i Modify | awk -F. '{print $1}' | awk '{print $2$3}'| awk -F- '{print $1$2$3}' | awk -F: '{print $1$2$3}'20111129160306

2、ls查看文件时间

相应的通过ls 查看时也有三个时间:

• modification time(mtime,修改时间):当该文件的“内容数据”更改时,就会更新这个时间。内容数据指的是文件的内容,而不是文件的属性。
• status time(ctime,状态时间):当该文件的”状态(status)”改变时,就会更新这个时间,举例来说,更改了权限与属性,就会更新这个时间。
• access time(atime,存取时间):当“取用文件内容”时,就会更新这个读取时间。举例来说,使用cat去读取 ~/.bashrc,就会更新atime了。

[root@web10 ~]# ls -l --time=ctime install.log-rw-r--r-- 1 root root 33386 2011-11-29 install.log
[root@web10 ~]# ls -l --time=atime install.log-rw-r--r-- 1 root root 33386 07-13 16:02 install.log

注意:ls参数里没有--mtime这个参数,因为我们默认通过ls -l查看到的时间就是mtime 。

 二、修改文件时间

创建文件我们可以通过touch来创建。同样,我们也可以使用touch来修改文件时间。touch的相关参数如下:

-a : 仅修改access time。-c : 仅修改时间,而不建立文件。
-d : 后面可以接日期,也可以使用 --date="日期或时间"
-m : 仅修改mtime。
-t : 后面可以接时间,格式为 [YYMMDDhhmm]

注:如果touch后面接一个已经存在的文件,则该文件的3个时间(atime/ctime/mtime)都会更新为当前时间。若该文件不存在,则会主动建立一个新的空文件。

[root@web10 ~]# touch install.log[root@web10 ~]# stat install.logFile: “install.log”Size: 33386           Blocks: 80         IO Block: 4096   一般文件Device: fd00h/64768d    Inode: 7692962     Links: 1Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)Access: 2012-07-13 16:21:50.000000000 +0800Modify: 2012-07-13 16:21:50.000000000 +0800Change: 2012-07-13 16:21:50.000000000 +0800

同样,使用ls ,查看到的结果也一样。

[root@web10 ~]# ls -l --time=ctime install.log-rw-r--r-- 1 root root 33386 07-13 16:21 install.log
[root@web10 ~]# ls -l --time=atime install.log-rw-r--r-- 1 root root 33386 07-13 16:21 install.log
[root@web10 ~]# ls -l install.log-rw-r--r-- 1 root root 33386 07-13 16:21 install.log

下面再看一个和touch不相关的例子:

[root@web10 ~]# cp /etc/profile .;ll --time=atime profile ;ll --time=ctime profile
cp:是否覆盖“./profile”? y
-rw-r--r-- 1 root root 1344 07-13 16:24 profile
-rw-r--r-- 1 root root 1344 07-13 16:25 profile

因为我之前运行过这个命令一次,所以会出现覆盖,不过这个覆盖出的好,刚才让我们看到了atime和ctime的时间的差别。

我们再回到touch利用touch修改文件时间:

1. 同时修改文件的修改时间和访问时间
touch -d "2010-05-31 08:10:30" install.log
2. 只修改文件的修改时间
touch -m -d "2010-05-31 08:10:30" install.log
3. 只修改文件的访问时间
touch -a -d "2010-05-31 08:10:30" install.log

下面再给一个rootkit木马常用的伎俩。就是把后一个文件的时间修改成和前一个相同。

touch -acmr /bin/ls /etc/sh.conf

另外touch还支持像date命令一样参数修改文件时间:

[root@web10 ~]# touch -d "2 days ago" install.log ; ll install.log-rw-r--r-- 1 root root 33386 07-11 16:35 install.log

最后总结下常用的文件操作与时间的关系:

1、访问时间,读一次这个文件的内容,这个时间就会更新。比如对这个文件使用more命令。ls、stat命令都不会修改文件的访问时间。

2、修改时间,对文件内容修改一次,这个时间就会更新。比如:vim后保存文件。ls -l列出的时间就是这个时间。

3、状态改变时间。通过chmod命令更改一次文件属性,这个时间就会更新。查看文件的详细的状态、准确的修改时间等,可以通过stat命令 文件名。

==========================================

[LINUX]警告:检测到时钟错误。您的创建可能是不完整的。的更多相关文章

  1. [转]make: 警告:检测到时钟错误。您的创建可能是不完整的。

    转自http://blog.csdn.net/maopig/article/details/6599660 我在make的时候也出现了同样的问题,不过不是什么大问题,这个不影响编译结果 分析原因可能是 ...

  2. make: 警告:检测到时钟错误。您的创建可能是不完整的。

    我在make的时候也出现了同样的问题,不过不是什么大问题,这个不影响编译结果,但是强迫症还是希望能解决掉 分析原因可能是:服务器上的文件最后修改时间比当前时钟要晚 解决办法:用touch 命令把源程序 ...

  3. make: 警告:检测到时钟错误。您的创建可能是不完整的。

    问题: make: 警告:检测到时钟错误.您的创建可能是不完整的. 原因:1. 文件时间不一致.(或者修改了系统时间) 如何解决:你touch *一下,然后重新编译 touch * touch命令有两 ...

  4. Linux死锁检测-Lockdep

    关键词:LockDep.spinlock.mutex. lockdep是内核提供协助发现死锁问题的功能. 本文首先介绍何为lockdep,然后如何在内核使能lockdep,并简单分析内核lockdep ...

  5. Linux 入侵检测小结

    Linux  入侵检测小结 0x00 审计命令 在linux中有5个用于审计的命令: last:这个命令可用于查看我们系统的成功登录.关机.重启等情况:这个命令就是将/var/log/wtmp文件格式 ...

  6. Linux kernel ‘lbs_debugfs_write’函数数字错误漏洞

    漏洞名称: Linux kernel ‘lbs_debugfs_write’函数数字错误漏洞 CNNVD编号: CNNVD-201311-421 发布时间: 2013-11-29 更新时间: 2013 ...

  7. Linux kernel get_prng_bytes函数数字错误漏洞

    漏洞名称: Linux kernel get_prng_bytes函数数字错误漏洞 CNNVD编号: CNNVD-201310-142 发布时间: 2013-10-11 更新时间: 2013-10-1 ...

  8. [转帖]Linux的标准输入 标准输出和错误输出

    Linux标准输入.输出和错误和文件重定向 专题 https://www.cnblogs.com/softidea/p/3965093.html 感觉自己对 这一块的理解一直不好 昨天同事给了一个 b ...

  9. linux异常处理:selinux配置错误导致无法重启

    点击返回自学Linux集锦 linux异常处理:selinux配置错误导致无法重启 一次linux无法重启异常记录: 当时第一反应就是梳理最近的配置变更,特别是能预知相关的就是selinux配置变更. ...

随机推荐

  1. Generating Complex Procedural Terrains Using GPU

    前言:感慨于居然不用tesselation也可以产生这么复杂的地形,当然致命的那个关于不能有洞的缺陷还是没有办法,但是这个赶脚生成的已经足够好了,再加上其它模型估 计效果还是比较震撼的.总之好文共分享 ...

  2. ReentrantLock详解

    ReentrantLock概述 ReentrantLock是Lock接口的实现类,可以手动的对某一段进行加锁.ReentrantLock可重入锁,具有可重入性,并且支持可中断锁.其内部对锁的控制有两种 ...

  3. JNI模板

    java为了调用底层驱动函数,需要调用外部的C/C++代码,java提供了JNI接口: 然后将C代码编译成库(windows下 .dll / android环境下 .so) arm-linux-gcc ...

  4. python装饰器+递归+冒泡排序

    冒泡排序 li = [33, 2, 10, 1,23,23523,5123,4123,1,2,0] for k in range(1,len(li)): for i in range(len(li) ...

  5. Electronic Devices【电子设备】

    Electronic Devices We may think we're a culture that gets rid of our worn technology at the first si ...

  6. spring boot踩坑记

    Resolved exception caused by handler execution: org.springframework.http.converter.HttpMessageNotWri ...

  7. 【转】mybatis调用mssql有输入输出参数那种..

    吐槽下,百度的搜索能力真心垃圾(有可能是我没想好关键词的缘故吧..)... 谷歌中国程序员呼唤你... 这面这边文章是别人的,感觉不错,转过来. http://lohasle.iteye.com/bl ...

  8. python2.7入门---循环语句(while)

        接下来就要了解循环语句了.我们都知道,程序在一般情况下是按顺序执行的.编程语言提供了各种控制结构,允许更复杂的执行路径.循环语句允许我们执行一个语句或语句组多次,下面是在大多数编程语言中的循环 ...

  9. ajax同步和异步的切换

    ajax为网页提供了非常不错的异步机制,但是有时候两个ajax放在一起,希望第一个完成后再继续第二个ajax的执行.这时候可以将第一个ajax代码带上同步参数即可,如下: $.ajax({ async ...

  10. vs13发布web程序 iis上

    一.配置iis 1,找到控制面板--程序--启用或关闭Windows功能 2,从列表中选择Internet Infomation Services,并且把相应的功能条目勾选上,如果不清楚,可以全部选中 ...