How to display files sizes in MB in Linux/Ubuntu

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.

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 3 Comments

  1. 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. @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.

Leave a Reply

Close Menu