- 论坛徽章:
- 1
|
大家都知道,用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 编辑 ] |
|