- 論壇徽章:
- 1
|
大家都知道,用find可以找出比某一文件新的文件,如:
- find . -type f -newer filename
復(fù)制代碼
#查找比filename的age(歲數(shù)?)新的文件,那么要查比filename老的(old)的用find如何實現(xiàn)呢?(我不知道! #_#)
那么,剛看了看shell的手冊,其中對文件的test的那段有幾句介紹(看過的應(yīng)該知道) 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
復(fù)制代碼
[ 本帖最后由 寂寞烈火 于 2005-12-19 03:55 編輯 ] |
|