You can’t say that. In fact, the example you used is rather special. Among the options of the tar command - it can be written or not. If not used - the effect will be the same. However, it is still recommended to use -, after all, there are many specifications.
Let me show you an example where - cannot be ignored [ioitboy@linux ~]$ ls -ld / dr-xr-xr-x. 17 root root 4096 Jul 25 12:29 / [ioitboy@linux ~]$ ls ld / ls: cannot access ld: No such file or directory /: bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
//The first command using - was executed successfully, but we found that the execution result of the second command was completely different and there was an error. 1, because - is not written, bash interprets ld as a file or directory and gives an error. 2, because - was not written, so bash did not get the request to use the -ld option. The output of ls / is given directly without listing the / directory information.
Finally, it is recommended to read more about man and --help. Learning the standardized command writing method can avoid some unexpected execution results.
I don’t know much about the origin of the ps command, but you can take a look at the command line option parsing principle. Those with - are UNIX style, those without are BSD style, and there are also GNU styles, etc. wait. . You can simply understand the getopt and getopt_long functions. These two functions support UNIX style
You can’t say that. In fact, the example you used is rather special.
Among the options of the tar command - it can be written or not. If not used - the effect will be the same. However, it is still recommended to use -, after all, there are many specifications.
Let me show you an example where - cannot be ignored
[ioitboy@linux ~]$ ls -ld /
dr-xr-xr-x. 17 root root 4096 Jul 25 12:29 /
[ioitboy@linux ~]$ ls ld /
ls: cannot access ld: No such file or directory
/:
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
//The first command using - was executed successfully, but we found that the execution result of the second command was completely different and there was an error.
1, because - is not written, bash interprets ld as a file or directory and gives an error.
2, because - was not written, so bash did not get the request to use the -ld option. The output of ls / is given directly without listing the / directory information.
Finally, it is recommended to read more about man and --help. Learning the standardized command writing method can avoid some unexpected execution results.
The bad thing is the writing method of bsd, such as ps aux, you can write it like this because ps is ported from bsd
I don’t know much about the origin of the
ps
command, but you can take a look at the command line option parsing principle.Those with
-
are UNIX style, those without are BSD style, and there are also GNU styles, etc. wait. .You can simply understand the
getopt
andgetopt_long
functions. These two functions support UNIX styleI think this is a special case. Try other commands.
It can only be said that some can be omitted, such as the tar command, but some cannot be omitted. This mainly depends on the style of the command.