1. 程式人生 > >Linux常用基礎命令(二)

Linux常用基礎命令(二)

目錄

1.檢視命令型別:

2.命令別名:

3.which:

4.whereis:

5.who:

6.w:

注:本系統環境為centos 7 。

1.檢視命令型別:

命令型別:
外部命令、shell內部命令

命令格式:type COMMAND:
                   內部:builtin(內建)
                   外部:顯示為命令檔案路徑;
                   注意:命令可以有別名;
                              別名可以與原名相同,此時原名被隱藏;此時如果要執行原命令,則使用\COMMAND
                              在使用一些不熟悉的命令的時候,應該先type COMMAND;
                              然後help COMMAND或COMMAND --help, 
                              來獲取命令的幫助文件;或者使用man COMMAND.

2.命令別名:

獲取所有可用別名的定義:
如下所示,為系統預設的別名設定。

~]#alias
alias cp='cp -i'
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'

定義別名:
注意:這種定義別名的方法,僅對當前shell程序有效

~]# alias NAME='COMMAND'

如果要長期有效,可以在使用者的家目錄,編輯這個檔案:
 

~]#cat .bashrc 
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

撤銷別名:

~]# unalias NAME

3.which:

which - shows the full path of (shell) commands
which [options] programname [...]
                --skip-alias:忽略別名

~]#which cp
alias cp='cp -i'
	/usr/bin/cp
~]#which --skip-alias cp
/usr/bin/cp

4.whereis:

whereis - locate the binary, source, and manual page files for a command
whereis [options] name...
                -b: 僅搜尋二進位制程式路徑;
                -m:僅搜尋使用手冊檔案路徑;

~]#whereis cp
cp: /usr/bin/cp /usr/share/man/man1/cp.1.gz /usr/share/man/man1p/cp.1p.gz
~]#whereis -b cp
cp: /usr/bin/cp
~]#whereis -m cp
cp: /usr/share/man/man1/cp.1.gz /usr/share/man/man1p/cp.1p.gz

5.who:

who - show who is logged on
 who [OPTION]...
                 -b: 系統此次啟動的時間;
                 -r: 執行級別;

~]#who -r
         執行級別 5 2018-12-03 10:09

6.w:

w - Show who is logged on and what they are doing.