Find Files by File Size


file -size

Sometimes you'll want to find files based on their size. The find command can assist here as well. To specify a size, use the -size option, followed by a letter representing the size scheme you wish to use. If you don't provide a letter, the default is used; however, you should understand that you probably won't find what you want. If you don't append a letter after the number, the default is in bytes (which is then divided by 512 and rounded up to the next integer). This is too much math. It's easier to use a suffix after the number that represents the size in more common terms, as shown in Table 10.1.

Table 10.1. Find Files by Size

Suffix

Meaning

b

512-byte blocks (the default)

c

Bytes

k

Kilobytes (KB)

M

Megabytes (MB)

G

Gigabytes (GB)


Let's say we want to find every Clash song from their immortal album, London Calling, that is 10MB. (Yes, these were encoded at a super-high rate.) This job is easy enough with find:

$ cd Punk/Clash/1979_London_Calling $ find . -size 10M ./07_-_The_Right_Profile.ogg ./08_-_Lost_In_The_Supermarket.ogg ./09_-_Clampdown.ogg ./12_-_Death_Or_Glory.ogg 


That's weird. Only four songs? Here's where you need to understand a "gotcha" associated with using find: If you say 10M, then find looks for files that are exactly 10MB in size (rounded to 10MB, of course). If you want files larger than 10MB, you need to place a plus sign (+) in front of the given size; if you want files smaller than 10MB, use a minus sign (-) in front of the size:

$ find . -size +10M ./Jimmy_Jazz.ogg ./ Lover's_Rock.ogg ./ Revolution_Rock.ogg 


Now we have a problem. Specifying 10M gives us files that are exactly 10MB, excluding those that are bigger, while specifying +10M gives us files that are larger than 10MB, excluding those that are exactly 10MB. How do we get both? If you want to learn how to obtain files that are 10MB and larger, see the "Show Results If Either Expression Is True (OR)" section later in this chapter.

Tip

If you want to find large text files, use c after your number. As Table 10.1 shows, c changes the search size to bytes. Every character in a text file is a byte, so an easy way to remember c is to associate it with the "characters" in a text file.

For instance, to find enormous text files, you can use this code:

$ find /home/scott/documents -size +500000c 





Linux Phrasebook
Linux Phrasebook
ISBN: 0672328380
EAN: 2147483647
Year: 2007
Pages: 288

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net