0

Is there any reason that someone would use ls -a over using ls -A? That is, can . or .. ever show anything useful? I used to use -a only because I didn't know that -A was the same thing but without the . and ... Which brings me back to my question: does -a ever show anything non-trivial about . or .. that someone might want to see?

David542
  • 339
  • Are other options allowed? E.g. -l? – Kamil Maciorowski Jun 28 '21 at 21:35
  • 2
    -al is pretty useful to see permissions on the current and parent directory – Panki Jun 28 '21 at 21:41
  • @KamilMaciorowski sure, I think I always use ls -Al by default now. – David542 Jun 28 '21 at 21:43
  • Since every directory has a "." (pointer to the directory) and ".." (pointer to parent directory), some users of -a complained that they were redundant. Eventually, the ls development team added "-A". Looking at . and .. modification times might have some use. – waltinator Jun 28 '21 at 22:26
  • To me personally, ls -a has the considerable advantage of not needing the shift key. – berndbausch Jun 28 '21 at 22:31
  • The exact question asked, "is there any reason": Yes. As other comments said, sometimes seeing the permissions, timestamps, ownership, etc, is desired, and "." provides a quick and simple way to do so. (There are other ways to do so, as well--but historically, ls "has always been here, and probably always will be", while other ways may be newer.) – C. M. Jun 29 '21 at 00:56

3 Answers3

2

Initially, ls only supported -a, already there in the very first version of Unix in the early 70s.

A -A option was added to BSD ls in the late 70s (though not documented until the late 80s), for the very reason that ls -a listing . or .. is rarely useful. The GNU implementation of ls from the early 90s had it from the start (also called --almost-all there).

POSIX in its 2008 edition eventually specified that option so it eventually made it to most other ls implementations. But by that time most people were already used to typing ls -a.

ls -a can be sometimes useful in ls -la when you want to check the permissions, modification time, etc of the current and parent directory in addition to those of the files in the directory.

Note that while POSIX requires the dir/. and dir/.. paths to resolve to dir and its parent respectively (and . and .. to the current working directory and its parent), it doesn't require readdir() to return the . and .. entries, nor that those . and .. be implemented as actual directory entries as they were in the original versions of Unix. So you can find systems where ls -a does not report . nor ... On Linux, . and .. are not stored as directory entries in several filesystems, but readdir() (well, the getdents() system call underneath) does still fake them when that's the case.

A related (and much worse) issue is some shells including . and .. in the expansion of .*. That's the reason rm -rf . and rm -rf .. fails for instance as a safeguard against that misfeature of those shells.

0

According to the man page for ls, there's not much of a difference.

       -a, --all
              do not ignore entries starting with .
   -A, --almost-all
          do not list implied . and ..

-A will list all entries beginning with a ., but omit the entries . and ...

0

The only advantage I can see is the number of links in current directory and parent directory. This can give you information about the number of subdirectories in the parent directory or the current directory.

unxnut
  • 6,008