Summary of linux Command for filtering Empty files

Source: Internet
Author: User

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.

 
 
  1. DUM1102 /oravl01/oracle> ll *.lst  
  2. -rw-r--r-- 1 oracle dba 0 Jul 21 15:39 a.lst  
  3. -rw-r--r-- 1 oracle dba 0 Jul 21 15:39 b.lst  
  4. -rw-r--r-- 1 oracle dba 0 Jul 21 15:39 c.lst  
  5. -rw-r--r-- 1 oracle dba 0 Jul 21 15:39 d.lst  
  6. -rw-r--r-- 1 oracle dba 7 Jul 21 15:39 e.lst 

The simplest command is to use grep.

 
 
  1. DUM1102 /oravl01/oracle> ll *.lst|grep -v " 0 "  
  2. -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:

 
 
  1. DUM1102 /oravl01/oracle> ll *.lst  
  2. -rw-r--r-- 1 oracle dba 0 Jul 21 15:39 a.lst  
  3. -rw-r--r-- 1 oracle dba 0 Jul 21 15:39 b.lst  
  4. -rw-r--r-- 1 oracle dba 0 Jul 21 15:39 c.lst  
  5. -rw-r--r-- 1 oracle dba 0 Jul 21 15:39 d.lst  
  6. -rw-r--r-- 1 oracle dba 7 Jul 21 15:39 e.lst  
  7. -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.

 
 
  1. ll *.lst | awk -v file_size=7 '{ if ( $5==file_size ) print $5 " " $9}'  
  2. DUM1102 /oravl01/oracle> ll *.lst | awk -v file_size=7 '{ if ( $5==file_size ) print $5 " " $9}'  

7 e. lst

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.