It’s often helpful to view file sizes in a way that’s easy to understand, rather than just a raw number of bytes. This is what we call a “human-readable” format.
To display file sizes in common units like Kilobytes (KB), Megabytes (MB), or Gigabytes (GB), when using the `ls` command to list files in Linux, you would use the `-lh` option. The “l” gives you the long listing format, and the “h” makes the sizes human-readable.
ls -lh
It’s good to know that the `-h` option is part of the GNU coreutils, which are standard tools on most Linux systems.
Read: How to Check File and Directory Size in Linux: du and ncdu Guide
If you want to see file sizes rounded up to the nearest Mebibyte (MiB), which is a power of 2 (220 bytes), you can use the following command:
ls -l –block-size=M
Read: How to find the largest files on Linux
If you prefer not to see the “M” suffix, use `–block-size=1M` instead. This will show the size in the same units but without the letter.
To show sizes in Megabytes (MB), which are powers of 10 (106 bytes), use the `–block-size=MB` option.
It’s important to understand the difference between MiB (Mebibyte) and MB (Megabyte). The following table (from majordifferences.com) helps explain the distinction:
For a complete guide on the `ls` command and all its options related to file sizes, you can view the manual page. Open a terminal and type `man ls`, then search for the word “SIZE” to find relevant information. You’ll discover other units are available as well.
If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.