Linux第一週學習筆記(13)linux
2.5.alias命令shell
alias命令:用來設置指令的別名。咱們能夠使用該命令能夠將一些較長的命令進行簡化。使用alias時,用戶必須使用單引號''
將原來的命令引發來,防止特殊字符致使錯誤。alias 編程
unalias命令:用來取消命令別名,是爲shell內建命令。若是須要取消任意一個命令別名,則使用該命令別名做爲指令的參數選項便可。若是使用-a
選項,則表示取消全部已經存在的命令別名。bash
daizhihong='ls -lha'(建立別名)ssh
unalias daizhihong(取消別名)ide
-----------------------------------------------------------------------------------------------------------------------------------------------------學習
查看全部命令的別名:spa
[root@daizhihong01 ~]# alias(查看全部命令的別名)code
alias cp='cp -i'orm
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
--------------------------------------------------------------------------------------------------------------------------------------------------------
建立定義別名:
[root@daizhihong01 ~]# daizhihong
-bash: daizhihong: 未找到命令
[root@daizhihong01 ~]# alias daizhihong='ls -lha'(建立別名)
[root@daizhihong01 ~]# daizhihong(運行「daizhihong」後執行結果爲「ls -lha」命令的執行結果)
總用量 28K
dr-xr-x---. 3 root root 147 1月 24 22:37 .
dr-xr-xr-x. 17 root root 265 1月 24 22:48 ..
-rw-------. 1 root root 1.4K 1月 22 08:19 anaconda-ks.cfg
-rw-------. 1 root root 935 1月 26 05:47 .bash_history
-rw-r--r--. 1 root root 18 12月 29 2013 .bash_logout
-rw-r--r--. 1 root root 176 12月 29 2013 .bash_profile
-rw-r--r--. 1 root root 176 12月 29 2013 .bashrc
-rw-r--r--. 1 root root 100 12月 29 2013 .cshrc
drwx------. 2 root root 48 1月 26 04:29 .ssh
-rw-r--r--. 1 root root 129 12月 29 2013 .tcshrc
[root@daizhihong01 ~]# which daizhihong
alias daizhihong='ls -lha'
/usr/bin/ls
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
取消別名:
[root@daizhihong01 ~]# unalias daizhihong(取消別名)
[root@daizhihong01 ~]# daizhihong
-bash: daizhihong: 未找到命令
---------------------------------------------------------------------------------------------------------------------------------
Which命令:用於查找並顯示給定命令的絕對路徑,環境變量PATH中保存了查找命令時須要遍歷的目錄。which指令會在環境變量$PATH設置的目錄裏查找符合條件的文件。也就是說,使用which命令,就能夠看到某個系統命令是否存在,以及執行的究竟是哪個位置的命令。
[root@daizhihong01 ~]# which ls
alias ls='ls --color=auto'
/usr/bin/ls
[root@daizhihong01 ~]# which ll
alias ll='ls -l --color=auto'
/usr/bin/ls
PATH:系統環境變量就是一個別名路徑,若是一個命令在這個目錄下面,直接運行這個命令就能夠生效。若是沒有在目錄下面就不會生效,這個就是PATH的做用
echo命令:用於在shell中打印shell變量的值,或者直接輸出指定的字符串。linux的echo命令,在shell編程中極爲經常使用, 在終端下打印變量value的時候也是經常用到的,所以有必要了解下echo的用法echo命令的功能是在顯示器上顯示一段文字,通常起到一個提示的做用。
[root@daizhihong01 ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin