1 / 43

Chap 5 檔案系統管理

Chap 5 檔案系統管理. 鄧姚文 http://www.ywdeng.idv.tw. 大綱. 5-1 Linux 檔案系統架構 5-2 ext3fs 檔案系統結構 5-3 建立 ext3 檔案系統 5-4 檔案系統基本指令操作 5-5 檔案權限基本觀念 5-6 I/O 重新導向及管線 5-7 指令與圖形工具的迷失. 5-1 Linux 檔案系統架構. 檔案系統可分為二種類型 共用與非共用檔案 變動與固定檔案. Linux 檔案名稱. 最長可允許 256 個字元 沒有「副檔名」的觀念 檔案名稱區分大小寫.

hunter
Download Presentation

Chap 5 檔案系統管理

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chap 5 檔案系統管理 鄧姚文 http://www.ywdeng.idv.tw

  2. 大綱 • 5-1 Linux檔案系統架構 • 5-2 ext3fs檔案系統結構 • 5-3 建立ext3檔案系統 • 5-4 檔案系統基本指令操作 • 5-5 檔案權限基本觀念 • 5-6 I/O重新導向及管線 • 5-7 指令與圖形工具的迷失

  3. 5-1 Linux檔案系統架構 • 檔案系統可分為二種類型 • 共用與非共用檔案 • 變動與固定檔案

  4. Linux檔案名稱 • 最長可允許256個字元 • 沒有「副檔名」的觀念 • 檔案名稱區分大小寫

  5. 5-2 ext3fs檔案系統結構 • ext3fs組成 • Boot Block 開機程式區塊 • Super Block 紀錄檔案系統配置 • i-node(Index Node) • Data Block 資料區塊

  6. ext3fs檔案系統優點 • 有效性(Availability) • 日誌(Journal) • 資料完整性(Integrity) • 資料存取速度 • 易於轉移

  7. 5-3 建立ext3檔案系統 • 以fdisk分割磁碟 • 以mkfs格式化ext3檔案系統

  8. 5-4 檔案系統基本指令操作 • 顯示目前工作目錄一pwd (Print Working Directory) • 列出目錄內容一ls (List) • 目錄切換一cd(Change Directory) • 檔案的複製/移動/刪除一cp/mv/rm • 目錄的新增/刪除一mkdir/rmdir • 建立連結檔案一ln

  9. 5-4 檔案系統基本指令操作 • 檢視檔案內容一cat • 一頁一頁顯示檔案內容一more • 互動式操作顯示檔案內容一less • 辨識檔案類型一file • 輸出檔案內容前面與後面的部份一head和tail

  10. 顯示檔案與目錄 • 列出目錄中的檔案:ls • -a:all • -A:almost-all, do not list implied . and .. • -l:use a long listing format • -d:list directory entries instead of contents • -F:append indicator (one of */=@|) to entries • -R:list subdirectories recursively • 在 Linux 檔案系統中,任何字母的大小寫都被認為是相異的(case sensitive)

  11. 萬用字元 • *零個或多個字,任何字都 Match • ?一個字,任何字都 Match • [ ] 列舉 • 例如,[A,B,C]* match 任何以 A 或 B 或 C 開頭的檔名,[a-z]* match 任何以英文字母開頭的檔名 • [^a-z]* match 任何不以英文字母開頭的檔名 • ls .?*列出所有檔名開頭有一個句點的檔案

  12. 檔案操作 • 檢視檔案類型:file

  13. $ file file.c file /dev/hda file.c: C program text file: ELF 32-bit LSB executable, Intel 80386, version 1, dynamically linked, not stripped /dev/hda: block special $ file -s /dev/hda{,1,2,3,4,5,6,7,8,9,10} /dev/hda: x86 boot sector /dev/hda1: Linux/i386 ext2 filesystem /dev/hda2: x86 boot sector /dev/hda3: x86 boot sector, extended partition table /dev/hda4: Linux/i386 ext2 filesystem /dev/hda5: Linux/i386 swap file /dev/hda6: Linux/i386 swap file /dev/hda7: Linux/i386 swap file /dev/hda8: Linux/i386 swap file /dev/hda9: empty /dev/hda10: empty

  14. 檔案操作(續) • 刪除檔案:rm • -i:prompt before any removal • -d:unlink directory, even if non-empty (super-user only) • -r, -R:remove the contents of directories recursively • -f:force, never prompt • -v:verbose explain what is being done

  15. 檔案操作(續) • 複製檔案:cp • -b:backup, make backup before removal • -f:force, remove existing destinations, never prompt • -i:interactive, prompt before overwrite • -R:recursive, copy directories recursively

  16. 檔案操作(續) • 檔案移動、改名:mv • -i:interactive, prompt before overwrite • -f:force, remove existing destinations, never prompt • -v:verbose, explain what is being done

  17. 檔案操作(續) • 建立連結:ln • -b:backup, make a backup of each existing destination file. The backup suffix is ~. • -d, -F:directory, hard link directories (super-user only) • -f:force, remove existing destination files • -i:interactive, prompt whether to remove destinations • -s:symbolic, make symbolic links instead of hard links

  18. 檔案操作(續) • 顯示檔案內容:cat • -E:show-ends, display $ at end of each line • -n:number, number all output lines • -s:squeeze-blank, never more than one single blank line • -T:show-tabs, display TAB characters as ^I

  19. 檔案操作(續) • 分頁顯示檔案內容:more, less • SPACE:Display next screen • RETURN:Display next line of text • q or Q or INTERRUPT:Exit. • F:Skip forward a screenfuls of text • b or ^B:Skip backwards a screenfuls of text. • /pattern:Search for 1st occurrence of regular expression • n:Search for next occurrence of last r.e. • !<cmd> or :!<cmd>:Execute <cmd> in a subshell

  20. 磁碟空間使用狀況 • du - estimate file space usage • -b:print size in bytes • --block-size=SIZE:use SIZE-byte blocks • -k :print size in kilobytes • -m:megabytes, like --block-size=1048576 • -s:summarize, display only a total for each argument • -h:以比較友善的方式顯示結果

  21. 磁碟空間使用狀況(續) • df - report filesystem disk space usage • --block-size=SIZE:use SIZE-byte blocks • -h:human-readable, print sizes in human readable format (e.g., 1K 234M 2G) • -H:likewise, but use powers of 1000 not 1024 • -k :print size in kilobytes • -m:megabytes, like --block-size=1048576

  22. 5-5 檔案權限基本觀念 • 檔案存取權限 • 可讀取(r,Readable) • 可寫入(w,Writable) • 可執行(x,eXecute) • 無權限(-)

  23. Permission, Owner, and Group [ywdeng@dns ywdeng]$ ls -alF total 2064 drwx------ 2 ywdeng ywdeng 4096 Aug 26 10:43 . drwxr-xr-x 8 root root 4096 Aug 26 09:54 .. -rw-r--r-- 1 ywdeng ywdeng 3785 Aug 26 09:54 .Xdefaults -rw-r--r-- 1 ywdeng ywdeng 24 Aug 26 09:54 .bash_logout -rw-r--r-- 1 ywdeng ywdeng 248 Aug 26 09:54 .bash_profile -rw-r--r-- 1 ywdeng ywdeng 1273 Aug 26 09:54 .bashrc -rwxr-xr-x 1 root root 13488 Dec 23 1999 MacRegister* lrwxrwxrwx 1 root root 7 Aug 23 00:40 adduser -> useradd* -rwxr-xr-x 1 root root 132328 Dec 9 1999 afpd* -rwxr-xr-x 1 root root 1043 Dec 9 1999 am-eject* -rwxr-xr-x 1 operator disk 43965 Dec 18 1999 amadmin* -rwxr-xr-x 1 root mail 18316 Dec 10 1999 ipop3d* -rwsr-sr-x 1 root mail 330468 Dec 17 1999 sendmail*

  24. 檔案權限修改一chmod • 以數字表示法修改存取權限 • 以文字表示法修改存取權限

  25. 檔案與目錄權限 • 可讀取(r):讀取檔案或列出目錄中的內容 • 可寫入(w):可以更改、刪除檔案,或在目錄中新增、刪除和修改檔案。 • 可執行(x):檔案可以執行,或可以使用 cd 指令進入目錄 • 無權限(-):沒有存取權限

  26. 檢視 ls -l 的輸出 符號連結 Symbolic Link 擁有者 群組 目錄 chmod +t 或 chmod 1777的結果,任何人都可以在目錄內建立檔案,只有檔案擁有者可以刪除 第三組 rwx 是其他帳號(others)的權限 開暫存檔專用的目錄 第二組 rwx 是同群組帳號(group)的權限 第一組 rwx 是檔案擁有者的權限

  27. chmod [ugoa...][[+-=][rwxst...]...] files 檔案權限 Permission • Change mode:chmod • -v:verbose, output a diagnostic for every file processed • -R:recursive, change files and directories recursively • u: the owner • g: users in the group • o: users not in group • a: all users • r: read • w: write • x: execute (or access for directories) • s: set user or group ID on execution • t: save program text on swap device

  28. 檔案權限 Permission • 文字表示:rwx數字表示:1112 = 710 • 文字表示:rw-數字表示:1102 = 610 • 文字表示:r-x數字表示:1012 = 510 • 文字表示:r--數字表示:1002 = 410

  29. 檔案權限 Permission • 除去其他帳號(other)全部的權限:$ chmod 770 a.out或$ chmod o-r,o-w,o-x a.out • 除去同群組(group)寫與執行的權限:$ chmod 740 a.out或$ chmod g-w,g-x a.out

  30. 變更檔案與目錄擁有者一chown • Change Owner:chown • -R:recursive, operate on files and directories recursively • -v:verbose, explain what is being done • Change Group:chgrp • -R:recursive, operate on files and directories recursively • -v:verbose, explain what is being done

  31. 保留群組設定 chmod 2770 • 讓同群組的帳號都有完整的權限 • 在目錄內建立檔案或目錄時,擁有者是建立者本身,但繼承頂層目錄的群組 • 確保同一群組的使用者可以互相存取對方的檔案與目錄

  32. 指定檔案的預設權限遮罩一umask • 新建檔案的預設權限是 0666 • 新建目錄的預設權限是 0777 • 若 umask 是 0002 • 新建檔案權限 0666 – 0002 = 0664-rw-rw-r-- • 新建目錄權限 0777 – 0002 = 0775drwxrwxr-x

  33. 5-6 I/O重新導向及管線 • Linux標準輸入及輸出(I/O) • 標準輸入(Standard Input,stdin) • 標準輸出(Standard Output,stdout) • 標準錯誤輸出(Standard Error,stderr) • 輸出重新導向指令 > 輸出檔案指令 >> 輸出檔案(附加) • 輸入重新導向指令 < 輸入檔案

  34. 管線 pipe • 將其他程式的輸出結果,直接導向到另一個程式當成輸入資料 • 程式A | 程式B • 每一支程式只做一件事情 • 寫程式時,專心只把這件事情做到完美 • 用小積木堆積成大城堡

  35. 管線範例: • 列出系統中已經安裝的 kernel 套件,依照版本號碼:# rpm -qa | grep kernel | sort • 將帳號依照 uid 從小排到大:# cat /etc/passwd | sort -t ":" -k 3 -n

  36. 5-7指令與圖形工具的迷失 • 實體上的限制 • 管理上的深度 • 應避免的錯誤觀念

  37. 練習 • 以下列指令轉換身份成為管理員$ su -(輸入 root 密碼) • 以下列指令建立帳號 student2# adduser -G student student2 • 以下列指令建立目錄# mkdir /home/work • 以下列指令變更目錄擁有者# chown student /home/work# chgrp student /home/work

  38. 練習(續) • 以下列指令變更目錄權限# chmod 770 /home/work • 以下列指令轉換身分成為 student# su - student • 以 student 的身分執行下列指令$ cd /home/work$ dd if=/dev/zero of=test1 count=1024$ls -al

  39. 練習(續) • 以下列指令轉換身份成為管理員$ su - • 以下列指令轉換身分成為 student2# su - student2 • 以 student2 的身分執行下列指令$ cd /home/work$ dd if=/dev/zero of=test2 count=1024$ ls -al • 紀錄畫面顯示 ls -al 的內容

  40. 練習(續) • 以 student2 的身分執行下列指令刪除檔案 test1$ rm test1 • 問題一:刪除成功否? • 為什麼 student2 可以刪除 student 的檔案?

  41. 練習(續) • 以下列指令轉換身份成為管理員$ su - • 以下列指令變更目錄權限# chmod 2770 /home/work# chmod +t /home/work • 以下列指令轉換身分成為 student# su - student • 以 student 的身分執行下列指令$ cd /home/work$ dd if=/dev/zero of=test1 count=1024$ ls -al

  42. 練習(續) • 以下列指令轉換身份成為管理員$ su - • 以下列指令轉換身分成為 student2# su - student2 • 以 student2 的身分執行下列指令$ cd /home/work$ dd if=/dev/zero of=test3 count=1024$ ls -al • 紀錄畫面顯示 ls -al 的內容

  43. 練習(續) • 以 student2 的身分執行下列指令刪除檔案 test1$ rm test1 • 問題二:刪除成功否? 為什麼? • 問題三:student2 兩次以 dd 產生的檔案(test2 和test3),群組是否相同? 為什麼?

More Related