![]() |
![]() |
![]() |
![]() |
![]() |
C:\Documents and Settings\User>dir c:\readme* /s/b/a ←輸入藍字+ <Enter> c:\android-sdk-windows\tools\Jet\demo_content\README.txt c:\android-sdk-windows\tools\Jet\JetCreator\ReadMe1st.txt c:\android-sdk-windows\tools\Jet\logic_templates\README.txt c:\BC45\README c:\cygwin\etc\alternatives\README c:\cygwin\etc\openldap\schema\README 以下略 |
文字操作界面的登入畫面 Fedora release 8 (Werewolf) ←顯示 Linux 發行版的資料 Kernel 2.6.23.1-42.cf8 on an i686 ←顯示 Linux Kernel 版本 localhost login: aaa↵ Enter ←輸入使用者的帳號 (此例為建立使用者帳號時所建立帳號〝aaa〞) password:(輸入使用者的帳號密碼)↵ Enter ←為了安全理由,輸入帳號密碼時不會有任何訊息在螢幕上 [aaa@localhost ~]$ ←登入後的提示,如 shell 種類為〝bash〞一般為〝[帳號@主機名稱+目錄的位置]〞 |
C:\dir c:\ /s/b↵ Enter ←輸入藍字 + <Enter> c:\android-sdk-windows c:\ATI c:\AUTOEXEC.BAT c:\CONFIG.SYS c:\CrashLogs c:\cygwin c:\Documents and Settings c:\eMake.bat 以下略 |
[aaa@localhost ~]$ echo $SHELL ↵ Enter ←顯示目前使用的 shell /bin/bash [aaa@localhost ~]$ chsh -l ↵ Enter ←查詢有那些 shell 可用 /bin/sh /bin/bash /sbin/nologin /bin/zsh [aaa@localhost ~]$ chsh -s /bin/zsh ↵ Enter←指定〝Z Shell〞為此帳號以後預設的 Shell(要登出後再登入才會生效) |
[aaa | @localhost | ~] | $ | |
↑ | ↑ | ↑ | ↑ | |
登 | 主 | 目 | 提 | |
入 | 機 | 錄 | 示 | |
者 | 名 | 的 | 符 | |
帳 | 稱 | 位 | 號 | |
號 | 置 |
[aaa@localhost ~]$ ls ↵ Enter ←Fedora 8 的指令〝ls〞,事實上是執行〝ls --color=tty〞,故輸出不同屬性的檔案會顯示不同的顏色 bin dev home lost+found misc net proc sbin srv tmp var boot etc lib media mnt otp root selinux sys usr [aaa@localhost ~]$ \ls ↵ Enter ←指令之前輸入〝\〞代表〝除去別名〞,輸出就不會五顏六色 bin dev home lost+found misc net proc sbin srv tmp var boot etc lib media mnt otp root selinux sys usr |
[aaa@localhost ~]$ type -a pwd ←查指令〝pwd〞為 shell 內建或執行檔或別名 pwd is a shell builtin ←指令〝pwd〞有二個,其一為shell 內建,另一個執行檔〝/bin/pwd〞 pwd is /bin/pwd [aaa@localhost ~]$ cd /var/mail↵ Enter ←進入目錄〝/var/mail〞 [aaa@localhost mail]$ pwd↵ Enter ←執行 shell 內建的〝pwd〞(內建優先) /var/mail ←內建的指令〝pwd〞顯示的路徑為連結檔 [aaa@localhost mail]$ /bin/pwd↵ Enter ←換執行檔〝/bin/pwd〞看輸出和內建的有無不同 /var/spool/mail ←執行檔指令〝/bin/pwd〞顯示的為真實路徑 |
[aaa@localhost ~]$ cat /etc/fst\↵ Enter ←輸入藍字 + <Enter> > ab↵ Enter ←輸入藍字,〝>〞 是自動產生的,不用輸入 LABEL=/ / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 LABEL=SWAP-sda3 swap swap defaults 0 0 [aaa@localhost ~]$ [aaa@localhost ~]$ cat /etc/fstab↵ Enter ←此例和上例是一樣的,只是上例利用〝\<Enter>〞分二行輸入 LABEL=/ / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 以下略 |
[aaa@localhost /]$ clear;cd /;ls↵ Enter ←多個指令時,指令和指令間可用〝;〞分隔 bin dev home lib media mnt opt root selinux sys usr boot etc lib lost+found misc net proc sbin srv tmp var |
[aaa@localhost ~]$ history↵ Enter 以下為輸入〝history〞指令後所列出曾經輸入過的字串(指令) 1 cat proc/cpuinfo 2 ls 3 rm ex07-7.cpp |
[aaa@localhost ~]$ seq 1 10000000↵ Enter 1 2 3 4 8Ctrol+C ←按 <Ctrl+C>可放棄目前的運算 aaa@localhost ~]$ |
[aaa@localhost ~]$ _Ctrl+D ←此時按 <Ctrl+D> 無效因游標不是在最左邊的位置 [aaa@localhost ~]$ ls_Ctrl+D ←此時按 <Ctrl+D> 無效,原因同上 [aaa@localhost ~]$ _Ctrl+D ←此時按 <Ctrl+D> 成立,因游標在最左邊的位置,會登出目前的使用者 |
[aaa@localhost ~]$ cat > EOF-test↵ Enter Hello, this is a EOF test↵ Enter Ctrl+D ←此時按 <Ctrl+D> 結束輸入 [aaa@localhost ~]$ cat EOF-test ←驗證看剛建立的檔案 Hello, this is a EOF test |
[aaa@localhost ~]$ lsTab ⇌ Tab ⇌ ←輸入〝ls〞按 <Tab> 没反應表示有多種可能,再按一次 <Tab> 即會列出所有符合的指令 |
[aaa@localhost ~]$ ls /etc/hosts.aTab ⇌llow _ ←輸入藍字,按 <Tab> 後自動補全檔名。 |
[aaa@localhost ~]$ |
[aaa@localhost ~]$ |
[aaa@localhost ~]$ 01234 |
[aaa@localhost ~]$ history Ctrl+L ←游標之上的的螢幕都會被清除掉 |
[aaa@localhost ~]$ echo $SHELL ←查詢目前的 shell (父 shell) /bin/bash ←目前為 Bourne shell (bash) [aaa@localhost ~]$ chsh -l ←查詢有那些 shell 可用(〝chsh -l〞實際上是讀取檔案〝/etc/shells〞的內容) /bin/sh /bin/bash /sbin/nologin /bin/zsh [aaa@localhost ~]$ zsh ←輸入可用的 shell(除了 nologin) [aaa@localhost]~% ←提示符號改變了,表示已進入其他子 shell (zsh) [aaa@localhost]~% logout ←用 logout 登出看看 logout: not login shell ←回應 zsh 不是登入的 shell 故不讓你登出 [aaa@localhost]~% exit ←退出目前的 shell [aaa@localhost ~]$ ←提示符號改變,回父 shell 的登入符號 [aaa@localhost]~% logout ←此時即可用 logout 登出了 |
語法:su [-otpiton][--option][帳號(若沒指定帳號,預設的帳號為〝root〞)] | ||
指令名稱/功能/命令使用者 | 選項 | 功能 |
su/ (Super User)暫時變更使用者/ Any |
-c '指令' 或 -command '指令' | 執行完指令後恢復原登入者 |
- 或 -l 或 --login ['帳號] | 改變使用者同時也變更該使用者的工作的環境 |
[aaa@localhost ~]$ ←非〝root〞帳號登入(預設提示符號為〝[帳號@主機名稱+目錄的位置]$〞) [aaa@localhost ~]$ su root ←變更帳號為〝root〞,注意,這次沒有〝-〞選項(不會變更工作環境) Password: ←輸入 root 的密碼 [root@localhost aaa]# ←(提示字元變了.但並沒有變更工作環境,工作目錄在原〝aaa〞的家目錄 [root@localhost ~]# exit ←恢復原登入者 [aaa@localhost ~]$ su - ←沒指定帳號,預設的帳號為〝root〞(這次有〝-〞選項) Password: ←輸入 root 的密碼 [root@localhost ~]# ←目前登入使用者己變 root,且工作目錄在 root 的家目錄 [root@localhost ~]# exit ←恢復原登入者 |
[aaa@localhost ~]$ su -c 'ls -a' - l bbb ←變更使用者〝bbb〞,執行指令〝ls -a〞 Password: ←會要求輸入 bbb 的密碼 . .. .bash_history .bash_logout .bash_profile .bashrc [aaa@localhost ~]# ←執行完指令後自動恢復原登入者 |
[aaa@localhost ~]$ halt Broadcast message from root (tty1)(Mon jul 4 15:50:44 2011): The system is going down for system halt NOW! INIT: Sending processes the TERM signal [ OK ] Shutting down Avahi deamon: [ OK ] Stopping HAL deamon: [ OK ] 中間略 Turning off swap: [ OK ] Turning off quotas: [ OK ] Unmounting file systems: [ OK ] Halting system... System halted. ←關機完成,此時才可按 PC 開關來關電源 |
語法:shutdown [-otpiton][時間(hh:mm) 或 (+m) 或 (now)]['訊息'] | ||
指令名稱/功能/命令使用者 | 選項 | 功能 |
shutdown/ 關機/ Superuser |
-F | 重開機時強迫用 fsck 檢查 partition |
-k | 只送訊息給其他登入的使用者,但不關機 | |
-h | 關掉所有執行中的行程後關機 | |
-r | 關機後重開機 (同 reboot 指令) |
[aaa@localhost ~]$ shutdown -h now ←立刻關機 -bash: shutdown: command not found ←沒此指令?原來只有 root 才可執行 shutdown 哦 [aaa@localhost ~]$ su - ←換 root 身分登入 Password: ←輸入 root 的密碼 [root@localhost ~]# shutdown -h +3 ←設 3 分鐘後會關機 Broadcast message from root (tty1) (wed jul 6 03:28:13 2011): The system is going DOWN for system halt in 3 minutes! ←其他的登入者都會同步收到3 分鐘後會關機的訊息哦 Ctrl+C ←如閞機時間還沒到,想後悔,可按 <Ctrl+C> 來停止關機 Shutdown cancelled.←shutdown 指令被 <Ctrl+C>中止了 |
[root@localhost ~]# shutdown -h 0 'hello' ←可加其他的訊息通知其他的登入者 [root@localhost ~]# shutdown -k now 'hello' ←不會真正關機,只是把訊息通知其他的登入者 [root@localhost ~]# shutdown -r 10:08 ←10:08會重開機 |
[root@localhost ~]# sync;sync;sync;shutdown -h 0 |
runlevel | 模式 |
0 | 關機 |
1 | 單用戶模式,維護用途故不會讓其他帳號登入 |
2 | 多人模式,但無網路連線 |
3 | 多人模式,有網路連線但運行純文字界面(許多 server 的預設值) |
4 | 預留未使用 |
5 | 同 3,但以圖形介面開機和操作 |
6 | 重開機 |
[root@localhost ~]# runlevel N 5 ←第一個字元〝N〞為之前的 runlevel,第二個字元〝5〞為目前的 runlevel,其中 runlevel 等級有時會用英文字母代表,如〝N〞表示 None 不存在的意思,〝S〞表示 Single 單用戶模式) |
[root@localhost ~]# init 0 ←耍帥一下,關機指令用〝init 0〞(即 runlevel =0 來關機) [root@localhost ~]# init 6 ←等於 reboot 重新開機 [root@localhost ~]# init 1 ←進入維護模式 |
[aaa@localhost ~]$ cat /sbin/reboot ←故意螢幕輸出一執行檔〝reboot〞(執行檔為機械碼)大部分會造成亂碼 ┌┌␋┼┤│.⎽⎺.2 ␋┼␋├┌⎺±. ▒┌ ⎻ os├ sbi┼] $ c┌e▒r ←就算用〝clear〞清除螢幕還是亂碼,只好用〝reset〞指令來重置螢幕,消除亂碼 |
[aaa@localhost ~]$ man shutdown SHUTDOWN(8) Linux System Administrator’s Manual SHUTDOWN(8) NAME shutdown - bring the system down SYNOPSIS /sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message] DESCRIPTION shutdown brings the system down in a secure way. All logged-in users are notified that the system is going down, and login(1) is blocked. It is possible to shut the system down immediately or after a specified 中間略 OPTIONS -a Use /etc/shutdown.allow. -t sec Tell init(8) to wait sec seconds between sending processes the warning and the kill signal, before changing to another run- level. 中間略 SEE ALSO fsck(8), init(8), halt(8), poweroff(8), reboot(8) |
man section numbers | 說明 |
1 | 一般命令 |
2 | 系統呼叫(System call) |
3 | C 語言函數 (C library functions) |
4 | 裝置檔 |
5 | 檔案格式 |
6 | 遊戲或螢幕保護程式 |
7 | 雜項 |
8 | 系統管理員的指令 |
9 | Kernel Interface |
[aaa@localhost ~]$ man -f shutdown shutdown (2) - shut down part of a full-duplex connection shutdown (3p) - shut down socket send and receive operations shutdown (8) - bring the system down |
man Subsection | 說明 |
p | POSIX |
x | X Window System |
對記性不好的我而言 SEE ALSO 還蠻重要的,例如我可能只記得關機指令是 shutdown, 但 SEE ALSO 會提醒我和 shutdown 有相關的 init、reboot、halt 等指令。
man page 各參考手冊的資料都存放在那個目錄呢?可由指令 manpath 查閱其路徑,所以自行下載的指令如有附 man page 說明檔,記得要把該指令的 man page 存放在正確的位置,不然 man 會查不到喔。
[aaa@localhost ~]$ man whereis | col -b > whereis.txt ←將 man page 存成文字檔 |
man 更詳細的用法請自行輸入 man man。
[aaa@localhost ~]$ info shutdown file: *manpages*, Node: shutdown, Up: (dir) ←如出現〝*manpages*〞表示無 info 格式文件,故借用 man page 的文件 SHUTDOWN(8) Linux System Administrator’s Manual SHUTDOWN(8) 以下略 |
[aaa@localhost ~]$ info su
file:coreutils.info, Node: su invocation, Next: dir invocation, Up: Modif\ ied command invocation ←如出現〝file:coreutils.info〞表示是正確的 info 格式文件 2.5 'su' : Run a command with substitute user and group ID 以下略 |
[aaa@localhost ~]$ reboot --help usage: reboot [-n] [-w] [-d] [-f] [-h] [-i] -n: don't sync before halting the system -w: only write a wtmp reboot record and exit. -d: don't write a wtmp record. -f: force halt/reboot, don't call shutdown. -h: put harddisks in standby mode. -i: shut down all network interfaces. |