|
Linux常用指令
UNIX Commands
 | Format
指令(Command) 選項s(Options) 參數s(arguments) |
 | UNIX指令三大部分之間至少須有一個空白鍵(Space) or
<TAB> 鍵區隔之。 |
 | 選項一律以『-』 為前導,同時使用多個選項,可以將之合併,例如
ls -l -a -t == ls -alt |
 | 三大部分之順序不可更動。 |
 | UNIX系統中,指令、選項及參數均為Case
Sensitive,亦即大小寫不可任意更換。例如指令『ls』不可寫成『LS』 |
 | 同一行中可輸入一個以上之指令,但指令之間必須以分號『;』分隔開。 |
 | UNIX Command很少超過四個字 |
 | 很多UNIX Commands無法由字面了解其用途 |
 | Commands(external) are files.
|
PATH:
 | UNIX use $PATH to locate
commands
[woody@nmc woody]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/woody/bin
--> $PATH是系統對應指令的環境參數,由系統設定,使用者也可以自行設定之。
[woody@nmc woody]$ type passwd
passwd is /usr/bin/passwd
-->passwd is located in /usr/bin/passwd
|
Internal and
External Commands:
 | Internal commands are absorbed in
the shell. Even you can locate it in the file system with command "which",it
is not the file which is to be executed.
[woody@nmc
woody]$ which echo
/bin/echo
[woody@nmc woody]$ type echo
echo is a shell builtin
--> echo is an internal
command
|
 | External command is itself an
excutable file in the system, that can be located with command "type" or
"which".
|
Command line can
overflow:
 |
當指令該成對的符號只出現其一,或我們輸入"\"時,系統會出現"secondary prompt" ">" 或"?",允許你將一個指令分為兩行輸入。
[root@nmc
/root]# echo "this
> is
> a
> test"
this
is
a
test
[root@nmc /root]# echo "this \
> is \
> a \
> test
> "
this is a test
|
Type ahead buffer:
 | You can type your command at any
time and the system will interpret it in sequence latter. |

Linux常用指令

 | alias
功能:指定指令的別名
語法:alias "別名"="指令名稱"
Example:
[woody@dragon1 woody]$ alias del="rm -i"
[woody@dragon1 woody]$ alias del
alias del='rm -i' |

 | bg
功能:將指定的工作(job)移至背景執行
語法:bg "工作代號"
Example:
[woody@dragon1 woody]$ find ./ -name woody -print
(Ctrl + Z)
[1]+ Stopped find ./ -name woody -print
[woody@dragon1 woody]$ find ./ -name pk -print
(Ctrl + Z)
[2]+ Stopped find ./ -name pk -print
[woody@dragon1 woody]$ jobs
[1]- Stopped find ./ -name woody -print
[2]+ Stopped find ./ -name pk -print
[woody@dragon1 woody]$ bg %1
補充說明:Linux中一個login
Session只能有一個前景程式存在,因此讓某一程式進入背景執行為兩以上的程式同時執行的方法。另一個讓程式進入背景的方法為:執行程式時,在程式名稱之後加一個"&"符號。例如:"find
/ -name inetd.conf &" |

 | cat
功能:印出檔案內容至銀幕(標準輸出)或合併多檔。cat file1 file2 >
file3可將檔案file1、file2之內容依順序合併,並將結果存至file3。
語法:cat [-選項] file |

 | cd
功能:改變目前工作目錄之位置至directory,若[directory]略之,則返回至使用者之簽入時之目錄(Home Directory)。
語法:cat [目的目錄名稱] |

 | clear
功能:清除目前銀幕顯示。
語法:clear
補充說明:當銀幕因某些原因無法正常顯示時,可用指令"reset"重設銀幕。 |

 | cp
