命令行操作小技巧

Table of Contents

1 Aerial View

moving_cli.png

2 Bash shortcuts

Command Description
Ctrl + a To the beginning of the line
Ctrl + e To the end of the line
Alt + b One word back
Alt + f One word forward
Ctrl + k Delete to the end of the line
Ctrl + u Delete to the beginning of the line
Alt + d Delete to the end of the word
Ctrl + w Delete to the beginning of the word
Ctrl + p Previous command or arrow up
Ctrl + n Next command or arrow down
Ctrl + r Search history (fzf is a good, 3rd party alternative)
Ctrl + u Remove line
Ctrl + l Clear screen
Ctrl + b Move back one character
Ctrl + f Move forward one character
Ctrl + d Delete current character
Ctrl + - Undo
Ctrl + y Paste the last cut

3 Others

  • z is a good util to jump around folders.
  • jq is a fast and flexible command line JSON processor.
  • httpie is a fancy cURL alternative.
  • ExplainShell is great website to explain how a command or chain of commands work.
  • The Art of Command Line
  • pbcopy & pbpaste

4 magic

  • ! 加id可以直接复用改id之前的输入
  • !$ 也可以先按esc 然后按点 . 会自动出来,重复上面输入的最后一段参数。 Alt + dot 同时按也是同样的操作
  • !! 重复上面输入的整行. Control + p 也可以达到同样的效果
  • !* 将除了第一个单词后面的所有参数打印出来
  • !c 搜索历史中以c开头的字符输入