Linux如何過(guò)濾空文件?Linux過(guò)濾空文件的命令總結(jié)
在Linux中有經(jīng)常做文件的操作,今天有個(gè)同事在生產(chǎn)環(huán)境統(tǒng)計(jì)數(shù)據(jù),發(fā)現(xiàn)有很多日志文件都是空的,文件太多了,他想查看一下有哪些文件不是空文件。
而且還不想使用腳本,就想用一個(gè)命令來(lái)搞定,確實(shí)夠懶的一個(gè)人。簡(jiǎn)單模擬了下。我只想查看e.lst 因?yàn)樗拇笮〔皇强盏摹?/p>
DUM1102 /oravl01/Oracle> ll *.lst
-rw-r--r-- 1 oracle dba 0 Jul 21 15:39 a.lst
-rw-r--r-- 1 oracle dba 0 Jul 21 15:39 b.lst
-rw-r--r-- 1 oracle dba 0 Jul 21 15:39 c.lst
-rw-r--r-- 1 oracle dba 0 Jul 21 15:39 d.lst
-rw-r--r-- 1 oracle dba 7 Jul 21 15:39 e.lst
最精簡(jiǎn)的命令就是使用grep了。
DUM1102 /oravl01/oracle> ll *.lst|grep -v " 0 "
-rw-r--r-- 1 oracle dba 7 Jul 21 15:39 e.lst
當(dāng)然也可以使用awk來(lái)完成。
難度再升級(jí)一下,新增一個(gè)文件 f.lst 現(xiàn)在文件的結(jié)構(gòu)如下:
DUM1102 /oravl01/oracle> ll *.lst
-rw-r--r-- 1 oracle dba 0 Jul 21 15:39 a.lst
-rw-r--r-- 1 oracle dba 0 Jul 21 15:39 b.lst
-rw-r--r-- 1 oracle dba 0 Jul 21 15:39 c.lst
-rw-r--r-- 1 oracle dba 0 Jul 21 15:39 d.lst
-rw-r--r-- 1 oracle dba 7 Jul 21 15:39 e.lst
-rw-r--r-- 1 oracle dba 14 Jul 21 16:35 f.lst
他現(xiàn)在想查看大小為7字節(jié)的文件,使用awk來(lái)牛刀小試。
ll *.lst | awk -v file_size=7 '{ if ( $5==file_size ) print $5 " " $9}'
DUM1102 /oravl01/oracle> ll *.lst | awk -v file_size=7 '{ if ( $5==file_size ) print $5 " " $9}'
7 e.lst
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。