Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

4 Answers 4

up vote 2 down vote accepted

Should be

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

That is find:

  • this directory only

  • type is a file

  • size less than 10 megs

share|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.

share|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

share|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 '{}' ';'

share|improve this answer

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.