功能:檔案複製。若target為檔案名稱,則file只能指定一個檔案,若target為一個目錄名稱,則會將file1、file2..分別複製至此一目錄之下。
語法:cp[選項] file1 file2, cp [選項]file directory
Example:
[woody@dragon1 test]$ ls -l
total 197
-rw-r--r-- 1 root root 56199 Dec 4 1997 badpasswd.3
-rw-r--r-- 1 root staff 29266 Dec 4 1997 mail_cmd
-rw-r--r-- 1 woody staff 104261 Oct 20 1997 test.tar
-rw-r--r-- 1 root staff 225 Dec 4 1997 warnning
[woody@dragon1 test]$ cp -i test.tar warnning
cp: 蓋寫 `warnning' 而不理保護模式 0644? n
補充說明:選項"i"若target存在,會要求使用者確認複製之動作。 |

 | df
功能:顯示磁碟相關資訊。
語法:df [選項]
Example:
[woody@dragon1 test]$ df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/sda1 2974519 1299841 1520858 46% /
/dev/sda8 1088223 80639 951359 8% /data
/dev/sda5 2974519 476434 2344265 17% /home
/dev/sda6 1517920 925240 515572 64% /rd61
/dev/sdb1 1890676 994932 798152 55% /slack70
dragon:/users 679478 291877 319653 48% /users
dragon:/users1 980217 417176 465019 47% /users1
dragon:/var/spool/mail
1938727 523699 1221155 30% /var/spool/mail
可用選項及代表意義:
-a 所有檔案系統(Partition)
-i 顯示inode資訊
-k 以KByte為單位顯示磁碟資訊
-l 僅顯示Local File Syatem(不含NFS)
--help 顯示獻上求助資訊(關於df) |

 | exit
功能:退出系統(=logout)。 |

 | fg
功能:將指定的工作(job)移至前景景執行。
語法:用法同 "bg"
補充說明: 當你把程式移至前景,你將無法繼續在終端機上輸入指令。 |

 | find
功能:依照指定條件,找尋檔案或目錄。
語法:find start_directory [-選項]
常用選項及代表檔案條件:
-amin <min> 指定時間內曾被存取過的檔案,單位為分鐘
-atime <day> 指定時間內曾被存取過的檔案,單位為24小時
-exec <指令> 當找到符合條件的檔案,就執行該指令,指令結尾必須是";"
-mmin <min> 指定時間內曾異動過的檔案,單位為分鐘
-mtime <day> 指定時間內曾被異動過的檔案,單位為24小時
-nouser 檔案不屬於本機上之任何User的檔案
-ok <指令> 用法同-exec,唯每一個指令執行前均會詢問使用者
-print 將符合條件的檔案資料由終端機顯示出來
-size <檔案大小> 符合檔案大小的檔案,單位為512Byte(Block),檔案大小前加"+"號代表大於這個 size,"-"代表小於這個size
-user <username> 屬於"username"的檔案
Example:
[root@dragon1 woody]# find ./ -size +500 -print
###找到目前目錄下,檔案大小大於250K Bytes的檔案,並將結果由終端機輸出
[root@dragon1 woody]# find / -nouser -exec rm {} \;
###找出整個系統中所有"無主檔案"並刪除之。 |

 | grep
功能:找尋並印出files中含有字串pattern 所在行內容
語法:grep pattern file_name
Example1:
[woody@dragon1 woody]$ grep woody /etc/passwd
woody:x:3694:710:Woody WU:/users/staff/woody:/bin/bash
woody1:x:5361:5361::/home/woody1:/bin/tcsh
woody2:x:5362:5362::/home/woody2:/bin/tcsh
###找出/etc/passwd中含有woody字串的行
Example2:
[woody@dragon1 woody]$ ps aux|grep woody
root 10554 0.0 0.8 2236 1136 pts/0 S 00:14 0:00 login -- woody
woody 10555 0.0 0.7 1700 944 pts/0 S 00:15 0:00 -bash
woody 10569 0.0 0.6 2516 876 pts/0 R 00:17 0:00 ps aux
woody 10570 0.0 0.4 2124 520 pts/0 S 00:17 0:00 grep woody
###找出目前系統中,所有以woody名義執行的process訊息 |

 | gunzip (gnu unzip)
功能:解開壓縮檔(.gz)
語法:gunzip file_name
Example1:
[woody@dragon1 woody]$ gunzip a.gz
###解開檔名為a.gz的壓縮檔,並刪除a.gz
Example2:
[woody@dragon1 woody]$ gunzip a.gz > b
###解開檔名為a.gz的壓縮檔,保留a.gz,並將結果輸出至"b" |

 | gzip
功能:檔案壓縮
語法:gzip file_name
###gzip -d = gunzip |

 | last
功能:列出目前與過去登入系統的使用者相關資訊
語法:last [帳號名稱]
Example1:
[woody@dragon1 woody]$ last woody
woody pts/0 woody Thu Mar 9 00:15 still logged in
woody pts/0 woody Wed Mar 8 03:48 - 05:29 (01:41)
woody pts/0 liu Mon Mar 6 21:38 - 23:28 (01:50)
woody pts/1 woody Fri Mar 3 21:44 - 21:49 (00:05)
woody pts/0 woody Fri Mar 3 21:39 - 22:54 (01:14)
woody pts/0 woody Fri Mar 3 05:15 - 05:22 (00:06) |

 | ls
功能:列出所在或指定目錄的內容or檔案之相關特性
語法:ls [-選項] [目錄or檔案名稱]
常用選項及其代表之意義
-a : 列出所有檔案名稱,包括以『.』開頭之隱藏檔,如.profile、.login等。
-d : 若參數的為一目錄名稱,則只列出檔案名稱而非目錄之內容。
-l : 列出檔案的詳細資料,包括檔案形態、存取權限、連結數目、擁有 者名稱、群組名稱等。 |

 | mail
功能:E-Mail收送管理程式
語法:mail [-b <bcc_list>] [-f <mail_file>] [-s <subject>] [-u <user>] [mail
Address]
Example1:
[woody@dragon1 woody]$ mail -v -s "Mail Test" woody@nchu.edu.tw
###寄一封信給woody,信件主旨為"Mail Test"
This is a mail test.
###這是信件內容
.
###以"."為開頭的空白行代表訊息主體結束
###以下是信件寄送過程,Local Machine 與Email Server間溝通送信過程
Cc:
woody@nchu.edu.tw... Connecting to dragon.nchu.edu.tw. via esmtp...
220 dragon.nchu.edu.tw ESMTP Sendmail 8.9.1a/8.9.1; Wed, 8 Mar 2000 13:29:41 +0)
>>> EHLO dragon1.nchu.edu.tw
250-dragon.nchu.edu.tw Hello IDENT:root@dragon1 [140.120.2.17], pleased to meetu
....
>>> MAIL From:<woody@dragon1.nchu.edu.tw> SIZE=63
250 <woody@dragon1.nchu.edu.tw>... Sender ok
>>> RCPT To:<woody@nchu.edu.tw>
250 <woody@nchu.edu.tw>... Recipient ok
>>> DATA
354 Enter mail, end with "." on a line by itself
>>> .
250 NAA08638 Message accepted for delivery
woody@nchu.edu.tw... Sent (NAA08638 Message accepted for delivery)
Closing connection to dragon.nchu.edu.tw.
>>> QUIT
221 dragon.nchu.edu.tw closing connection |


 | mkdir
功能:建立目錄
語法:mkdir <目錄名稱> |

 | more
功能:以每次一頁方式顯示一個檔案
語法:more file_name |

 | passwd
功能:更改使用者密碼
語法:passwd [user_name]
補充說明:
1.當user_name不提供時,為更改目前login者密碼
2.更改本身密碼時,必須先輸入舊密碼,確認無誤後,才可更改。
3.不具備MD5功能的系統,密碼最大長度為8字元 |

 | w (who)
功能:列出目前線上使用者資訊
語法:w (who) |

 | whereis
功能:在指定或特定的目錄中尋找檔案
語法:whereis file_name |

|