linux命令行usage格式解释

点击量:5010

经常要在Linux下面敲指令,但指令太多很多是忘了记,记了又忘。其实这些指令不用一个一个去记,每一个命令都会有帮助和提示。之前我一看到这些提示就头大,什么方括号,尖括号,省略号,杠之类的,今天静下心来专门学习这个东西,了解完之后发现还是比较简单的,这样遇到新的命令自己学习一下就知道如何使用了,不用再去一个一个查询和记忆了。

帮助的格式一般分以下几种:

方括号[]:表示可选参数,也就是说可以忽略,使用时没有方括号。

尖括号<>:表示必选参数,不能忽略,且尖括号里的输入只能是指定的option,使用时没有尖括号。

省略号…:表示重复多次的参数。

接下来我们以jstat为例,学习如何通过以上几个格式的含义一步步来学习使用一个新的指令。jstat是JDK下面一个用于监控JVM内存使用情况的轻量级工具,我们在命令行下面输入jstat时会输出以下信息,我们一行一行看。

[astd@VM_139_5_tlinux ~]$ jstat
invalid argument count【1】
Usage: jstat -help|-options【2】
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]【3】

Definitions:【4】
<option> An option reported by the -options option【5】
<vmid> Virtual Machine Identifier. A vmid takes the following form:<lvmid>[@<hostname>[:<port>]] Where <lvmid> is the local vm identifier for the target Java virtual machine, typically a process id; <hostname> is the name of the host running the target Java virtual machine;and <port> is the port number for the rmiregistry on the target host. See the jvmstat documentation for a more complete description of the Virtual Machine Identifier.【6】
<lines> Number of samples between header lines.【7】
<interval> Sampling interval. The following forms are allowed:<n>[“ms”|”s”]【8】
Where <n> is an integer and the suffix specifies the units as milliseconds(“ms”) or seconds(“s”). The default units are “ms”.【9】
<count> Number of samples to take before terminating.【10】
-J<flag> Pass <flag> directly to the runtime system.【11】

【1】:告诉你count这个参数不合法

【2】:使用方法是jstat -help 或者jstat-options。

【3】:这个就是这个指令具体的格式了,jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]。首先必须有参数-<option>,这里的option的值在【5】中有了说明,即通过jstat -options获得。接下来是一个可选参数-t,没有说明,试了一下发现是在输出的头部显示时间戳。然后是可选参数-h<lines>,【7】对这个有解释:字面很难翻译准确,等会儿用例子解释下就明白了。接下来是一个必选参数<vmid>虚拟机的id,最常见的是进程号也就是pid。然后是可选参数[<interval> [<count>]],interval是监控刷新的时间间隔,该参数后还可以接m/ms,表示时间的单位是秒或者毫秒,count则是显示的数量。一个看似很复杂的指令就这样解析完了,挺简单的吧。

我们用几个组合试试吧。

jstat -options

jstat -gcutil  18064 1000 10000

jstat -gcutil  -h2 18064 1000 10000

jstat -gcutil -t -h2 18064 1000 10000

$ jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcpermcapacity
-gcutil
-printcompilation

$ jstat -gcutil 18064 1000 10000
S0 S1 E O P YGC YGCT FGC FGCT GCT
1.08 0.00 69.12 92.86 55.28 88136 827.589 11692 1777.799 2605.388
1.08 0.00 71.55 92.86 55.28 88136 827.589 11692 1777.799 2605.388
1.08 0.00 72.24 92.86 55.28 88136 827.589 11692 1777.799 2605.388

$ jstat -gcutil -h2 18064 1000 10000
S0 S1 E O P YGC YGCT FGC FGCT GCT
0.85 0.00 41.33 92.86 55.28 88138 827.610 11710 1780.803 2608.412
0.85 0.00 43.97 92.86 55.28 88138 827.610 11710 1780.803 2608.412
S0 S1 E O P YGC YGCT FGC FGCT GCT
0.85 0.00 44.60 92.86 55.28 88138 827.610 11710 1780.803 2608.412
0.85 0.00 47.03 92.86 55.28 88138 827.610 11710 1780.803 2608.412

$ jstat -gcutil -t -h2 18064 1000 10000
Timestamp S0 S1 E O P YGC YGCT FGC FGCT GCT
1982902.1 0.00 1.12 65.73 92.86 55.28 88137 827.601 11702 1779.541 2607.141
1982903.1 0.00 1.12 67.50 92.86 55.28 88137 827.601 11702 1779.541 2607.141
Timestamp S0 S1 E O P YGC YGCT FGC FGCT GCT
1982904.1 0.00 1.12 68.95 92.86 55.28 88137 827.601 11702 1779.541 2607.141
1982905.1 0.00 1.12 70.66 92.86 55.28 88137 827.601 11702 1779.541 2607.141
Timestamp S0 S1 E O P YGC YGCT FGC FGCT GCT
1982906.1 0.00 1.12 72.14 92.86 55.28 88137 827.601 11702 1779.541 2607.141
1982907.1 0.00 1.12 73.99 92.86 55.28 88137 827.601 11702 1779.541 2607.141

 

     

原创不易,如果您觉得本文对您有帮助,可以打赏博主一杯咖啡,鼓励博主持续创作!


  • Ethereum/Polygon/Bsc/Arbitrum: 0xa8c00949fd7dD23b5Ec36A9181966c8C8436A015
  • Bitcoin: bc1qdvf0j0rntarvdal62n35etwmjzwk307w4jtyjz
  •    
  • 支付宝:

  • 发表评论

    邮箱地址不会被公开。 必填项已用*标注