Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 6 Linux 檔案權限與目錄配置 VBird 2005/08/03

Similar presentations


Presentation on theme: "Chapter 6 Linux 檔案權限與目錄配置 VBird 2005/08/03"— Presentation transcript:

1 Chapter 6 Linux 檔案權限與目錄配置 VBird 2005/08/03
Linux基礎--Linux 檔案權限與目錄配置

2 Linux基礎--Linux 檔案權限與目錄配置
課程目標 認識 Linux 的群組概念 Linux 檔案權限概念 Linux 目錄配置狀況 Linux 支援的 filesystem 類型 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

3 Linux基礎--Linux 檔案權限與目錄配置
內容 Linux 的使用者與群組 Linux 檔案屬性介紹 簡易的檔案、目錄操作指令 Linux 檔案權限修改 Linux 目錄權限的意義 Linux 系統檔案目錄結構 Linux 支援的檔案系統 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

4 Linux基礎--Linux 檔案權限與目錄配置
關於身份: VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

5 Linux基礎--Linux 檔案權限與目錄配置
關於身份: 身份分類: user (owner) 王大毛 group 王大毛家 others 張小豬 每個檔案均會對上述三種類別身份進行權限設定! 群組 (group) 的主要用意: 將帳號歸類,有助於類似專案開發; 每個使用者均可加入多個群組。 關於更多的使用者與群組概念,後續再繼續談。 關於身份類別: 系統管理員: root 一般帳號: 系統帳號 (用於系統帳號的工作) 一般使用者帳號 (用於一般使用者登入用。) VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

6 Linux基礎--Linux 檔案權限與目錄配置
利用 ls -l 列出檔案的完整項目 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

7 Linux基礎--Linux 檔案權限與目錄配置
關於檔案屬性的項目 (共 個) VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

8 Linux基礎--Linux 檔案權限與目錄配置
關於檔案屬性的項目:第 1 個檔案類型 [-]: Regular file: 例如 ASCII, texts, binary file,還有以 . 開頭的隱藏檔 [d]: Directory: 至少包含兩個入口目錄,即: [c] 或 [b]: Device files:幾乎都位於 /dev 底下 包含 character device 與 block device [l]: Links: 主要指 symbolic link [s]: Sockets:通常用於 services ,透過協定存取本機 [p]: FIFOs:通常用於本機程序間交換資料的過程 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

9 Linux基礎--Linux 檔案權限與目錄配置
關於檔案屬性的項目:第 2-10 個檔案權限 共分成三組,分別是: user (owner) group other 每組有三種權限,分別是: Read Write eXecute 誰可不可以執行這個檔案,與 x 權限有關!與副檔名無關。 問: -rwxr-xr-- 代表的意義為何? VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

10 Linux基礎--Linux 檔案權限與目錄配置
關於其他資料: 第二欄:佔用的 inode 數量,與 hard line 及連結點 (例如目錄) 有關; 第三欄:該檔案的所屬使用者; 第四欄:該檔案的所屬群組; 第五欄:檔案的容量大小; 第六欄:檔案的建檔日期或最近內容修改日期 稱為 modification time 或 mtime, 若為亂碼,則以 LANG_TIME=en 來設定語系; 第七欄:檔案名稱 若檔名開頭為 . ,則為『隱藏檔』; 可以使用 ls -al 那個 a 參數來列出隱藏檔 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

11 Linux基礎--Linux 檔案權限與目錄配置
簡易的檔案、目錄操作指令 目錄變換指令: cd cd /root cd .. cd /home/ cd /var/spool 檔案複製指令: cp cd /tmp cp /etc/passwd . 檔案查閱指令:ls ls -l ls -al VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

12 Linux基礎--Linux 檔案權限與目錄配置
修改檔案擁有者 (owner/user) chown username filename chown username.groupname filename chown username:groupname filename 為何建立帳號時,建議不要以 . 或數字來作為帳號? 練習: 將 /etc/passwd 複製到 /tmp 觀察 /tmp/passwd 的 user 與 group 權限 將 /tmp/passwd 的 user 與 group 修改為 bin 與 users 觀察 /tmp/passwd 的 user 與 group 權限 將 /tmp/passwd 的 user 修改為 vbirdking 說明上述指令是否能夠成功的原因為何? VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

