linux下好像命令-可以不写,譬如tar jxvf ...也可以tar -jxvf ?
ringa_lee
ringa_lee 2017-04-17 15:26:42
0
5
667

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

ringa_lee
ringa_lee

ringa_lee

reply all(5)
黄舟

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.

Peter_Zhu

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

Ty80

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

左手右手慢动作

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

Peter_Zhu

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!