How to display files sizes in MB in Linux/Ubuntu

Update on 3/6/2022 – Sometimes we want to see the sizes of files as returned by the ls command displayed in some reasonable format or in other words in human readable presentation.

To display the file
sizes in units like 7K, 5M, 8.2G, etc… use the -lh option with  ls. 

ls -lh

command ls -lh

Note that -h is a GNU coreutils extension.

Read: How to find the size of a file or directory on Linux using du and ncdu commands

To display the sizes rounded up to the nearest MiB (2^20 bytes), you should use the command :

ls -l –block-size=M

command ls -l --block-size=M

Read: How to find the largest files on Linux

If the M suffix bothers you in some way, you can get rid of it by using –block-size=1M.

command ls -l --block-size=1M

file size linux

If however you want to see the size in MB (10^6 bytes) instead, you should use the command with the option –block-size=MB.

command ls -l --block-size=MB

To understand the differences between the units MiB and MB, have a look at the table below (courtesy majordifferences.com) :

differences between MB and MiB

For more on this, you may want to visit the man page for ls.
Simply type in man ls and look up the word SIZE. In case you are interested, you will find other units as well (besides MB/MiB).


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

amin nahdy

Amin Nahdy, an aspiring software engineer and a computer geek by nature as well as an avid Ubuntu and open source user. He is interested in information technology especially Linux based ecosystem as well as Windows and MacOS. He loves to share and disseminate knowledge to others in a transparent and responsible way.

This Post Has 5 Comments

  1. Fred

    Absolutely and utterly WRONG !

    Windows has NEVER EVER EVER, used IEC (Mebibyte etc) notation.
    Windows CORRECTLY reports filesizes as KB, MB, GB and TB etc ,always has and is one of the few current OSes that does.
    I guess it has to have something going for it, right ?

    In fact ALL computer Operating Systems used to, until fairly recently that is with this IEC standard rubbish with mebi, gibi, kibi nonsense creeping in.

    A Megabyte IS and ALWAYS WILL BE 1024KB
    1 KB = 1024 Bytes
    1 MB = 1024 x 1KB or 1024 x 1024 bytes
    1 GB = 1024 X 1MB or 1024 x 1024 x 1024 bytes
    so on and so forth and no sign of those stupid KiB, MiB, GiB things anywhere.

    It’s laughable (and very annoying) really that people who should know better are swallowing this garbage all to come in line with weights and measures ! ha !

    BTW I’ve been using computers for over 40 years so there’s a fair chance I know what I am talking about here.

  2. Fred

    @Net2
    Could your point be that some group (IEC) arbitrarily decided to TRY and change things to protect lying Hard disk manufacturers (as well as come in line with weights and measures) ?
    That article means nothing to me and doesn’t hold any information I didn’t already know.

    Look, I love using Linux but it has become infested with this nonsense but I am FORCED to show files with those ridiculous IEC labels so I can see the real size of my files as the ‘new’ MB, GB etc are NOT the REAL filesize.

    Back in the late 70s, 80s and 90s there was consensus as to names of filesizes, now, because of the stupid IEC and people that go along with them, it’s a complete dog’s breakfast !

    I see MiB and I say Megabyte and I will ’til the day I die.

  3. Varge

    I’m going to have to agree with Fred. 1 kB = 1024 B. That’s a lower case k. Never use a upper case k when writing, km, kL, k$, ky, kg, ks and so on. When talking about temperature, if you want to use Kelvin, never put a ° symbol. For example, 298 K.
    Back to computers. There is no confusion at all. I am not confused. 1 kB = 1024 B. 1 MB = 1024 * 1024 B.
    When I write software, that is the standard that I use.

    That is the standard used on Intel and AMD’s websites. Look at their cache sizes. That is the standard used in computer science. I am not interested in how hard disk manufacturers are confused.

  4. Dmitry

    I’m sorry to tell you this, but considerable chunk of information above (in both post and comments) looks completely wrong to me. Here is the official Ubuntu Units Policy: https://wiki.ubuntu.com/UnitsPolicy Hopefully it can remove the confusion. Unfortunately Ubuntu doesn’t always follow the policy. For instance network bandwidth is supposed to be measured in base-10, but System Monitor shows it in base-2. It’s the reason I got to this page to see if there’s some hidden system property to switch to SI units. I don’t see any so far anywhere.

Leave a Reply