8

The usual ls command can display the size of files with the option -h and I am having a little doubt about it being display in MB or MIB.

For example :

$ ls -lha
drwxr-xr-x 2 user group 4.0K Apr  2 21:49 . 
drwxr-xr-x 5 user group 4.0K Apr  2 21:49 ..
-rw-r--r-- 1 user group 129M Apr  2 21:49 2018-04-02T21:49:08.981976.hdf5

So, this leaves me with 2 questions :

  • Does ls -lha displayed the size in MB or MiB?
  • Is it consistent across Unix-based operating systems and their own versions over time?

N.B.: Not only commercial Unix-based operating systems should be considered for this question.

Paradox
  • 1,425
  • 1
    I am not asking about the meaning but a subtle difference (which stay "blurry" in these answers's posts) in one option of this command, not to mention whether if this option display is consistent across OSs. – Paradox Apr 02 '18 at 20:41
  • 1
    None of the Q&As pointed to by don_crissti actually answers this question, which is not what the option does, but whether the units are consistent across all implementations and what they are. – JdeBP Apr 03 '18 at 06:21
  • I don't understand. Doesn't this answer from the duplicate answer your question about the units? If you are primarily interested in whether -h is portable (it isn't), then please [edit] your question to reflect that. Editing will also put it into the reopen review queue. – terdon Apr 04 '18 at 09:47
  • It doesn't, terdon. The giveaway is it talking about a --si option as if that were a universal, and it speaking of "the" ls manual (a familiar turn of phrase). Two non-GNU ls programs with -h options, completely unaddressed by answers here or there, have already been mentioned in comments on this very page. – JdeBP Apr 04 '18 at 19:23
  • 2
    @JdeBP the question of what the -h flag does in GNU ls, which actually has it, has been adequately answered by the dupe. I don't know how these ls you mention should be "addressed", we can't give a list of all ls implementations, that would be off topic. Paradox, again, please edit your question and clarify what you're asking. The -h option is not standard so yes, it can behave differently or be absent or do something completely different if the authors of an implementation choose it. – terdon Apr 05 '18 at 08:18
  • 1
    Addressing the other ls implementations that exist apart from the GNU one is off-topic? I strongly dispute that. This is Unix and Linux Stack Exchange, not GNU Stack Exchange. – JdeBP Apr 05 '18 at 19:12
  • 1
    @JdeBP of course non-GNU is 100% on topic! What is off topic is asking or providing a long list that attempts to cover all current and past implementations of ls in the *nix world. If Paradox would only edit the question to make it ask something that is specific and answerable about the portability of -h, then it would absolutely be on topic. But asking for the existence and behavior of the -h flag on every ls in existence is just too broad for this site. – terdon Apr 06 '18 at 10:24

1 Answers1

10

From the ls manpage:

-h, --human-readable
         with -l and -s, print sizes like 1K 234M 2G etc.
--si   likewise, but use powers of 1000 not 1024

So if you just use -h you will get MiB (^1024). If you add --si to the options, it will use MB (^1000). Verified on ubuntu, debian, and redhat. I don't have access to any commercial UNIX operating systems at the moment, but out of the box they tend not to include a -h option.

  • "but out of the box they tend not to include a -h option" From my experience, it is exactly the opposite (Fedora, Manjaro, Debian, Ubuntu and Scientific Linux) ; maybe you meant something else? – Paradox Apr 02 '18 at 20:43
  • None of those are commercial Unices. Although M. McMahon could at least have looked at the BSDs. – JdeBP Apr 02 '18 at 20:51
  • @JdeBP This option was available on the version of RHEL 6/7 I had been using in the past. (BTW Scientific Linux is based on it). But, still, I do not see the point : are "commercial Unices" universally lacking this option? – Paradox Apr 02 '18 at 20:57
  • Solaris has it, not AIX or HPUX. I recall answering this, but don't see it readily. – Thomas Dickey Apr 02 '18 at 21:26
  • 1
    @ThomasDickey - https://unix.stackexchange.com/a/302681/22142 – don_crissti Apr 02 '18 at 21:32
  • @Paradox none of the systems you have mentioned are Unix, commercial or otherwise. The -h option is not POSIX so you cannot depend on its working anywhere. GNU ls has it, yes, so any Linux system will have it, but Unices can do as they wish. – terdon Apr 04 '18 at 09:50