13 Linux基礎--Linux 檔案權限與目錄配置
修改檔案的群組 (group) chgrp groupname filename 練習: 將 /etc/crontab 複製到 /tmp 觀察 /tmp/crontab 的檔案所屬群組; 將 /tmp/crontab 群組改為 users 觀察 /tmp/crontab 的檔案群組 將 /tmp/crontab 群組改為 vbirdking 說明為何上述指令成功與否的原因? VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

14 Linux基礎--Linux 檔案權限與目錄配置
修改檔案權限: chmod (符號法) 各種身份代表符號: user/owner : u group g others o 全部的身份: a 設定權限的方式 + 加入某種權限,而不管其他權限為何; - 拿掉某種權限,而不管其他權限為何; = 設定『就是要這樣的權限』的意思。 三種權限符號: r read w write x execute VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

15 Linux基礎--Linux 檔案權限與目錄配置
基礎範例: 將剛剛建立的 /tmp/passwd 修改成為 user 與 group 均可寫入 chmod ug+w /tmp/passwd 將上述的檔案權限,拿掉 other 可讀的權限: chmod o-r /tmp/passwd 將上述檔案權限修改成為 -rwxr-xr-- chmod u=rwx,g=rx,o=r /tmp/passwd 練習 將 /tmp/crontab 修改權限成為 -rwxrw-r- - 全部加上 x 權限 減去 group 與 others 的 x 權限 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

16 Linux基礎--Linux 檔案權限與目錄配置
修改檔案權限: chmod (數字) 分成三組身份計分,user/group/others 分數計算: r=4, w=2, x=1 基礎範例: 修改 /tmp/passwd 權限成為 -rwxrw-r- - chmod 764 /tmp/passwd 為什麼底下的指令是『危險而可怕的』 chmod -R 777 / 因為系統很多檔案是隱密的(/etc/shadow),若被改成大家都能看的屬性,危險性會提高! VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

17 Linux基礎--Linux 檔案權限與目錄配置
關於目錄權限說明 r (read contents in directory) 表示讀取目錄結構清單的權限 w (modify contents of directory) 表示異動該目錄結構清單的權限 即在該目錄內如下權限 建立新的檔案、目錄 刪除已經存在的檔案、目錄(不論該檔案屬於誰的!) 更名已經存在檔案、目錄的名稱 搬移該目錄內的檔案、目錄位置 x (access directory) 表示進入至該目錄的權限 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

18 Linux基礎--Linux 檔案權限與目錄配置
幾個特殊目錄: . 代表『目前所在目錄』 .. 代表『上層目錄』 ~ 代表目前使用者的『家目錄』 基礎範例: 如何查詢目前所在目錄的權限? ls -al /root 的權限為何?代表的意義為何? 如果您的一般身份使用者 dmtsai 在他的家目錄內有一個檔案,屬性為: -rwx root root xxxx thefile ,那請問, dmtsai 能否刪除該檔案? VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

