Is there a way with GNU find to find files with a size >=
or <=
a certain size? I have only found the >
, <
, ==
operators, e.g. -size +1M
, -size -1M
, -size 1M
, respectively.
In this blog, the author suggested a combination of multiple -size
arguments as in find . -type f -size +1M -size -2M
. However, this does not work for my find (GNU findutils) 4.4.2.
if [ (( $FILESIZE > MAXSIZE)) ]; -> if (( FILESIZE > MAXSIZE )); The arithmetic operators can serve as a conditional expression. (you don't need the $ within ((...)) )
Syntax of find command to find files bigger than given size in Linux. For example, “-size +4G” makes the find command to search for files greater than 4GB. Here, + sign is denote that look for files greater than or equal to N[Type], like in this case, -size +4G will make find command to look for files bigger than 4GB.
Using the -size flag The -size flag is used to find files of a specific size using k for kilobytes, M for megabytes, G for gigabytes, T for terabytes and P for petabytes. However on its own the size specified needs to be an exact match.
Since the operator <=
is logically equivalent to not >
(Not greater than), these 2 operators can be swapped with each other. In our example, to find files with size less than or equal to 1M, you can look for files not larger than 1M: -not -size +1M
.
The same logic can be applied to >=
using not <
.
the following command seems to work:
]$ find -version
find (GNU findutils) 4.4.2
find ~ -type f -size '+1k' -a -size '-3k' -exec ls -lah '{}' ';'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With