Arthas keymap 命令教程 (#1318)

* add keymap command scenario. #847

Signed-off-by: hollowman6 <hollowman186@vip.qq.com>

* fix link typo

Signed-off-by: hollowman6 <hollowman186@vip.qq.com>

* remove additional link

Signed-off-by: hollowman6 <hollowman186@vip.qq.com>

* polish 'Custom shortcuts'

Signed-off-by: hollowman6 <hollowman186@vip.qq.com>

* polish kaymap command scenario. #847

Signed-off-by: hollowman6 <hollowman186@vip.qq.com>

* fix mistake

Signed-off-by: hollowman6 <hollowman186@vip.qq.com>
This commit is contained in:
Hollow Man
2020-07-23 16:21:07 +08:00
committed by GitHub
parent 0da415f0ce
commit d5fa0d037f
20 changed files with 382 additions and 0 deletions
+2
View File
@@ -1,6 +1,8 @@
Arthas Console Keymap
===
[`keymap` online tutorial](https://alibaba.github.io/arthas/arthas-tutorials?language=en&id=command-keymap)
Use `keymap` command to print the current keymap:
The default keymap is:
+2
View File
@@ -1,6 +1,8 @@
Arthas 命令行快捷键
===
[`keymap`在线教程](https://alibaba.github.io/arthas/arthas-tutorials?language=cn&id=command-keymap)
`keymap`命令输出当前的快捷键映射表:
默认的快捷键如下:
@@ -0,0 +1,16 @@
在新的`Terminal 2`里,下载`arthas-boot.jar`,再用`java -jar`命令启动:
`wget https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar`{{execute T2}}
`arthas-boot``Arthas`的启动程序,它启动后,会列出所有的Java进程,用户可以选择需要诊断的目标进程。
选择第一个进程,输入 `1`{{execute T2}} ,再`Enter/回车`
Attach成功之后,会打印Arthas LOGO。输入 `help`{{execute T2}} 可以获取到更多的帮助信息。
![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png)
@@ -0,0 +1,10 @@
下载`arthas-demo.jar`,再用`java -jar`命令启动:
`wget https://alibaba.github.io/arthas/arthas-demo.jar
java -jar arthas-demo.jar`{{execute T1}}
`arthas-demo`是一个很简单的程序,它随机生成整数,再执行因式分解,把结果打印出来。如果生成的随机数是负数,则会打印提示信息。
@@ -0,0 +1,61 @@
首先退出Arthas, 在当前用户目录下新建`$USER_HOME/.arthas/conf/inputrc`文件,可加入自定义配置。
`exit`{{execute interrupt}}
`mkdir -p /root/.arthas/conf/`{{execute T2}}
假设我是vim的重度用户,我要把`ctrl+h`设置为光标向前一个字符,则首先拷贝默认配置:
```text
"\C-a": beginning-of-line
"\C-e": end-of-line
"\C-f": forward-word
"\C-b": backward-word
"\e[D": backward-char
"\e[C": forward-char
"\e[B": next-history
"\e[A": previous-history
"\C-h": backward-delete-char
"\C-?": backward-delete-char
"\C-u": undo
"\C-d": delete-char
"\C-k": kill-line
"\C-i": complete
"\C-j": accept-line
"\C-m": accept-line
"\C-w": backward-delete-word
"\C-x\e[3~": backward-kill-line
"\e\C-?": backward-kill-word
```
然后把`"\C-h": backward-delete-char`换成`"\C-h": backward-char`,修改后的keymap配置即以下内容:
`cat > /root/.arthas/conf/inputrc <<EOF
"\C-a": beginning-of-line
"\C-e": end-of-line
"\C-f": forward-word
"\C-b": backward-word
"\e[D": backward-char
"\e[C": forward-char
"\e[B": next-history
"\e[A": previous-history
"\C-h": backward-char
"\C-?": backward-delete-char
"\C-u": undo
"\C-d": delete-char
"\C-k": kill-line
"\C-i": complete
"\C-j": accept-line
"\C-m": accept-line
"\C-w": backward-delete-word
"\C-x\e[3~": backward-kill-line
"\e\C-?": backward-kill-word`{{execute T2}}
然后重新连接即可。
`java -jar arthas-boot.jar`{{execute interrupt}}
最后执行下面命令查看效果:
`keymap | grep C-h`{{execute T2}}
@@ -0,0 +1,26 @@
| 快捷键 | 快捷键说明 | 命令名称 | 命令说明 |
| ---- | ---- | ---- | ---- |
| `"\C-a"` | ctrl + a | beginning-of-line | 跳到行首 |
| `"\C-e"` | ctrl + e | end-of-line | 跳到行尾 |
| `"\C-f"` | ctrl + f | forward-word | 向前移动一个单词 |
| `"\C-b"` | ctrl + b | backward-word | 向后移动一个单词 |
| `"\e[D"` | 键盘左方向键 | backward-char | 光标向前移动一个字符 |
| `"\e[C"` | 键盘右方向键 | forward-char | 光标向后移动一个字符 |
| `"\e[B"` | 键盘下方向键 | next-history | 下翻显示下一个命令 |
| `"\e[A"` | 键盘上方向键 | previous-history | 上翻显示上一个命令 |
| `"\C-h"` | ctrl + h | backward-delete-char | 向后删除一个字符 |
| `"\C-?"` | ctrl + shift + / | backward-delete-char | 向后删除一个字符 |
| `"\C-u"` | ctrl + u | undo | 撤销上一个命令,相当于清空当前行 |
| `"\C-d"` | ctrl + d | delete-char | 删除当前光标到行尾的所有字符 |
| `"\C-k"` | ctrl + k | kill-line | 光标向前移动一个字符 |
| `"\C-i"` | ctrl + i | complete | 自动补全,相当于敲`TAB` |
| `"\C-j"` | ctrl + j | accept-line | 结束当前行,相当于敲回车 |
| `"\C-m"` | ctrl + m | accept-line | 结束当前行,相当于敲回车 |
| `"\C-w"` | | backward-delete-word | |
| `"\C-x\e[3~"` | | backward-kill-line | |
| `"\e\C-?"` | | backward-kill-word | |
任何时候使用 `tab`{{execute T2}}键,会根据当前的输入给出提示
命令后敲 `-``--` ,然后按 `tab` 键,可以展示出此命令具体的选项
@@ -0,0 +1,10 @@
通过本教程基本掌握了Arthas keymap的用法。更多高级特性,可以在下面的进阶指南里继续了解。
* [Arthas进阶](https://alibaba.github.io/arthas/arthas-tutorials?language=cn&id=arthas-advanced)
* [Arthas Github](https://github.com/alibaba/arthas)
* [Arthas 文档](https://alibaba.github.io/arthas/)
欢迎关注公众号,获取Arthas项目的信息,源码分析,案例实践。
![Arthas公众号](/arthas/scenarios/common-resources/assets/qrcode_gongzhonghao.jpg)
@@ -0,0 +1,45 @@
{
"title": "Arthas keymap命令教程",
"description": "Arthas keymap命令教程",
"details": {
"steps": [
{
"title": "启动arthas-demo",
"text": "arthas-demo.md"
},
{
"title": "启动arthas-boot",
"text": "arthas-boot.md"
},
{
"title": "keymap 命令",
"text": "keymap.md"
},
{
"title": "默认的快捷键",
"text": "default-keymap.md"
},
{
"title": "自定义快捷键",
"text": "custom-shortcuts.md"
},
{
"title": "后台异步命令相关快捷键",
"text": "shortcuts-for-jobs.md"
}
],
"intro": {
"text": "intro.md"
},
"finish": {
"text": "finish.md"
}
},
"environment": {
"uilayout": "terminal"
},
"backend": {
"imageid": "java",
"environmentsprotocol": "http"
}
}
@@ -0,0 +1,11 @@
![Arthas](https://alibaba.github.io/arthas/_images/arthas.png)
`Arthas` 是Alibaba开源的Java诊断工具,深受开发者喜爱。在线排查问题,无需重启;动态跟踪Java代码;实时监控JVM状态。
`Arthas` 支持JDK 6+,支持Linux/Mac/Windows,采用命令行交互模式,同时提供丰富的 `Tab` 自动补全功能,进一步方便进行问题的定位和诊断。
* Github: https://github.com/alibaba/arthas
* 文档: https://alibaba.github.io/arthas/
@@ -0,0 +1,4 @@
通过`kaymap`命令可以输出当前的快捷键映射表。
`keymap`{{execute T2}}
@@ -0,0 +1,8 @@
`ctrl + c`: 终止当前命令
`ctrl + z`: 挂起当前命令,后续可以 bg/fg 重新支持此命令,或 kill 掉
`ctrl + a`: 回到行首
`ctrl + e`: 回到行尾
@@ -0,0 +1,15 @@
In the new `Terminal 2`, download `arthas-boot.jar` and start with the `java -jar` command:
`wget https://alibaba.github.io/arthas/arthas-boot.jar
java -jar arthas-boot.jar`{{execute T2}}
`arthas-boot` is the launcher for `Arthas`. It lists all the Java processes, and the user can select the target process to be diagnosed.
Select the first process, type `1`{{execute T2}} then type `Enter`
After the Attach is successful, Arthas LOGO is printed. Enter `help`{{execute T2}} for more help.
![Arthas Boot](/arthas/scenarios/common-resources/assets/arthas-boot.png)
@@ -0,0 +1,11 @@
Download `arthas-demo.jar` and start with the `java -jar` command:
`wget https://alibaba.github.io/arthas/arthas-demo.jar
java -jar arthas-demo.jar`{{execute T1}}
`arthas-demo` is a very simple program that randomly generates integers, performs factorization, and prints the results.
If the generated random number is negative, a error message will be printed.
@@ -0,0 +1,61 @@
Specify customization in `$USER_HOME/.arthas/conf/inputrc` file in the current user home directory.
`exit`{{execute interrupt}}
`mkdir -p /root/.arthas/conf/`{{execute T2}}
The default configuration is as follows:
```text
"\C-a": beginning-of-line
"\C-e": end-of-line
"\C-f": forward-word
"\C-b": backward-word
"\e[D": backward-char
"\e[C": forward-char
"\e[B": next-history
"\e[A": previous-history
"\C-h": backward-delete-char
"\C-?": backward-delete-char
"\C-u": undo
"\C-d": delete-char
"\C-k": kill-line
"\C-i": complete
"\C-j": accept-line
"\C-m": accept-line
"\C-w": backward-delete-word
"\C-x\e[3~": backward-kill-line
"\e\C-?": backward-kill-word
```
Vim user may want to map `ctrl+h` to moving the cursor forward one character. To achieve this, replace `"\C-h": backward-delete-char` with `"\C-h": backward-char` in the default configuration. The modified configuration is as follows:
`cat > /root/.arthas/conf/inputrc <<EOF
"\C-a": beginning-of-line
"\C-e": end-of-line
"\C-f": forward-word
"\C-b": backward-word
"\e[D": backward-char
"\e[C": forward-char
"\e[B": next-history
"\e[A": previous-history
"\C-h": backward-char
"\C-?": backward-delete-char
"\C-u": undo
"\C-d": delete-char
"\C-k": kill-line
"\C-i": complete
"\C-j": accept-line
"\C-m": accept-line
"\C-w": backward-delete-word
"\C-x\e[3~": backward-kill-line
"\e\C-?": backward-kill-word`{{execute T2}}
Then reconnect to Arthas console to take effect.
`java -jar arthas-boot.jar`{{execute interrupt}}
Finally you can see the modification by executing
`keymap | grep C-h`{{execute T2}}
@@ -0,0 +1,26 @@
| Shortcut | Shortcut Description | Command Name | Command Description |
| ---- | ---- | ---- | ---- |
| `"\C-a"` | ctrl + a | beginning-of-line | go to the beginning of the line |
| `"\C-e"` | ctrl + e | end-of-line | go to the end of the line |
| `"\C-f"` | ctrl + f | forward-word | forward a word |
| `"\C-b"` | ctrl + b | backward-word | backward a word |
| `"\e[D"` | left arrow | backward-char | backward a character |
| `"\e[C"` | right arrow | forward-char | forward a character |
| `"\e[B"` | down arrow | next-history | show next history command |
| `"\e[A"` | up arrow | previous-history | show previous history command |
| `"\C-h"` | ctrl + h | backward-delete-char | backward delete a character |
| `"\C-?"` | ctrl + shift + / | backward-delete-char | backward delete a character |
| `"\C-u"` | ctrl + u | undo | clear current line |
| `"\C-d"` | ctrl + d | delete-char | delete the character of the current cursor |
| `"\C-k"` | ctrl + k | kill-line | delete all characters from the current cursor to the end of the line |
| `"\C-i"` | ctrl + i | complete | Auto completion, equivalent to `TAB` |
| `"\C-j"` | ctrl + j | accept-line | end the current line, equivalent to `enter` |
| `"\C-m"` | ctrl + m | accept-line | end the current line, equivalent to `enter` |
| `"\C-w"` | | backward-delete-word | |
| `"\C-x\e[3~"` | | backward-kill-line | |
| `"\e\C-?"` | | backward-kill-word | |
Press `tab`{{execute T2}} to enable auto-completion prompt at any time.
Enter command and `-` or `--`, then press `tab` to display the concrete options for the current command.
@@ -0,0 +1,6 @@
Through this tutorial, you can know how to use Arthas `keymap`. More advanced features can be found in the Advanced Guide below.
* [Arthas Advanced](https://alibaba.github.io/arthas/arthas-tutorials?language=en&id=arthas-advanced)
* [Arthas Github](https://github.com/alibaba/arthas)
* [Arthas Documentation](https://alibaba.github.io/arthas/en)
@@ -0,0 +1,45 @@
{
"title": "Arthas keymap",
"description": "Arthas keymap",
"details": {
"steps": [
{
"title": "Start arthas-demo",
"text": "arthas-demo.md"
},
{
"title": "Start arthas-boot",
"text": "arthas-boot.md"
},
{
"title": "keymap command",
"text": "keymap.md"
},
{
"title": "The default keymap",
"text": "default-keymap.md"
},
{
"title": "Custom shortcuts",
"text": "custom-shortcuts.md"
},
{
"title": "Shortcuts for jobs",
"text": "shortcuts-for-jobs.md"
}
],
"intro": {
"text": "intro.md"
},
"finish": {
"text": "finish.md"
}
},
"environment": {
"uilayout": "terminal"
},
"backend": {
"imageid": "java",
"environmentsprotocol": "http"
}
}
@@ -0,0 +1,11 @@
![Arthas](https://alibaba.github.io/arthas/_images/arthas.png)
`Arthas` is a Java diagnostic tool open-sourced by Alibaba middleware team. Arthas helps developers in trouble-shooting issues in production environment for Java based applications without modifying code or restarting servers.
`Arthas` supports JDK 6+, supports Linux/Mac/Windows.
* Github: https://github.com/alibaba/arthas
* Documentation: https://alibaba.github.io/arthas/en
@@ -0,0 +1,4 @@
`kaymap` can list all Arthas keyboard shortcuts and shortcut customizations.
`keymap`{{execute T2}}
@@ -0,0 +1,8 @@
`ctrl + c`: Terminate current command
`ctrl + z`: Suspend the current command, you can restore this command with bg/fg, or kill it.
`ctrl + a`: Go to the beginning the line
`ctrl + e`: Go to the end of the line