Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What commands do I need for Linux's ls to show the file size in MB?

share|improve this question
up vote 103 down vote accepted

ls -l --block-size=M will give you a long format listing (needed to actually see the file size) and round file sizes up to the nearest MiB.

If you want MB (10^6 bytes) rather than MiB (2^20 bytes) units, use --block-size=MB instead.

If you don't want the M suffix attached to the file size, you can use something like --block-size=1M. Thanks Stéphane Chazelas for suggesting this.

This is described in the man page for ls; man ls and search for SIZE. It allows for units other than MB/MiB as well, and from the looks of it (I didn't try that) arbitrary block sizes as well (so you could see the file size as number of 412-byte blocks, if you want to).

Note that the --block-size parameter is a GNU extension on top of the Open Group's ls, so this may not work if you don't have a GNU userland (which most Linux installations do). The ls from GNU coreutils 8.5 does support --block-size as described above. Thanks to kojiro for pointing this out.

share|improve this answer
A difference maybe worth noticing: --block-size=M cause a M suffix to be displayed next to the size, and you can use --block-size=1M to omit it. It may be worth mentioning as well that you need GNU ls for that (most non-embedded Linux systems will have GNU ls). – Stéphane Chazelas Feb 8 '13 at 12:59
Would this be GNU ls? Standard ls has no such argument. With the xsi extension ls has the -s flag, which makes it report the number of blocks, but there is no standard flag --block-size. – kojiro Feb 8 '13 at 13:15
@kojiro GNU ls does have --block-size as of coreutils 8.5, which is what's installed on my Debian Squeeze system. Since the question was explicitly for Linux and did not specify anything else, I'll admit I assumed a userland centered around GNU coreutils. I have updated the answer to clarify this. (Besides, Open Group ls doesn't seem to have -h either. :)) – Michael Kjörling Feb 8 '13 at 13:34
@StephaneChazelas: ls -l --block-size=Z (as well as ZB, Y, and YB) gives the following error (for the corresponding --block-size argument): ls: --block-size argument Z' too large. If I read ls(1)` correctly, Z is 1000^7, ZB is 1024^7, Y is 1000^8, and YB is 1024^8. I have no intuition on such large numbers -- what do you think, is there an overflow on the application level (i.e., some C variable) or is it beyond the system architecture? – Emanuel Berg Feb 9 '13 at 22:49
@EmanuelBerg, 1000^7 (10^21) is greater than 2^64 (which is ~10^19.27) – Stéphane Chazelas Feb 10 '13 at 10:17

ls -lh human readable file sizes, long format

share|improve this answer
That will print file sizes in GB for anything bigger than just under 1.0 GiB (I believe). – Michael Kjörling Feb 8 '13 at 8:36
yeah, sorry, i thought that's what was wanted (as opposed to bytes). – Sirex Feb 8 '13 at 8:48
I must say I'm a little surprised that this has received two upvotes, considering that it doesn't answer the question. (Or rather, it only does so when file sizes are in the range 1 MiB - 1 GiB.) -h is a useful switch that I too use quite often, but it doesn't do what the OP is after. – Michael Kjörling Feb 8 '13 at 10:35
@MichaelKjörling I don't see it as a bad answer (although I didn't upvote). Sometimes the OP doesn't word a question exactly as they should so it was possible that they just wanted human readable output and instead phrased that as "in MB". – Dason Feb 8 '13 at 14:33
@Dason I didn't downvote this, either, for precisely the reason you state as well as the fact that for most semi-large files, -h does meet the OP's stated requirement quite nicely. But I also didn't upvote, because as I said it doesn't really answer the question. As for "phrasing it wrong", well, the OP has been on SE (ServerFault, StackOverflow and SuperUser) at least since late 2009 - early 2010, so certainly can hardly be considered a newcomer to the site. – Michael Kjörling Feb 8 '13 at 14:39

ls -lhS sort by size, in human readable format

share|improve this answer
Please see the comments on ls -lh answer for reasons why this doesn't really answer the question. – Alexander Batischev May 4 at 19:11
Not only does this not really answer the question (as discussed in the comments to Sirex's answer) but it also doesn't add anything relevant over either existing answer: the OP isn't asking about sort order. – Michael Kjörling May 30 at 12:41
just thought sorting by size is a potential follow-up people might have, at least that's what I had – jaciefan Jun 3 at 21:53

Your Answer


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.