• 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.
  • 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 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.
[ad type=”banner”]

Maybe -h is sufficient for you:

[pastacode lang=”bash” manual=”%20%20-h%20%0A” message=”Bash Code” highlight=”” provider=”manual”/]

When used with the -l option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to three or less using base 2 for sizes.

[pastacode lang=”bash” manual=”ls%20-lah%0A” message=”Bash Code” highlight=”” provider=”manual”/] [ad type=”banner”]

Use man commandname to read the manual of a certain commend, e.g. here man ls.

Categorized in: