今天遇到一个特殊需求,需要找到某天(例如2017-04-13)以及这之后生成的空文件。那么这个要怎么处理呢?这个当然是用find命令来解决。如下所示:
-mtime -5 表示查找距现在 5*24H 内修改过的文件
-type f -empty 表示空文件
由于需要以显示修改时间等文件信息,所以使用-exec ls -lt {}\; 具体命令如下所示:
$ find ./ -mtime -5 -type f -empty -exec ls -lt {} \; | more
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 15 21:30 ./PO/KK_WIS/in/POGETWISI09L3302.txt
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 15 23:40 ./PO/KK_WIS/log/POGETWISI09H3302.16643223.out
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 16 03:24 ./PO/KK_WIS/log/POGETWISI13R3705.16646635.out
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 15 23:43 ./PO/KK_WIS/log/POGETWISI09D3302.16643223.log
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 16 03:24 ./PO/KK_WIS/log/POGETWISI13R3705.16646635.log
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 15 03:25 ./PO/KK_WIS/log/POGETWISI13R3704.16643862.log
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 15 23:41 ./PO/KK_WIS/log/POGETWISI09L3302.16643223.out
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 15 23:40 ./PO/KK_WIS/log/POGETWISI09H3302.16643223.log
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 15 23:42 ./PO/KK_WIS/log/POGETWISI09S3302.16643223.out
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 15 23:41 ./PO/KK_WIS/log/POGETWISI09L3302.16643223.log
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 15 23:42 ./PO/KK_WIS/log/POGETWISI09S3302.16643223.log
............................................................
如果我们需要按修改时间做一个排序,那么可以使用下面命令:
$ find ./ -mtime -5 -type f -empty -exec ls -lt {} \; | sort -n -k6 |more
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 13 22:00 ./PO/CC_B2B/log/20170413.download.CICN.lst
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 13 22:00 ./PO/CC_B2B/log/20170413.download.FFI-EEL.lst
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 13 22:00 ./PO/CC_B2B/log/20170413.download.FFI-GET.lst
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 13 22:00 ./PO/CC_B2B/log/20170413.download.HSOCN-EEL.lst
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 13 22:00 ./PO/CC_B2B/log/20170413.download.HSOCN-GET.lst
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 13 23:01 ./PO/CC_B2B/arch/SOEELB2BI16N3473.16631117.txt
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 13 23:05 ./AP/CC_B2B/arch/APEELB2BLABI01H2919.16631124.txt
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 13 23:30 ./AP/CC_B2B/arch/APEELB2BI01H3660.16631214.txt
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 14 22:00 ./PO/CC_B2B/log/20170414.download.CICN.lst
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 14 22:00 ./PO/CC_B2B/log/20170414.download.FFI-EEL.lst
-rw-r--r--. 1 oaintprd oaintprd 0 Apr 14 22:00 ./PO/CC_B2B/log/20170414.download.FFI-GET.lst
............................................................