Linux: Find Files with a Given Size

How to use the find command…

In the current directory, find files with size greater than 4096 bytes:

find . -type f -size +4096c

In the current directory, find files with size lower than 4096 bytes:

find . -type f -size -4096c

As per the find‘s man page, the size can be specified as follows:

-size n[cwbkMG]
    File uses n units of space. The following suffixes can be used:
    `b'    for 512-byte blocks (this is the default if no suffix is used)
    `c'    for bytes
    `w'    for two-byte words
    `k'    for Kilobytes       (units of 1024 bytes)
    `M'    for Megabytes    (units of 1048576 bytes)
    `G'    for Gigabytes (units of 1073741824 bytes)
    The size does not count indirect blocks, but it does count
    blocks in sparse files that are not actually allocated. Bear in
    mind that the `%k' and `%b' format specifiers of -printf handle
    sparse files differently. The `b' suffix always denotes
    512-byte blocks and never 1 Kilobyte blocks, which is different
    to the behaviour of -ls.

In the current directory, delete files with size equal to zero:

find . -size 0 -delete
Advertisements
This entry was posted in Linux, Server and tagged , , , , . Bookmark the permalink.