語(yǔ)法:alias 別名=’命令’
unalias別名
alias 如后面什么也不跟。代表查詢所有別名命名信息
舉例1:查看所有別名
[root@localhost ~]# alias
alias cp='cp -i'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=tty'
alias ll='ls -l --color=tty'
alias ls='ls --color=tty'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
舉例2:設(shè)置別名
[root@localhost ~]# alias dir='cd'
[root@localhost ~]# dir /tmp
[root@localhost tmp]# [root@localhost tmp]#
舉例3:取消別名
[root@localhost tmp]# unalias dir
語(yǔ)法:history n
history [-c]
history [raw]histfiles
選項(xiàng)與參數(shù):
n:數(shù)字,列出最近 n 條命令
-c:將目前 shell 中所有歷史命令全部清除
-a:將目前新增的歷史命令添加到 histfiles,若沒(méi)有加 histfiles 則默認(rèn)添加到 ~/.bash_history
-r:將 histfiles 讀取到 這個(gè) shell 的記憶
-w:將目前的 history 記憶寫(xiě)入 histfiles 中
說(shuō)明:$HISTSIZE 記錄了 shell 以及文件中最大存儲(chǔ)歷史記錄數(shù)量
系統(tǒng)注銷時(shí)會(huì)將 bashshell 歷史記錄記錄到文件中~/.bash_history
舉例:
[root@localhost tmp]# history 3 =>查看歷史最近3條記錄
876 echo $HISTSIZE
877 history
878 history 3
[root@localhost tmp]# history –c =>清空 shell 中的歷史記錄
[root@localhost tmp]# history 4 =>以前的被清空 因此這里只能查詢到這1條
1 history 4
[root@localhost tmp]# history –w =>shell 中的歷史記錄寫(xiě)入文件
[root@localhost tmp]# vim ~/.bash_history
history 5
vim ~/.bash_history
history –w
語(yǔ)法:
!number:執(zhí)行第幾條命令
!command:由最近的命令向前搜索由 command 開(kāi)頭的命令
!!:執(zhí)行上一個(gè)命令
說(shuō)明:使用以上命令可以做好保密性,別人看到你的命令歷史記錄卻不能知道你的操作
舉例:
[root@localhost /]# history 5 =>先查詢歷史命令
16 cd /
17 history -a
18 vim ~/.bash_history
19 alias
20 history 5
[root@localhost /]# !19 =>執(zhí)行第19條命令
alias
alias cp='cp -i'
alias grep='grep --color=auto'
……
[root@localhost /]# !! =>執(zhí)行上一個(gè)命令
alias
alias cp='cp -i'
alias grep='grep --color=auto'
[root@localhost /]# !al =>執(zhí)行以 al 開(kāi)頭命令
alias
alias cp='cp -i'