Changes between Version 2 and Version 3 of YM_Course_2009/Lab3


Ignore:
Timestamp:
Jul 4, 2009, 9:04:13 AM (15 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • YM_Course_2009/Lab3

    v2 v3  
    11{{{
    22#!html
    3 <div style="text-align: center;"><big style="font-weight: bold;"><big>實作三: </big></big></div>
     3<div style="text-align: center;"><big style="font-weight: bold;"><big>實作三: SSH 遠端登入</big></big></div>
    44}}}
    55[[PageOutline]]
    66
    77◢ <[wiki:YM_Course_2009/Lab2 實作二]> | <[wiki:YM_Course_2009 回課程大綱]> ▲ | <[wiki:YM_Course_2009/Lab4 實作四]> ◣
     8
     9= 前言 =
     10
     11 * 首先,請使用 Ubuntu 9.04 安裝光碟開機。然後選擇 Application > Accessories > Terminal
     12  * [[Image(Lab3-01.jpg)]]
     13
     14= 1. ssh =
     15
     16== 1.1 ssh 登入遠端主機練習 ==
     17
     18 * 在 Linux 下,你可以用以下指令連線
     19{{{
     20$ ssh bio.classcloud.org
     21}}}
     22  * 此時 ssh 會使用你目前正在使用的使用者名稱登入,並要求輸入密碼
     23  * [[Image(Lab3-02.jpg)]]
     24 * 在 Windows 底下,你可以使用各種 SSH Client 連線,例如: PuTTY (英文) 或 PieTTY (中文)
     25  * 下載 PieTTY - http://ntu.csie.org/~piaip/pietty
     26  * 開啟 PieTTY[[BR]][[Image(Lab3-03.jpg)]]
     27  * 確認選擇 SSH 而非 Telnet , PORT (連接埠) 數值為 22
     28  * 輸入 IP 位址
     29{{{
     30#!sh
     31bio.classcloud.org
     32}}}
     33 * PieTTY 會詢問使用者名稱與密碼
     34  * [[Image(Lab3-04.jpg)]]
     35
     36== 1.2 ssh 連線指定使用者名稱 ==
     37
     38 * 在 Linux 下,你可以用以下指令來指定欲登入的使用者名稱
     39{{{
     40$ ssh bio.classcloud.org -l ym24
     41
     42$ ssh ym24@bio.classcloud.org
     43}}}
     44 * [[Image(Lab3-05.jpg)]]
     45 * 要結束 ssh 連線,請輸入 exit
     46{{{
     47$ exit
     48}}}
     49 * [練習] 請使用發給各位的帳號與密碼登入此次課程專用的叢集
     50 
     51
     52== 1.3 ssh 連線非預設 22 連接埠 ==
     53
     54 * 在 Linux 下,你可以用以下指令連線
     55{{{
     56$ ssh bio.classcloud.org -u ym24 -p 8022
     57}}}
     58 * [[Image(Lab3-06.jpg)]]
     59 * 在 Windows 底下,你可以直接修改 PORT 的數?
     60 
     61== 1.4 不用登入也可以執行指令 ==
     62
     63 * 在 Linux 下,你可以用以下指令直接執行指令
     64{{{
     65$ ssh ym24@bio.classcloud.org ls
     66}}}
     67 * [[Image(Lab3-07.jpg)]]
     68 
     69= 2. scp =
     70
     71== 2.1 使用 scp 將本地端檔案複製到遠端 ==
     72
     73 * 在 Linux 底下,可以用以下指令複製本地端檔案到遠端
     74{{{
     75ubuntu@ubuntu:~$ scp /etc/profile ym24@bio.classcloud.org:.
     76ym24@bio.classcloud.org's password:
     77profile                                      100%  497     0.5KB/s   00:00
     78}}}
     79 * 檢查有沒有複製成功呢??
     80{{{
     81ubuntu@ubuntu:~$ ssh ym24@bio.classcloud.org ls
     82ym24@bio.classcloud.org's password:
     83profile
     84}}}
     85
     86== 2.2 使用 scp 從遠端複製檔案到本地端 ==
     87
     88 * 在 Linux 底下,可以用以下指令複製遠端檔案到本地端
     89{{{
     90ubuntu@ubuntu:~$ scp ym24@bio.classcloud.org:profile .
     91ym24@bio.classcloud.org's password:
     92profile                                      100%  497     0.5KB/s   00:00
     93ubuntu@ubuntu:~$ ls
     94profile
     95}}}
     96
     97== 2.3 懶得打密碼??請交換 SSH 認證金鑰 ==
     98
     99 * 在 Linux 下,你可以用以下指令產生 SSH 認證金鑰
     100{{{
     101ubuntu@ubuntu:~$ ssh-keygen
     102Generating public/private rsa key pair.
     103Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa):
     104Enter passphrase (empty for no passphrase):
     105Enter same passphrase again:
     106Your identification has been saved in /home/ubuntu/.ssh/id_rsa.
     107Your public key has been saved in /home/ubuntu/.ssh/id_rsa.pub.
     108The key fingerprint is:
     109ad:40:81:53:dc:4b:6f:41:b2:71:82:4b:a7:3a:63:8d ubuntu@ubuntu
     110}}}
     111 * 然後用 ssh 指令在遠端建立 .ssh 目錄
     112{{{
     113ubuntu@ubuntu:~$ ssh ym24@bio.classcloud.org mkdir -p .ssh
     114ym24@bio.classcloud.org's password:
     115}}}
     116 * 把 .ssh/id_rsa.pub 拷貝到遠端 .ssh/authorized_keys
     117{{{
     118ubuntu@ubuntu:~$ scp .ssh/id_rsa.pub ym24@bio.classcloud.org:.ssh/authorized_keys
     119ym24@bio.classcloud.org's password:
     120id_rsa.pub                                   100%  395     0.4KB/s   00:00
     121}}}
     122 * 此時要透過 ssh 在遠端執行 ls 指令就不用密碼了
     123{{{
     124ubuntu@ubuntu:~$ ssh ym24@bio.classcloud.org ls
     125profile
     126}}}
     127
     128== 2.4 複製本地目錄到遠端 ==
     129
     130 * 我們可以透過 -r 參數說明要複製的是目錄
     131{{{
     132ubuntu@ubuntu:~$ scp -r temp/ ym24@bio.classcloud.org:.
     133ubuntu@ubuntu:~$ ssh ym24@bio.classcloud.org ls
     134profile
     135temp
     136}}}
     137 * 若是不加 -r 的話,scp 指令會警告你 "not a regular file"
     138{{{
     139ubuntu@ubuntu:~$ scp temp ym24@bio.classcloud.org:.
     140temp: not a regular file
     141}}}
     142
     143== 2.5 複製遠端目錄到本地 ==
     144
     145 * 我們可以透過 -P (注意大寫) 來指定要連線的 PORT
     146{{{
     147ubuntu@ubuntu:~$ scp -r -P 8022 ym24@bio.classcloud.org:temp temp2
     148ubuntu@ubuntu:~$ ls
     149profile  temp  temp2
     150}}}
     151
     152== 2.6 WinSCP 操作 ==
     153
     154 * 在 Windows 底下,可以下載 WinSCP,就可以像使用 FTP 軟體一樣直接上傳下載檔案。
     155 * 下載位址:http://winscp.net
     156 
     157= 3. screen =
     158
     159 * 有些時候,為了在不同的檔案之間複製、貼上,要開好幾個終端機 (Terminal) 或 PieTTY,其實 Linux 本身就內建這樣的功能,這個指令叫做 screen
     160 
     161== 3.1 啟用 screen ==
     162
     163 * 執行 screen 指令,即可進入 screen
     164{{{
     165ubuntu@ubuntu:~$ screen
     166}}}
     167 * [註] Ubuntu 9.04 有特別設計了幾種情境的 screen 可以使用,一般並不會出現這樣的訊息。
     168 * [[Image(Lab3-08.jpg)]]
     169 
     170== 3.2 列出 screen 資訊與強制關閉 screen ==
     171
     172 * 我們可以透過 screen -ls 來查詢目前開啟的 screen 有哪些
     173 * 縱使在 screen 中,還是可以強制用 screen -D 關閉目前的畫面
     174 * [[Image(Lab3-09.jpg)]]
     175 
     176== 3.3 接續斷線的 screen ==
     177
     178 * screen 的狀態如果是 Detached 就可以用 -r 接續
     179 * screen 的狀態如果是 Attached 就必須用 -R 接續
     180 * [[Image(Lab3-10.jpg)]]
     181
     182== 3.4 練習 screen 快速鍵 ==
     183
     184 * 請按下 CTRL+a 後按下 CTRL+c 可以新增一個視窗,編號為 1
     185 * 請按下 CTRL+a 後按下 CTRL+a 可以切換為視窗 1。同樣快速鍵,會切回視窗 0。
     186 * 請按下 CTRL+a 後按下 CTRL+c 可以新增一個視窗,編號為 2
     187 * 請按下 CTRL+a 後按下 0 可以切換為視窗 0
     188 * 請按下 CTRL+a 後按下 1 可以切換為視窗 1
     189 * 請按下 CTRL+a 後按下 2 可以切換為視窗 2
     190 * 請按下 CTRL+a 後按下 CTRL+d 可以強制離開 screen
     191 
     192=4. chown / chgrp / chmod ==
     193
     194== 4.1 查詢檔案目前的權限 ==
     195
     196 * 我們以 2.2 拷貝的 profile 這個檔案為例,使用 ls -al 來查詢權限狀態
     197{{{
     198ubuntu@ubuntu:~$ ls -al profile
     199-rw-r--r-- 1 ubuntu ubuntu 497 2009-07-04 00:50 profile
     200}}}
     201 * 由前面的 -rw-r--r-- 我們可以知道它是一個檔案,擁有者可以讀/寫,同群組的其他使用者可以讀,不同群組的其他使用者可以讀。
     202 * 擁有者是 ubuntu,所屬群組為 ubuntu,改變時間為 2009-07-04 00:50
     203
     204== 4.2 使用 chown 來改變檔案之擁有人 ==
     205
     206 * 欲使用 chown 必須擁有 sudo 權限或跟新擁有者同群組的權限,否則會有 "Operation not permitted" 的錯誤
     207{{{
     208ubuntu@ubuntu:~$ chown ym24 profile
     209chown: changing ownership of `profile': Operation not permitted
     210}}}
     211 * 這裡我們用 sudo 來改擁有者
     212{{{
     213ubuntu@ubuntu:~$ sudo chown root profile
     214}}}
     215 * 改好之後,再查詢現在的擁有者是 root
     216{{{
     217ubuntu@ubuntu:~$ ls -al profile
     218-rw-r--r-- 1 root ubuntu 497 2009-07-04 00:50 profile
     219}}}
     220 * 如果用 vi 開啟 profile 檔案,那會發現畫面上顯示 "profile" [readonly] 的訊息,代表 ubuntu 現在只是同群組的使用者,只能讀,不能寫了。
     221 
     222== 4.3 使用 chgrp 來改變檔案的群組 ==
     223
     224 * 這裡我們用 sudo 來執行 chgrp 改變檔案的群組
     225{{{
     226ubuntu@ubuntu:~$ sudo chgrp root profile
     227ubuntu@ubuntu:~$ ls -al profile
     228-rw-r--r-- 1 root root 497 Jul  4 00:50 profile
     229}}}
     230
     231== 4.4 使用 chmod 來改變檔案的權限 ==
     232
     233 * 這裡我們用 sudo 來執行 chmod 改變檔案的權限
     234  * 權限是以二進位計算,因此 7 = 111 = rwx 而 0 = 000 = ---
     235{{{
     236ubuntu@ubuntu:~$ sudo chmod 700 profile
     237ubuntu@ubuntu:~$ ls -al profile
     238-rwx------ 1 root root 497 Jul  4 00:50 profile
     239}}}
     240 * 此時,用 cat profile 會有 Permission denied 的錯誤
     241{{{
     242ubuntu@ubuntu:~$ cat profile
     243cat: profile: Permission denied
     244}}}
     245 * 我們若把擁有者身分換回 ubuntu 就會恢復可讀寫的狀態
     246{{{
     247ubuntu@ubuntu:~$ sudo chown ubuntu:ubuntu profile
     248ubuntu@ubuntu:~$ ls -al profile
     249-rwx------ 1 ubuntu ubuntu 497 Jul  4 00:50 profile
     250ubuntu@ubuntu:~$ cat profile
     251}}}
     252
     253= 5. ps =
     254
     255 * 查詢自己目前正在跑的程序,其中 PID 的意思是 Process ID 意即每個執行的程序都有一個自己識別用的編號
     256{{{
     257ubuntu@ubuntu:~$ ps
     258  PID TTY          TIME CMD
     259 6017 pts/1    00:00:00 bash
     260 6391 pts/1    00:00:00 ps
     261}}}
     262 * 加上 -l 參數,顯示詳細資料,這裡的 UID = User ID, PPID = Parent Process ID
     263{{{
     264ubuntu@ubuntu:~$ ps -l
     265F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
     2660 R  1003  6491  6490  3  80   0 -  5257 -      pts/0    00:00:00 bash
     2670 R  1003  6507  6491  0  80   0 -  1661 -      pts/0    00:00:00 ps
     268}}}
     269 * 加上 -ef 看所有執行中的程序
     270{{{
     271ubuntu@ubuntu:~$ ps -ef
     272UID        PID  PPID  C STIME TTY          TIME CMD
     273root         1     0  0 00:06 ?        00:00:01 /sbin/init
     274root         2     0  0 00:06 ?        00:00:00 [kthreadd]
     275root         3     2  0 00:06 ?        00:00:00 [migration/0]
     276root         4     2  0 00:06 ?        00:00:00 [ksoftirqd/0]
     277root         5     2  0 00:06 ?        00:00:00 [watchdog/0]
     278root         6     2  0 00:06 ?        00:00:00 [events/0]
     279root         7     2  0 00:06 ?        00:00:00 [khelper]
     280...略...
     281}}}
     282 * 加上 -ejH 看所有程序的樹狀關係
     283{{{
     284ubuntu@ubuntu:~$ ps -ejH
     285  PID  PGID   SID TTY          TIME CMD
     286    2     0     0 ?        00:00:00 kthreadd
     287    3     0     0 ?        00:00:00   migration/0
     288    4     0     0 ?        00:00:00   ksoftirqd/0
     289    5     0     0 ?        00:00:00   watchdog/0
     290    6     0     0 ?        00:00:00   events/0
     291    7     0     0 ?        00:00:00   khelper
     292   39     0     0 ?        00:00:00   kblockd/0
     293   42     0     0 ?        00:00:00   kacpid
     294   43     0     0 ?        00:00:00   kacpi_notify
     295  103     0     0 ?        00:00:00   kseriod
     296  145     0     0 ?        00:00:00   pdflush
     297  146     0     0 ?        00:00:00   pdflush
     298  147     0     0 ?        00:00:00   kswapd0
     299  190     0     0 ?        00:00:00   aio/0
     300 1377     0     0 ?        00:00:00   ata/0
     301 1381     0     0 ?        00:00:00   ata_aux
     302 1520     0     0 ?        00:00:00   scsi_eh_0
     303 1682     0     0 ?        00:00:00   scsi_eh_1
     304 1684     0     0 ?        00:00:00   scsi_eh_2
     305 2529     0     0 ?        00:00:00   kjournald
     306 2952     0     0 ?        00:00:00   kpsmoused
     307    1     1     1 ?        00:00:01 init
     308 2736  2736  2736 ?        00:00:12   udevd
     309 4208  4208  4208 tty4     00:00:00   getty
     310 4209  4209  4209 tty5     00:00:00   getty
     311 4213  4213  4213 tty2     00:00:00   getty
     312 4215  4215  4215 tty3     00:00:00   getty
     313 4216  4216  4216 tty6     00:00:00   getty
     314 ...略...
     315}}}
     316
     317= 6. bg / fg / jobs / kill =
     318
     319 * 這裡我們以 sleep 60 來產生一個展示用的程序,下完指令後按 CTRL + z 會顯示 Stopped
     320{{{
     321ubuntu@ubuntu:~$ sleep 60
     322
     323[1]+  Stopped                 sleep 60
     324ubuntu@ubuntu:~$
     325}}}
     326 * 此時下 bg 指令,會看到程序又恢復執行,只是後面多加上 & 符號。
     327 * 我們可以使用 jobs 指令來看背景有哪些指令在執行。
     328{{{
     329ubuntu@ubuntu:~$ bg
     330[1]+ sleep 60 &
     331ubuntu@ubuntu:~$ jobs
     332[1]+  Running                 sleep 60 &
     333}}}
     334 * 因此,如果你要直接把某個程序丟到背景執行,可以直接加上 & 符號
     335{{{
     336ubuntu@ubuntu:~$ sleep 60 &
     337[2] 6684
     338ubuntu@ubuntu:~$ sleep 60 &
     339[3] 6685
     340ubuntu@ubuntu:~$ sleep 60 &
     341[4] 6686
     342ubuntu@ubuntu:~$ jobs
     343[1]   Running                 sleep 60 &
     344[2]   Running                 sleep 60 &
     345[3]-  Running                 sleep 60 &
     346[4]+  Running                 sleep 60 &
     347}}}
     348 * 如果要恢復特定的背景程序,可以用 fg 加上識別 ID 來恢復
     349{{{
     350ubuntu@ubuntu:~$ fg 1
     351}}}
     352 * 當某個背景程序跑完時,會顯示 Done 訊息。
     353{{{
     354[1]   Done                    sleep 60
     355}}}
     356 * 我們如果用 ps 來觀察目前正在執行的程序,會發現還有三個留著。
     357{{{
     358ubuntu@ubuntu:~$ ps -a
     359  PID TTY          TIME CMD
     360 6684 pts/0    00:00:00 sleep
     361 6685 pts/0    00:00:00 sleep
     362 6686 pts/0    00:00:00 sleep
     363 6691 pts/0    00:00:00 ps
     364ubuntu@ubuntu:~$ jobs
     365[2]   Running                 sleep 60 &
     366[3]-  Running                 sleep 60 &
     367[4]+  Running                 sleep 60 &
     368}}}
     369 * 如果想要移除某個執行中的程序,可以用 kill PID 方式
     370{{{
     371ubuntu@ubuntu:~$ kill
     372kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
     373ubuntu@ubuntu:~$ kill 6684
     374[2]   Terminated              sleep 60
     375}}}
     376
     377= 7. top =
     378
     379 * 為了查詢系統負載,可以用 top 指令觀察目前 CPU 與記憶體的使用率
     380{{{
     381ubuntu@ubuntu:~$ top
     382}}}
     383 * 這裡主要是看 Cpu(s) 的 %us (使用百分比)與 Mem 的 total 總使用量
     384{{{
     385top - 02:41:00 up  2:34,  2 users,  load average: 0.08, 0.09, 0.03
     386Tasks:  43 total,   1 running,  42 sleeping,   0 stopped,   0 zombie
     387Cpu(s):  0.0%us,  0.0%sy,  0.0%ni,100.0%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
     388Mem:    253072k total,    85812k used,   167260k free,     5668k buffers
     389Swap:   915664k total,    39472k used,   876192k free,    26360k cached
     390
     391  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
     392    1 root      20   0  4020  804  672 S  0.0  0.3   0:01.29 init
     393    2 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 kthreadd
     394    3 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 migration/0
     395    4 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0
     396}}}
     397 * 可以按 s 然後輸入更新秒數,例如:1
     398{{{
     399Change delay from 3.0 to: 1
     400}}}
     401 * 如果系統是多核心系統,當按下 1 時,會切換顯示 Cpu0, Cpu1 ...
     402{{{
     403Cpu0  :  0.0%us,  0.1%sy,  0.0%ni, 99.8%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
     404Cpu1  :  0.0%us,  0.1%sy,  0.0%ni, 99.8%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
     405}}}
     406 * 欲結束 top 程式,請按 q
     407
     408= 8. uptime =
     409
     410 * 我們可以用 uptime 指令查看系統已經連續運行的多久
     411{{{
     412ubuntu@ubuntu:~$ uptime
     413 02:45:22 up  2:38,  2 users,  load average: 0.08, 0.04, 0.01
     414}}}
     415
     416= 9. who =
     417
     418 * 我們可以用 who 與 w 指令查詢目前系統有幾個人連線。以下是在 ssh 連線到遠端的示範情形。
     419{{{
     420ubuntu@ubuntu:~$ who
     421ubuntu   pts/0        2009-07-04 02:01 (192.168.0.253)
     422ubuntu@ubuntu:~$ w
     423 02:46:24 up  2:39,  2 users,  load average: 0.03, 0.03, 0.00
     424USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
     425ubuntu   pts/0    192.168.0.253    02:01    0.00s  0.34s  0.00s w
     426}}}
     427
     428= 10. las =
     429
     430 * 我們可以用 last 查詢歷史登入的紀錄
     431{{{
     432ubuntu@ubuntu:~$ last
     433ubuntu   pts/0        192.168.0.253    Sat Jul  4 02:01   still logged in
     434ubuntu   pts/3        192.168.0.253    Sat Jul  4 01:59 - 02:00  (00:01)
     435jazz     pts/3        192.168.0.253    Sat Jul  4 01:58 - 01:58  (00:00)
     436...略...
     437}}}
     438 * 可加上 -n 參數,指定要觀看的個數
     439{{{
     440ubuntu@ubuntu:~$ last -n 2
     441ubuntu   pts/0        192.168.0.253    Sat Jul  4 02:01   still logged in
     442ubuntu   pts/3        192.168.0.253    Sat Jul  4 01:59 - 02:00  (00:01)
     443
     444wtmp begins Thu Mar 19 12:53:15 2009
     445}}}
     446 * 可加入使用者名稱,指定要觀看的使用者登入紀錄
     447{{{
     448ubuntu@ubuntu:~$ last jazz
     449jazz     pts/3        192.168.0.253    Sat Jul  4 01:58 - 01:58  (00:00)
     450jazz     pts/0        192.168.0.253    Sat Jul  4 01:23 - 01:23  (00:00)
     451... 略 ...
     452}}}
     453 * 可指定 TTY 名稱,觀看從特定 TTY 進來的使用者
     454{{{
     455ubuntu@ubuntu:~$ last pts/0
     456ubuntu   pts/0        192.168.0.253    Sat Jul  4 02:01   still logged in
     457ubuntu   pts/0        192.168.0.253    Sat Jul  4 01:23 - 02:01  (00:37)
     458jazz     pts/0        192.168.0.253    Sat Jul  4 01:23 - 01:23  (00:00)
     459ubuntu   pts/0        192.168.0.253    Sat Jul  4 01:22 - 01:23  (00:01)
     460}}}
     461
     462= 11. whoami =
     463
     464 * 有時候當你在主機裡有多個帳號,又有權限 su 或 sudo 這時候 whoami 可以幫你確認目前的身分
     465{{{
     466ubuntu@ubuntu:~$ whoami
     467ubuntu
     468ubuntu@ubuntu:~$ sudo whoami
     469root
     470}}}
     471
     472= 12. pwd / du / df / free =
     473
     474 * 我們可以用 pwd 顯示目前工作目錄
     475{{{
     476ubuntu@ubuntu:~$ pwd
     477/home/ubuntu
     478ubuntu@ubuntu:~$ cd temp
     479ubuntu@ubuntu:~/temp$ pwd
     480/home/ubuntu/temp
     481ubuntu@ubuntu:~/temp$ cd
     482ubuntu@ubuntu:~$
     483}}}
     484 * 我們可以用 du 查詢空間使用量
     485{{{
     486ubuntu@ubuntu:~$ du
     4874       ./temp
     4884       ./temp2
     48916      ./.ssh
     49052      .
     491}}}
     492 * 加上 -a 可顯示全部檔案(包含以 . 開頭的隱藏檔),加上 -h 可以用人看得懂的格式(K, M, G, T)顯示
     493{{{
     494ubuntu@ubuntu:~$ du -ah
     4954.0K    ./.profile
     496... 略 ...
     497}}}
     498 * 我們也可以用 df 來觀看整個系統的硬碟使用量。加上 -h 參數可以用人看得懂的格式(K, M, G, T)顯示
     499{{{
     500ubuntu@ubuntu:~$ df
     501Filesystem           1K-blocks      Used Available Use% Mounted on
     502/dev/sda1             19891060   2574416  16314192  14% /
     503varrun                  126536        48    126488   1% /var/run
     504varlock                 126536         0    126536   0% /var/lock
     505udev                    126536        40    126496   1% /dev
     506devshm                  126536         0    126536   0% /dev/shm
     507ubuntu@ubuntu:~$ df -h
     508Filesystem            Size  Used Avail Use% Mounted on
     509/dev/sda1              19G  2.5G   16G  14% /
     510varrun                124M   48K  124M   1% /var/run
     511varlock               124M     0  124M   0% /var/lock
     512udev                  124M   40K  124M   1% /dev
     513devshm                124M     0  124M   0% /dev/shm
     514}}}
     515 * 最後,要查詢系統的記憶體使用量,可以使用 free 指令,可加上 -k 或 -m 參數指定顯示單位
     516{{{
     517ubuntu@ubuntu:~$ free
     518             total       used       free     shared    buffers     cached
     519Mem:        253072      86472     166600          0       6140      26572
     520-/+ buffers/cache:      53760     199312
     521Swap:       915664      39472     876192
     522ubuntu@ubuntu:~$ free -k
     523             total       used       free     shared    buffers     cached
     524Mem:        253072      86488     166584          0       6140      26584
     525-/+ buffers/cache:      53764     199308
     526Swap:       915664      39472     876192
     527ubuntu@ubuntu:~$ free -m
     528             total       used       free     shared    buffers     cached
     529Mem:           247         84        162          0          5         25
     530-/+ buffers/cache:         52        194
     531Swap:          894         38        855
     532}}}