19 Linux基礎--Linux 檔案權限與目錄配置
Linux 的檔案類型(file type)與檔名沒有絕對關係; Linux 的附檔名僅作為『提示』使用者之用; Linux 的檔名應盡量避免底下這些特殊字元: *, ?, >, <, ;, &, !, [, ], |, \, ‘, “, `, (, ), {, } 等 檔名開頭盡量不要以 + 或 - 開始檔名; .filename ,亦即檔名前面有小數點 . ,為隱藏檔。 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

20 Linux基礎--Linux 檔案權限與目錄配置
所有的 Linux distribution 當中,為何資料放置的目錄大多大同小異? 因為均需符合 Filesystem Hierarchy Standard (FHS) 的規範 網址說明: VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

21 Linux基礎--Linux 檔案權限與目錄配置
File system Hierarchy Standard (FHS) 主要談論各目錄的作用,與規範的遵循 定義出 / 需要的目錄 還有 /usr 與 /var 底下的第二層目錄所需之目錄 關於目錄樹(directory tree) The tree is not limited to a local partition. It begins at the root. A file in this directory tree is uniquely defined by its path. 關於路徑 (pathway) relative :相對於目前目錄的路徑寫法 absolute:一定由 / 開始寫(定義較為清楚!) 路徑最長可達 4096 個字元長度(characters)(檔名可達 255)。 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

22 Linux基礎--Linux 檔案權限與目錄配置
基礎範例: 請前往 /var/spool/mail 當中; 請查詢上層目錄所有的檔案內容; 如何去到 /var/spool/cron 呢?(寫出兩種方式) 如何執行我知道 ifconfig 這個指令在 /sbin 底下,該如何正確的執行這個指令? 請查詢 / 底下有哪些目錄?在 / 底下,是否還有 .. ?意義是? VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

23 Linux基礎--Linux 檔案權限與目錄配置
VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

24 Linux基礎--Linux 檔案權限與目錄配置
第一層目錄的規範: /  Root Directory 最頂層的目錄,底下建議僅接目錄,不要有檔案 系統開機時,為第一個被掛載(mount)的 partition 所有開機時會使用到的程式,都應該要被包含在這個 partition 當中 底下的目錄務必要接在 / 的 partition 內,不可獨立 /bin (一般執行檔) /etc (設定檔放置目錄) /dev (裝置檔案放置) /lib (一些模組,驅動程式放置) /sbin (一些 root 會使用到的指令) VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

25 Linux基礎--Linux 檔案權限與目錄配置
第一層目錄的規範(續): /bin, /usr/bin, /usr/local/bin (essential binaries for use by all users) 使用者可執行的 binary 檔案 /bin 不可與 / 的 partition 分開,且裡面含有系統執行最重要的執行檔,例如 /bin/bash, /bin/cat, /bin/cp, /bin/mount, /bin/rm 等等。 /sbin, /usr/sbin, /usr/local/sbin (System Binaries) 系統管理員可執行的指令 本目錄下的指令通常也可以讓 normal user 執行,但僅能查閱資料,無法修改與設定。例如: /sbin/fdisk, /sbin/fsck, /sbin/init, /sbin/mkfs 等。 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

26 Linux基礎--Linux 檔案權限與目錄配置
第一層目錄的規範(續): /lib, /usr/lib, /usr/local/lib (Libraries) 程式互相呼叫的函式庫放置目錄 一般是 share libraries 放置的所在。share libraries 是程式執行中才會呼叫的函式庫。 /lib/modules 則是核心 (kernel) 函式庫放置的目錄 /etc (Configuration files) 系統組態設定檔放置目錄 normal user 可查閱檔案內容,但不可修改本目錄下檔案 幾乎所有的檔案都是 ASCII 格式 不可有執行檔放置在此 (FHS 的規範) 幾個重要檔案與目錄: /etc/inittab, /etc/init.d/, /etc/rc.d/, /etc/modules.conf, /etc/X11/, /etc/fstab, /etc/sysconfig/* VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

27 Linux基礎--Linux 檔案權限與目錄配置
第一層目錄的規範(續): /dev/ (Device Files) 任何硬體、周邊裝置都是一個檔案並放置於此 透過存取此目錄下的檔案,即可對該設備存取 Character-oriented:周邊設備,如 printer, mouse Block-oriented:存取設備,如軟碟、硬碟 核心對某裝置的存取是透過每種裝置的: major device number:裝置的驅動程式(driver)與核心管道(channel)溝通的代碼 minor device number:同一種類型(相同的 major device number),用來區分不同裝置的代碼 可透過 mknod 來建立上述 number 與裝置的對應! 重要的裝置: /dev/null, /dev/tty1-6, /dev/ttyS*(serial), /dev/lp*(parallel), /dev/hd*, /dev/sd* VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

28 Linux基礎--Linux 檔案權限與目錄配置
第一層目錄的規範(續): /boot/ 開機過程中所需要的檔案,例如 loader 的設定檔 系統核心檔案 (kernel) System map 與 MBR 等相關資訊檔案 /initrd (不一定存在) 開機過程中的暫存掛載目錄 /opt/ (Application directory) 本主機額外安裝軟體的目錄 /tmp (temporary area) 暫存檔放置目錄,任何人均能存取 /lost+found VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

29 Linux基礎--Linux 檔案權限與目錄配置
第一層目錄的規範(續): /home/ (user directory) 一般使用者的家目錄 幾個常見的目錄: 家目錄代號:~, ~account 本目錄代號: ./ 上層目錄代號: ../ /root/ (home directory of administrator) 系統管理員 (root) 的家目錄 /srv/ (data directories for services) 一些服務啟動後,記錄其資料的目錄,例如 /srv/www, /srv/ftp 等等 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

30 Linux基礎--Linux 檔案權限與目錄配置
第一層目錄的規範(續): /proc/ (Process files) 虛擬檔案系統,放置系統核心、行程資訊、周邊裝置的資訊等檔案 本目錄下所有檔案都在記憶體中,不會佔去硬碟容量 舉例來說,init 在 /proc/1/ 底下: 查閱該目錄:ls /proc/1/ 查閱該行程的狀態: cat /proc/1/status 其他重要檔案 /proc/cpuinfo, /proc/dma, /proc/interrupts, /proc/ioports, /proc/filesystems, /proc/modules, /proc/net/*, /proc/partitions, /proc/sys/*, /proc/version /mnt 與 /media 預設的暫時掛載裝置的掛載點如 CD, floppy VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

31 Linux基礎--Linux 檔案權限與目錄配置
/usr/ (FHS 針對第二層目錄的規範) 系統主要程式、圖形介面檔案、額外的函式庫、本機主機安裝的軟體、共享檔案與文件檔案等。 重要的目錄: /usr/{bin,sbin}:程式檔案放置目錄 /usr/lib:函式庫檔案放置目錄 /usr/X11R6:X Window System 放置目錄 /usr/include:c/c++ header 檔案放置目錄 /usr/src:Linux 系統相關程式碼放置目錄 /usr/share:共享檔案放置目錄 /usr/share/doc:文件檔案 /usr/share/man:manpage 文件檔案 /usr/local/:本地主機自行安裝的軟體,也可放置到 /opt/ /usr/src/linux:Linux Kernel Source 放置目錄 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

32 Linux基礎--Linux 檔案權限與目錄配置
/var/ (FHS 針對第二層目錄的規範) 當系統執行中,常態性變動檔案放置目錄 重要檔案與目錄 /var/log:系統與程式紀錄檔案放置目錄 /var/lib:程式本身執行期所需要使用的資料檔案放置目錄 /var/cache:程式檔案暫存快取檔案放置目錄 /var/run:程式執行期本身 pid 資訊放置目錄 /var/spool:mail、news、printing 等 spool 檔案相關檔案放置目錄(queues 的檔案) /var/spool/mail:使用者信件放置目錄 /var/spool/mqueue:等待寄出信件放置目錄 /var/spool/news:news 文章檔案 /var/spool/cron:使用者排程設定資訊檔案放置目錄 /var/lock/:一些被 lock 住的裝置,避免被重複使用 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置

33 Linux基礎--Linux 檔案權限與目錄配置
MSDOS, vfat ext2, ext3, reiserfs, XFS iso9660 所有可支援的 filesystem 在 /lib/modules/`uname -r`/kernel/fs 當中。 Linux 檔案的讀取方式: 直接透過 Virtual Filesystem Switch 讀取底層的硬碟資料。 VBird (2005/08/03) Linux基礎--Linux 檔案權限與目錄配置


Download ppt "Chapter 6 Linux 檔案權限與目錄配置 VBird 2005/08/03"

Similar presentations


Ads by Google