Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In Centos, I have a text file in my home directory.

The command find . -size -1M doesn't show my file but find . -size -1000k does show it. This problem just seems to be happening when I use the number "1". The first command will work if I use -2M even though the file is only 500k in size.

Am I doing something wrong?

share|improve this question
2  
1M == 1024k, not 1000k –  warl0ck Oct 13 '12 at 12:14
    
Cheers, rookie mistake. –  Lukas88 Oct 13 '12 at 22:27

1 Answer 1

up vote 4 down vote accepted

find . -size -1M will only show file of size less than 1M, that is 0M. Yes, I know, it's confusing.

find . -size 1M will show you files whose size (rounded up to the upper MiB) is 1M (so any file size from 1 to 1048576). If you want from 0 to 1048575 (< 1M), that would be:

find . -size -1048576c

If you want from 0 to 1048576 (<= 1M)

find . -size -2M

or

find . ! -size +1M
share|improve this answer
    
Thanks, I would never have figured that. –  Lukas88 Oct 13 '12 at 22:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.