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

- 26,755
- 12
- 71
- 136

- 7,913
- 3
- 13
- 10
2 Answers
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.
If you simply want file sizes in "reasonable" units, rather than specifically megabytes, then you can use -lh
to get a long format listing and human readable file size presentation. This will use units of file size to keep file sizes presented with about 1-3 digits (so you'll see file sizes like 6.1K
, 151K
, 7.1M
, 15M
, 1.5G
and so on.
The --block-size
parameter 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 a number of 429-byte blocks if you want to).
Note that both --block-size
and -h
are GNU extensions 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 and -h as described above. Thanks to kojiro for pointing this out.

- 26,755
- 12
- 71
- 136
-
18A 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 08 '13 at 12:59
-
3Would this be GNU `ls`? [Standard `ls`](http://pubs.opengroup.org/onlinepubs/009695399/utilities/ls.html) has no such argument. With the [xsi extension](http://pubs.opengroup.org/onlinepubs/009695399/help/codes.html#XSI) `ls` has the `-s` flag, which makes it report the number of blocks, but there is no standard flag `--block-size`. – kojiro Feb 08 '13 at 13:15
-
2@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. `:)`) – user Feb 08 '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 09 '13 at 22:49
-
3@EmanuelBerg, 1000^7 (10^21) is greater than 2^64 (which is ~10^19.27) – Stéphane Chazelas Feb 10 '13 at 10:17
-
Typically when I'm looking at file sizes, am I looking at MiB or MB? – chris Jan 05 '17 at 20:18
-
@chris_anderson I don't know. Maybe you should ask that as a separate question. – user Jan 06 '17 at 21:24
-
1This returns `ls: illegal option -- -` for me on OSX Sierra 10.12.6 – Tom Dec 09 '17 at 12:33
-
7@Tom As it says in the final paragraph of the answer, `--block-size` is a GNU extension. I suspect that Mac OS X doesn't use GNU `ls`. – user Dec 09 '17 at 14:56
-
5@MichaelKjörling I can confirm that the --block-size flag causes an error on Mac OS X 10.13.2, but that ls -lh does work. – John Madden Feb 11 '18 at 21:47
-
1`du -sm *` is another (faster to type) way to get something similar. But `-m` isn't POSIX-standard either. (`-k` is, so you can `du -sk *` even on a system with only POSIX options). – Peter Cordes Feb 22 '18 at 21:19
-
@PeterCordes Sure, but OP asked specifically for a solution using `ls`. – user Feb 23 '18 at 08:30
-
Also, AFAIU, `ls -s --block-size=K` shows the file size rounded up *to the nearest block* (*disk size*), whereas `ls -lh` does not, and shows the factual *contents* size (for example, 396 KB vs 393 KB) – jakub.g Jul 11 '18 at 10:36
-
For macOS, we have the GNU `coreutils` package with Homebrew and the command `gls` (prefixed with `g` to avoid conflicts). Works like a charm – Ludovic Kuty Dec 13 '18 at 14:58
-
Note that this won't work at all on a thinly provisioned VM. – Alex Jansen Jun 11 '19 at 23:22
-
@AlexJohnson It should work fine if your VM has a GNU userland, as already stated in the answer. – user Jun 12 '19 at 08:27
-
Why is this long-winded, impossible to recall, overly verbose switch preferable to the simple, consistent and widely used across commands "human" readable switch: -h – Rick O'Shea Oct 28 '19 at 02:16
-
2@RickO'Shea Because passing `-h` to `ls` doesn't guarantee that sizes are printed in megabytes. Since the question specifically asked how to make `ls` show file sizes in megabytes, suggesting to use `-h` provides an answer to the question only for a subset of the possibilities. That said, there's an answer specifically suggesting `ls -lh` if you prefer that. – user Nov 02 '19 at 12:23
-
I'm the 666th +1 :O – Theodore R. Smith Sep 13 '20 at 05:25
ls -lh
gives human readable file sizes, long format.
ls
from the GNU coreutils package gives sizes in binary byte format in this case, e.g. Mebibyte (MiB), which is strongly endorsed by IEEE and CIPM instead of Megabyte (MB).
It uses k, M, G, and T suffixes (or no suffix for bytes) as needed so the number stays small, e.g. 1.4K
or 178M
.
-h
is a GNU coreutils extension, not baseline POSIX.
Note that this doesn't answer the question exactly as asked. If you want sizes strictly in MiB even for small or gigantic files, Michael Kjörling's answer does that for GNU coreutils ls
.

- 5
- 2

- 7,166
- 1
- 15
- 18
-
5That will print file sizes in GB for anything bigger than just under 1.0 GiB (I believe). – user Feb 08 '13 at 08:36
-
-
8@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 08 '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. – user Feb 08 '13 at 14:39
-
15Upvoted. "This doesn't answer the (MB) question" is a perfectly valid statement but this answer has only increased the usefulness of this SO page since this answer is in same context. I only came to this page looking for a solution to generic "show dates in human readable form" requirement and `h` is far easier to write than `--block-size=M` – Ejaz Mar 19 '17 at 10:08
-
9"human-readable" is kind of ironic. Who uses `ls -l` at all if not humans? :p – phil294 May 09 '17 at 14:17
-
@Blauhirn not really, often times the output of commands are piped as input for other commands – cheng yang Aug 06 '17 at 21:44
-
3@chengyang: parsing `ls -l` output is the wrong way to do things, 99% of the time. https://unix.stackexchange.com/questions/128985/why-not-parse-ls. That 1% is being generous, and is pretty much limited to one-liners you write interactively for one-time use, not a script you're going to use repeatedly on unknown filenames. – Peter Cordes Feb 22 '18 at 21:03
-
2@Blauhirn: sometimes you want an exact size in bytes you can copy/paste or compare with another number, instead of a rounded size you can read quickly. But I see what you mean, it is a bit funny. – Peter Cordes Feb 22 '18 at 21:16
-
Under macOS, the unit for the sizes is a power of 2, not 10. So it is MiB instead of MB. I prefer the powers of 10. – Ludovic Kuty Dec 13 '18 at 15:02
-
-
@phil294, I have scripts that use ls -l to get size and other details and they need a consistent size format so that all sizes can be treated as equivalent. Over time with a system and automation, the computer ends up reading itself more than any human does. – Zim Nov 15 '19 at 18:04
-
This is much easier than block size. Had a colleague SS a 1.5G ls -l? and I was like how the heck did he do that? Since I am the devops guy I can't just ask him. So thanks 2013 Sirex! – dustbuster Apr 06 '22 at 15:20
-
I personally prefer `ll -h`; just slightly less to have to remember. ;) – Talk Nerdy To Me Sep 08 '22 at 17:51