Shell Prompt

  1. username@machinename:current_working_directory[$|#]
  2. ronnie@ubuntu:/home/ronnie$
  3. root@ubuntu:/home/ronnie# The terminal session has superuser privileges

This is called a shell prompt , and it will appear whenever the shell is ready to accept input.

Command Line Editing

Action Type Key Action
Cursor Movement CTRL + A 光标移到行首
CTRL + E 光标移到行尾
CTRL + F Move cursor forward one character; same as the right arrow key.
CTRL + B Move cursor backward one character; same as the left arrow key.
ALT + F Move cursor forward one word.
ALT + B Move cursor backward one word.
Modify Text CTRL + D Delete the character at the cursor location.
CTRL + T Transpose (exchange) the character at the cursor location with the one preceding it.
ATL + T Transpose the word at the cursor location with the one preceding it.
ATL + L Convert the characters from the cursor location to the end of the word
to lowercase.
ATL + U Convert the characters from the cursor location to the end of the word
to uppercase.
Cutting and Pasting (Killing and Yanking) Text CTRL + K Kill text from the cursor location to the end of line.
CTRL + U Kill text from the cursor location to the beginning of the line.
ALT + D Kill text from the cursor location to the end of the current word.
ALT + BACKSPACE Kill text from the cursor location to the beginning of the current word. If
the cursor is at the beginning of a word, kill the previous word.
CTRL + Y Yank text from the kill-ring and insert it at the cursor location.
Other CTRL + R reverse-i-search
CTRL + L clear screen

Completion

Usage Type Description


Press TAB
commands 自动完成命令名,当是第一个单词时。
pathnames 自动完成路径名、文件名,当出现在命令的参数中时。
variables 自动完成环境变量,当首字母是 $ 时。
usernames 自动完成用户名,当首字母是 ~ 时。
hosts 自动完成包含在 /etc/hosts 里的主机名,当首字母是 @ 时。
Key Action
ALT + ?
or
Display a list of possible completions.
ALT + * Insert all possible completions. This is useful when you want to use more than one possible match.

Using History

HISTSIZE

  • $ vim ~/.bashrc
    • HISTSIZE=1000

      Searching History

      $ history

  1. $ cat ~/.bash_history 所有的命令行历史都记录在 .bash_history 文件里
  2. $ history | less
  3. $ history | grep /usr/bin
  4. $ !88 执行命令行历史中第 88 行的命令

    Reverse Incremental Search

    | Usage | Key | Action | | :—-: | :—-: | :—-: | | Press CTRL + R | Type texts | Incrementally search hisotry commands. | | | CTRL + J
    or
    Press ENTER | Copy the line from the history list to the current command line. | | | CTRL - G
    or
    CTRL - C | Quit searching. |

More History Commands

Key Action
ctrl-P Move to the previous history entry. This is the same action as the up arrow.
ctrl-N Move to the next history entry. This is the same action as the down arrow.
alt-< Move to the beginning (top) of the history list.
alt-> Move to the end (bottom) of the history list, i.e., the current command line.
ctrl-R Reverse incremental search. This searches incrementally from the current command line up the history list.
alt-P Reverse search, nonincremental. With this key, type in the search string and press enter before the search is performed.
alt-N Forward search, nonincremental.
ctrl-O Execute the current item in the history list and advance to the next one. This is handy if you are trying to re-execute a sequence of commands in the history list.

History Expansion

Sequence Action
!! Repeat the last command. It is probably easier to press the up arrow and enter.
!number Repeat history list item number.
!string Repeat last history list item starting with string.
!?string Repeat last history list item containing string.

The “HISTORY EXPANSION” section of the bash man page goes into all the gory details.

chroot

临时把当前环境的 root 地址指向另一个地址;
可供测试脚本使用。