鍍金池/ 教程/ Linux/ 命名別名與歷史命令
Linux 學(xué)習(xí)記錄--開(kāi)機(jī)掛載錯(cuò)誤
日志系統(tǒng)
數(shù)據(jù)流重定向
內(nèi)存交換空間的構(gòu)建
文件系統(tǒng)簡(jiǎn)介
Linux 學(xué)習(xí)記錄--軟件安裝 RPM|SRPM|YUM
文件特殊權(quán)限
目錄配置 FHS
文件內(nèi)容查閱
Boot Loader
文件壓縮
Linux 學(xué)習(xí)記錄--文件權(quán)限
Linux 命令縮寫(xiě)
命令與文件的查詢
文件|目錄的默認(rèn)權(quán)限與隱藏權(quán)限
shell script
服務(wù)
Linux 學(xué)習(xí)記錄--程序編譯與函數(shù)庫(kù)
正則表達(dá)式與其應(yīng)用
關(guān)機(jī)相關(guān)指令
shell
vim 與 vi 常用命令
系統(tǒng)調(diào)用:進(jìn)程控制
文件系統(tǒng)簡(jiǎn)單操作
磁盤(pán)掛載與卸載
有名管道通訊
磁盤(pán)分區(qū),格式化與檢驗(yàn)
工作管理與進(jìn)程管理
匿名管道通訊
Linux 學(xué)習(xí)記錄--啟動(dòng)流程
文件與目錄管理
管道命令
命名別名與歷史命令
文件備份|還原
shell變量
Linux 學(xué)習(xí)記錄--ACL 權(quán)限控制
內(nèi)核|內(nèi)核模塊編譯
文件管理相關(guān)系統(tǒng)編程

命名別名與歷史命令

命名別名

語(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

使用歷史命令執(zhí)行命令

語(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'