home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 17.13 Searching for Files by Type Chapter 17
Finding Files with find
Next: 17.15 Searching for Files by Permission
 

17.14 Searching for Files by Size

find has several operators that take a decimal integer. One such argument is -size . The number after this argument is the size of the files in disk blocks. Unfortunately, this is a vague number. Earlier versions of UNIX used disk blocks of 512 bytes. Newer versions allow larger block sizes, so a "block" of 512 bytes is misleading.

This confusion is aggravated when the command ls -s is used. The -s option supposedly lists the size of the file in blocks. But if your system has a different block size than ls -s has been programmed to assume, it can give a misleading answer. You can put a c after the number, and specify the size in bytes. To find a file with exactly 1234 bytes (as in an ls -l listing), type:

% find . -size 1234c -print

To search for files using a range of file sizes, a minus or plus sign can be specified before the number. The minus sign (- ) means less than, and the plus sign (+ ) means greater than. This next example lists all files that are greater than 10,000 bytes, but less than 32,000 bytes:

% find . -size +10000c -size -32000c -print

When more than one qualifier is given, both must be true (17.6 ) .

- BB


Previous: 17.13 Searching for Files by Type UNIX Power Tools Next: 17.15 Searching for Files by Permission
17.13 Searching for Files by Type Book Index 17.15 Searching for Files by Permission

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System