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?
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?
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.
ps aux
for over twenty years and I don't want to change. ;)
– Aaron D. Marasco
Sep 24 '17 at 12:06
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 thekey
argument. Thekey
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.
ps
command. Where are they from? – G-Man Says 'Reinstate Monica' Sep 24 '17 at 00:42