/bin/ls vs .dotted files

Chris Turner c.turner at 199technologies.com
Fri Sep 14 20:07:31 PDT 2012


This is most interesting.

On 09/14/12 09:30, Jeremy C. Reed wrote:
> The ls.c modified by Joy in 1977 included:
...
> See that -A didn't enable/disable but simply toggled the behavior.

... which defaulted to 'on' for superuser

> It didn't exist in the 6th or 7th editions (where the code was from).

... along with '-1 in a pipe' behavior, column formatting, etc.

> It was not documented until the code was replaced in 1989 and the
> behaviour changed.

... to being an 'on-only' flag

Digging further - it looks like the 'toggle' behavior was revoked
somewhere between 4.2 and 4.3BSD and not in 1989 as you suggest:

# grep sccs bin/ls.c
static char sccsid[] = "@(#)ls.c        5.6 (Berkeley) 5/12/86";
# sed -n -e '84,85p' -e '109,110p' bin/ls.c
         if (getuid() == 0)
                 Aflg++;
                 case 'A':
                         Aflg++; break;

So - if we take 4.2BSD as 'correct' w/r/t intent (which is reasonable) -
4.3BSD introduced a bug whereby '-A' does not disable for the root user.

Coincedentally, Solaris's /usr/ucb/ps looks to be based on 4.3 sources
and so also carries this 'cant disable -A for root' problem.

> I think the -A documentation regardless of version makes no sense.

True-

Indeed ls.u from 2BSD and ls.1 from 3BSD, 4.2BSD AND 4.3BSD make *0* mention
of -A at all.

So really - given this clarified context - it looks like '-I' is a hack
to fix a 'bug' introduced in 4.3BSD, likely because the 4.2BSD
version was not properly documented as something like:

"
      -A      Toggle listing of 'All' (hidden) files.
              Turns off this behavior for the superuser,
              and turns it on for unprivileged users.
"

.. and 'hidden' dot files are still not really documented and
probably should be.

So perhaps the best solution to allow historical 'root -A' behavior,
and also 'non-A' behavior for root, is to revert to the original 2BSD
behavior of  using -A as a toggle, fix the documentation bug, and advise
new users to read ls(1), glob(3), and find(1) if they are somehow
confused about *this* system not having the same userland as some
other system and are having difficulty with porting their shell
scripts.

Cheers,

- Chris



More information about the Users mailing list