I need to find a file in my current directory whose size should be less than or equal to 10 MB.

ls -lh gives me the file size of each file but not sure how to find the files whose size are less than or equal to 10 MB.

host@407d:t1_snapshot$ ls -lth

Is there any way I can do that?


Should be

find ./ -maxdepth 1 -type f -size -10M

That is find:

  • this directory only

  • type is a file

  • size less than 10 megs

| improve this answer | |

You can use the find command e.g. to find any plain files smaller than 10MB in the current directory and give a long listing of them similar to ls -l

find . -maxdepth 1 -size -10M  -type f -ls

If you want to descend into subdirectories as well, remove the -maxdepth 1

| improve this answer | |

Well, the h switch will make this very tough, because the 'human-readable format' it specifies gives you files in G (for gigabyte) when over 1023MB, in M (for megabyte) when over 1023KB and in KB when over 1023 bytes.

ls -lsr > size && nano size
is a better command to use, because

the size is displayed consistently and
it will soft files by size for you, largest first, plus
it will output the result to the file 'size', and show you the result in the text editor nano.

Then, scroll up from the top of 'size' once the command completes and find the small files in nano.


Or, you can use find instead of ls , with

find ~ -type -a -size '-10M' -exec ls -lah '{}' ';'

| improve this answer | |

Open your terminal and type as

du -H --min-depth=1 /home/username

that will sort the usage min to max so that you can see what are less then < 10 MB size.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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