5

Why are some commands (among Linux users) run with hyphens and others not?

For examples, ls -l or rm -r contrasting to ps ax or tar xvf?

I see it has historical reasons, but they mean the same, why weren't they unified?

7
9

For this, you need to go way back in the history of *nix, when you had many flavors of unices. ps is especially hairy, because it has totally different options if you use the - (POSIX/Unix style) or without (BSD). Unix Wars is a useful Wikipedia page to start reading about it.

Edit: History of Unix might interest you as well.

4
  • I see the historical reasons, but why not unify all syntax? – Pierre B Sep 24 '17 at 1:25
  • 2
    @PierreB As stated in The Open Group Base Specifications Issue 7 Vol. 1 Chapter 12: "some historical utilities could not be changed (to avoid breaking existing applications)". – nxnev Sep 24 '17 at 2:53
  • 1
    Because change for the sake of change rarely works out. Also: it is a breaking change. – John Keates Sep 24 '17 at 2:54
  • 1
    @PierreB because I've been typing ps aux for over twenty years and I don't want to change. ;) – Aaron D. Marasco Sep 24 '17 at 12:06
2

The command line option without dashes, as found with e.g. tar, dd and ps are older style command line flags that can't be removed due to too many applications depending on them.

The OpenBSD manual for tar calls the old-style option "legacy" options, but I'm pretty sure I've seen the name "packed options" or "binned options" (or something like that) to describe this older syntax.

dd inherited it's non-dashed options from the Job Control Language (JCL) on IBM mainframes.

Some of these utilities also accept dashed options, and the POSIX specification for ps does not mention the old-style options at all. The specification of dd lists "operands" rather than "options", and tar is not standardised by POSIX at all (the standard archiver is pax).

Note also that newer utilities also uses non-dashed options (or rather, operands) to determine what action to take. You will find these in e.g. git commit -p, and lxc exec etc.

This is actually rather similar to the "action" of tar. From the original tar manual in Unix Release 7:

tar saves and restores files on magtape. Its actions are controlled by the key argument. The key is a string of characters containing at most one function letter and possibly one or more function modifiers.

The original implementation of ps in Unix Release 3 had dashed options (note that the manual section here is 8 rather than 1, i.e. in the section for administrative utilities). In the next release, it had lost them.


Note: I'm mixing the terminology for "option" and "operand" throughout. An "option" is technically a dashed single letter or character, e.g. -a, while an "operand" is a non-option. Both are command line arguments though.

Not the answer you're looking for? Browse other questions tagged or ask your own question.