Summary of linux Command for filtering Empty files
In linux, file operations are often performed. Today, a colleague collects statistics in the production environment and finds that many log files are empty and there are too many files, he wants to check which files are not empty files.
If you don't want to use a script, you just want to use a command to handle it. It's really a lazy person.
A simple simulation. I only want to check e. lst because its size is not empty.
- 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
The simplest command is to use grep.
- DUM1102 /oravl01/oracle> ll *.lst|grep -v " 0 "
- -rw-r--r-- 1 oracle dba 7 Jul 21 15:39 e.lst
You can also use awk.
The difficulty is upgraded. The structure of the new file f. lst is as follows:
- 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
He now wants to view a 7-byte file and use awk to test it.
- 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