Blog 已遷移 http://steventtud.com,logdown 版本不再更新,麻煩大家前往新網站觀看^^

EDX Linux Foundation Ch 9:User Environment Section 3 Recalling Previous Commands &4 Command Aliases

Section 3:Recalling Previous Commands

Up and Down

you can recall previously used commands simply by using the Up and Down cursor keys.

histroy

To view the list of previously executed commands, you can just type history at the command line.

~/.bash_history.

The list of commands is displayed with the most recent command appearing last in the list. This information is stored in ~/.bash_history.

Using History Environment Variables

$HISTFILE stores the location of the history file.
$HISTFILESIZE stores the maximum number of lines in the history file.
$HISTSIZE stores the maximum number of lines in the history file for the current session.

ubuntu@ip-172-31-27-94:~$ echo $HISTFILE
/home/ubuntu/.bash_history
ubuntu@ip-172-31-27-94:~$ echo $HISTFILESIZE
2000
ubuntu@ip-172-31-27-94:~$ echo $HISTSIZE
1000
ubuntu@ip-172-31-27-94:~$

Finding and Using Previous Commands

Up/Down arrow key

Browse through the list of commands previously executed

!! (Pronounced as bang-bang)

Execute the previous command

CTRL-R

Search previously used commands

Executing Previous Commands

Section 4:Command Aliases

Creating Aliases

You can create customized commands or modify the behavior of already existing ones by creating aliases. Most often these aliases are placed in your ~/.bashrc file so they are available to any command shells you create.

alias

列出所有的縮寫(alias)

alias 縮寫='指令'

設定新的縮寫

範例: