大家都知道,用find可以找出比某一文件新的文件,如:
find . -type f -newer filename
#查找比filename的age(岁数?)新的文件,那么要查比filename老的(old)的用find如何实现呢?(我不知道! #_#)
那么,刚看了看shell的手册,其中对文件的test的那段有几句介绍(看过的应该知道)引用:
file1 -nt file2
True if file1 is newer (according to modification date) than
file2, or if file1 exists and file2 does not.
file1 -ot file2
True if file1 is older than file2, or if file2 exists and file1
does not.
file1 -ef file2
True if file1 and file2 refer to the same device and inode num-
bers.
通俗的说, -nt就是看谁new,-ot就是看谁old ,那个-ef用于比较两个文件是否拥有相同的inode number(我这样理解的)
OK! 了解了这些,用shell的对file的test,解决这些问题就很方便了,:-)
ls|while read file;do
[[ $file -nt filename ]] && echo $file #找比filename新的文件
[[ $file -ot filename ]] && echo $file #找比filename老的文件
[[ $file -ef filename ]] && echo $file #像是找相同inode的(符号连接文件)
done
[ 本帖最后由 寂寞烈火 于 2005-12-19 03:55 编辑 ]
小渔儿 回复于:2005-12-19 08:51:23
不错,学习
icesummit 回复于:2005-12-19 10:35:37
烈火多来些这样的Tips, 让我等好好学习一下啊:)
dbcat 回复于:2005-12-19 12:13:42
引用:原帖由 寂寞烈火 于 2005-12-19 03:54 发表
大家都知道,用find可以找出比某一文件新的文件,如:
find . -type f -newer filename
#查找比filename的age(岁数?)新的文件,那么要查比filename老的(old)的用find如何实现呢?(我不知道! #_#)
那 ...
to烈火哥:每天起来的太早了, 要注意休息撒.
find /path ! -newer file
寂寞烈火 回复于:2005-12-19 15:32:05
引用:原帖由 dbcat 于 2005-12-19 12:13 发表
to烈火哥:每天起来的太早了, 要注意休息撒.
find /path ! -newer file
晕, 一个! 看出咱俩的差距! 唉!!!
引用:原帖由 icesummit 于 2005-12-19 10:35 发表
烈火多来些这样的Tips, 让我等好好学习一下啊:)
呵呵,每天晚上看看这些文档,确实不错~
lampo 回复于:2006-04-02 23:30:54
哈哈,谢了,方便不少。。
|