search

Home  >  Q&A  >  body text

linux下好像命令-可以不写,譬如tar jxvf ...也可以tar -jxvf ?

linux下好像命令-可以不写,譬如tar jxvf ...也可以tar -jxvf ?

ringa_leeringa_lee2780 days ago689

reply all(5)I'll reply

  • 黄舟

    黄舟2017-04-17 15:28:42

    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.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 15:28:42

    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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 15:28:42

    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

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 15:28:42

    I think this is a special case. Try other commands.

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 15:28:42

    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.

    reply
    0
  • Cancelreply