320 likes | 446 Views
第六章. 檔案系統. 定義. 普通檔案 檔案系統. UNIX 檔案系型態. 普通檔案 目錄檔案 裝置檔案 (device file) 符號檔案 (symbolic link file). 普通檔案. 文字資料檔、程式 text file 、 binary file cat od mv 、 cp 、 ln 、 rm. 目錄檔案. home directory current directory working directory pwd 、 cd 、 mkdir 、 rmdir. 裝置檔案. 存取硬體裝置的方式、 /dev
E N D
第六章 檔案系統
定義 • 普通檔案 • 檔案系統
UNIX檔案系型態 • 普通檔案 • 目錄檔案 • 裝置檔案(device file) • 符號檔案(symbolic link file)
普通檔案 • 文字資料檔、程式 • text file 、 binary file • cat • od • mv 、 cp、ln 、rm
目錄檔案 • home directory • current directory • working directory • pwd 、cd 、mkdir 、rmdir
裝置檔案 • 存取硬體裝置的方式、 • /dev • device file 分為 • major device 指device的驅動程式 • minor device 指實際的device
File and directory Names • UNIX file names may comprise from the following characters, in any combination: • A to Z • a to z • 0 to 9 • Period(.), underscore(_), comma(,) • 有些UNIX系統限製檔名的長度不可超過14個字元 • 同一目錄裡檔名必須是唯一的
File and directory Names • The file name should not contain space or any of the following special characters: & * \ | [ ] { } $ < > ( ) # ? ‘ “ “ / ; ^ ! ~ %
檔案和目錄的萬用字元 • * 代替任何數量字元 • ? 代替任何單個字元 • [] 代替字元範圍 • chap[1-3] • chap1 chap2 chap3
階層式檔案系統 • 根目錄 / • 樹狀結構 • 主目錄(home directory) • 登入系統後所在目錄 • 存放每次登入之後所要用的檔案 • 存放個人檔案 • 工作目錄(working directory) • 目前工作的目錄 • 除非特別設定,否則任何命令只對你的工作目錄中的檔案有作用
The UNIX File Tree • bin • This directory contains the software for the shell and the most commonly used UNIX command. • bin is short for “binary”. • dev • The name is short for “device”; this directory holds the software needed to operate peripheral devices such as terminals and printers.
The UNIX File Tree • etc • Various administrative files are kept in this directory, including the list of users that are authorized to use the system, as well as their password. • home • Users’ home directories are kept here. • tmp • temporary files are often kept in this directory.
The UNIX File Tree • usr • Some versions of UNIX keep user’s home directories in usr; others keep such useful things as the on-line manual pages here. • var • Files containing information that varies frequently are kept in the var directory. An example would be user mailboxes, which are typically found in the /var/mail directory.
路徑名稱 • A pathname is a address that shows the file’s position in the file system. • 為了標名一個檔案或目錄的位置 • 路徑名稱就像目錄或檔案的地址
絕對路徑Absolute Pathnames • an absolute pathname shows how to find a file, beginning at the root. • 以/字元開始,從根目錄開始 • ~ absolute pathname of your home directory • ~jack absolute pathname of jack’s home directory • 如果要執行的程式不在PATH變數所設定的路徑之下,就必須使用絶對路徑表示法 /usr/local/bin/less
相對路徑 Relative Pathnames • A relative pathname shows how to find a file, beginning at your working directory. • 從工作目錄開始 • . • 代表工作目錄 • .. • 代表父母目錄(parent directory)
改變你的工作目錄 • 列出你的工作目錄的絕對路徑 • pwd • 由你的工作目錄切換到任何目錄 • cd pathname • cd /etc • cd 回到你的主目錄
管理檔案 • mkdir dir建立目錄 • cp old-file new-file複製檔案 • mv file dir移動檔案 mv file1 file2 更名 • rm file刪除檔案 • rmdir dir清除目錄 • pwd 顯示目前工作目錄的路徑
Copying File • cp pathname1 pathname2 • cp chap1 unit1 • 若unit1不存在,則先被建立,再複製內容 • 若unit1存在,則覆蓋 • 若unit1為一目錄 • cp chap1 unit1 = cp chap1 unit1/chap1
Copying File • 利用目錄為標的 cp /home/juliet/.profile .profile cp /home/juliet/.profile . 標的為目前目錄 cp chap1 chap2 chap3 progs progs 必須是目錄 cp chap* progs • 互動式複製 cp –i chap1 unit1 • 遞迴式複製 cp –r progs new progs
remove file • rm chap1 chap2 • rm chap* • rm * • 互動式複製 rm –i chap1 chap2 • 遞迴式複製 rm –r * • 強迫刪除 rm –f chap3 若具有防寫屬性也會被刪除
rename or move file • rename file mv chap1 man1 • move file mv chap1 chap2 chap3 progs progs 必須是個目錄
cat 顯示與建立檔案(ch1) • 顯示檔案內容 • cat filename • 連接數個檔案 • cat chat1 chat2 > book • cat chat[12345] > book • cat chat 3 chapt1 > newchapters • cat chat[31] > newchapters
cat (catenate) • 創造空檔案 cat /dev/null > empty • 編輯檔案 • 以(ctrl -d )結束 • cat > msforbob Victor from IBM called. New machine will arrive on Tuesday. ^d
lp-列印檔案(System V) • lp chap01 (列印到預設印表機) • lp –dlaser chap1 指定列表機laser • lp –t “First Chapter” chap1 加印表頭 • lp –n3 –m chap1 列印3份並mail通知 • 與pr配合使用 ls -l /bin/usr | pr| lp (列印到預設印表機) 預設印表機可在.cshrc用PRINTER設定 ls -l /bin/usr | pr | lp -d sp1 (列印到預設印表機) • lpstatprints information about lp查詢
lpr 、lpq 、lprm (Linux、BSD) • lpr -Pprinter filename lpr -Psp1 chapt1 (由印表機sp1列印檔案) • lpq –Pprinter lprq -Psp1 (查詢印表機SP1的列印工作) • lprm –Pprinter 刪除 print job lprm -Psp1 jobid
磁碟區塊查詢 df 列出每個目錄及其子目錄所使用之磁碟空間,單位為512- byte的區塊 檔案及目錄的用量 du –a 指定目錄總使用量 du -s 個人磁碟空間查詢 mis4k showquota 空間查詢