1

There have been multiple questions asked about this, like Understanding ls output, What are columns in ls -la?, What does 'ls -la' do?, What do the fields in ls -al output mean?, etc..
I've also come across many other websites with articles attempting to explain it.

What every single one of them seems to have in common is that despite writing down the meaning of the columns, there are never any links/references to where they acquired that information in the first place. An answer in the third question links to the coreutils manual, but much like the manpage that still provides no clarification.

The aforementioned resources are incomplete, as I'm developing a driver and found out ls -l provides the major and minor number for block/character devices (which is different from the regular output for files or directories):
enter image description here
Here the major/minor numbers for the device are 1 and 3 respectively.
I only discovered this because someone mentioned it in an answer (unrelated question). Had I wanted to know what these numbers meant before, I probably wouldn't have been able to find out save for the unlikely event I stumbled on that answer. Or went looking in the source code.

It seems pretty weird for a tool that pretty much every single linux user uses, not to have any proper information available about it's output. So am I missing something? Where is it documented?

EDIT: Muru in the comments referred to yet another question How to find what the fields in ls -l mean - the suggested answers in that question mention mostly the manpages (one outright pastes it), which for GNU coreutils does not provide a complete answer (manpage makes no mention of major/minor device numbers). The BSD manpage does, but Stephen's answer of the posix standard is (I think) the most correct.

TrisT
  • 121
  • 3
  • Ah, pasted wrong link, should have been: https://unix.stackexchange.com/q/454891/70524 "If the file is a character special or block special file, the major and minor device numbers for the file are displayed in the size field. " – muru Mar 24 '24 at 09:18
  • @muru the linked bsd ls documentation in How to find what the fields in ls -l mean (your second link) does document it: If the file is a character special or block special file, the major and minor device numbers for the file are displayed in the size field.. I suppose that's the one question I didn't find before. But also I'm not on BSD, so I might have skipped it if I had. Only with the hindisght of now knowing it's POSIX would I have taken it to be a correct source. – TrisT Mar 24 '24 at 09:29
  • You're not writing code that parses the output of ls -l, are you? :) – Kaz Mar 24 '24 at 16:07
  • @Kaz no, and I'm pretty sure there's no environment where that would actually be simpler than using the provided APIs. I just thought it should be an easy answer to find, and my subbornness made me spend way too long trying. So I figured it would make a good SE question. – TrisT Mar 24 '24 at 20:00

2 Answers2

4

ls is specified by POSIX, that’s the common reference. The output formats are described in the “STDOUT” section.

Stephen Kitt
  • 434,908
  • For the record Unix v6 ls man page from 1975 correctly documented the size being replaced by maj,min for device files. It didn't in v4 (1973) but it's likely because it wasn't the case then. I've reported the doc bug to GNU coreutils. – Stéphane Chazelas Mar 24 '24 at 10:18
3

Yes, the fact that the size field is replaced by major, minor for device files as has been the case since at least Research Unix v5 in 1974 and documented there since at least Research Unix v6 (couldn't find a v5 man page) was not documented in the documentation of the GNU implementation of ls (now fixed following this bug report, thanks to you).

The POSIX specification of the ls utility which most ls implementations including GNU ls¹ do try to conform to does mention that the size is replaced by some implementation-defined [...] <device-info> information associated with the device in question, though in the case of GNU ls like in the original Unix implementation, that is always major, minor. Contrary to the original Unix implementation though, GNU ls guarantees that there be always at least one space in addition to the comma between major and minor device number².


¹ at least when in a POSIX environment like when the POSIXLY_CORRECT environment variable is set and none of the BLOCKSIZE, BLOCK_SIZE, LS_BLOCK_SIZE ones are, though none of those are relevant in this instance.

² that's also the case of several other ls implementations such as the ones from busybox or toybox also commonly found on Linux-based systems (and themselves not POSIX-compliant), but not all. The one from ast-open for instance never includes a space and 0-pads all numbers to a length of 3 (like 001,005) while some still space-pad them to a length of 3 resulting in a variable number of whitespace delimited fields ( 1, 5 vs 7,128 for instance). One of the many reasons why the output of ls -l cannot be parsed reliably nor portably.