7

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?

Pierre B
  • 2,143
  • 6
  • 23
  • 38
  • My guess is the one's that don't use hyphens for arguments were written by non-conformists that wanted to make things difficult. However you would likely have to ask the author of each program to find out why they did it that way. – jesse_b Sep 23 '17 at 23:37
  • @Jesse_b Nope, it's AT&T vs BSD vs the world; see my answer. – Aaron D. Marasco Sep 23 '17 at 23:58
  • @AaronD.Marasco, I read Unix Wars and still stand by my statement. :) – jesse_b Sep 24 '17 at 00:32
  • Related: [What’s the difference between a flag, an option, and an argument?](https://unix.stackexchange.com/q/285575/80216)  and  [Unix-, BSD-, GNU-options in Linux’s ```ps``` command. Where are they from?](https://unix.stackexchange.com/q/78691/80216) – G-Man Says 'Reinstate Monica' Sep 24 '17 at 00:42
  • 1
    Possible duplicate of [The different ways of passing the arguments to console applications](https://unix.stackexchange.com/questions/128778/the-different-ways-of-passing-the-arguments-to-console-applications) – Jeff Schaller Sep 24 '17 at 00:42
  • Who would be doing this unification, how would they get everyone to agree on it, and what would be the benefit? (p.s. why does Spanish have irregular verbs, shouldn't someone unify the language?) – thrig Sep 24 '17 at 01:35
  • Related: [Why does my ls --help not work?](//unix.stackexchange.com/a/224451) – Stéphane Chazelas Sep 24 '17 at 08:33

2 Answers2

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.

Aaron D. Marasco
  • 5,708
  • 24
  • 29
  • I see the historical reasons, but why not unify all syntax? – Pierre B Sep 24 '17 at 01:25
  • 2
    @PierreB As stated in [The Open Group Base Specifications Issue 7 Vol. 1 Chapter 12](http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html): "some historical utilities could not be changed (to avoid breaking existing applications)". – nxnev Sep 24 '17 at 02:53
  • 1
    Because change for the sake of change rarely works out. Also: it is a breaking change. – John Keates Sep 24 '17 at 02: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
3

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.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936