The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Removing empty folders using 'find' deTTo UNIX for Dummies Questions & Answers 5 04-21-2008 06:24 PM
Empty Files DNAx86 Shell Programming and Scripting 3 04-18-2008 06:45 PM
how to find empty folders without using -empty lasse UNIX for Dummies Questions & Answers 7 01-16-2008 11:30 PM
deleting the empty files srivsn Shell Programming and Scripting 1 02-08-2006 03:39 AM
move files from folder thats are not empty Steven UNIX for Dummies Questions & Answers 8 11-21-2001 07:05 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 02-25-2006
Registered User
 

Join Date: Aug 2004
Posts: 141
How to find files not empty?

Is there any way, we can find files not empty? I know one can find empty files by using find with -size is equalled to 0.

Please let me know, how I can find files greater than 0 or any other size in number?
Reply With Quote
Forum Sponsor
  #2  
Old 02-25-2006
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
Code:
find . -type f  -exec wc -l {} \; | awk '$1 > 0 { print $2 }'
Reply With Quote
  #3  
Old 02-26-2006
Registered User
 

Join Date: Feb 2006
Location: Schenectady, NY
Posts: 130
You can use the find command to find non-zero length files:

find path -type f ! -size 0

In most UNIX implementations, the -size expression can also be used to search for file sizes of exactly N bytes (-size Nc), greater-than N bytes (-size +Nc), and less-than N bytes (-size -Nc).

The confusing thing is that the numeric following -size is, by default, 512-byte blocks not a byte count. The numeric must be followed by a 'c' for that. The following command will find files less than 2KB:

find . -type f -size -2048c -print

Conversely, for files greater than 2KB:

find . -type f -size +2048c -print

One note, the 512-byte block count does not directly translate into bytes. It's a long story. You can display a file's block usage with, under Solaris, ls -s. Stick to byte counts.

Oh, yes, one more thing, you can search for a specific range by using multiple -size expressions as long as they can all be satisfied by a single file. For example, locate files larger than 2KB and less than 8KB (inclusive):

find . -type f -size +2047c -size -8193c

Last edited by hegemaro; 02-26-2006 at 06:24 AM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0