Next Previous Contents

3. ระบบ files และ directories ใน Unix

ระบบ unix เอง มีอะไรๆหลายๆอย่างที่แตกต่างไปจากระบบของ mikro$ หนึ่งในส่วนที่แตกต่างมาก(ถึงมากที่สุด) คือเรื่องของระบบ ไฟล์ ในที่นี้จะกล่าวถึง directory structure แค่เบื้องต้น ถ้ามีโอกาส จะกลับมาพูดถึงอีกรอบ

3.1 เครื่องมือทำงานกับไฟล์

3.2 โครงสร้างพื้นฐานของ directory

/
|-- bin
|-- boot
|-- data
|-- dev
|-- etc
|-- home
|-- lib
|-- mnt
|-- opt
|-- proc
|-- root
|-- sbin
|-- tmp
|-- usr
`-- var

ในแต่ละ directory จะ แบ่งไว้เพื่อ เก็บ file ต่างๆกัน ตามลักษณะ และจุดประสงค์ของ file กลุ่มน้นๆ และทุกๆ directory จะต้องอยู่ภายใต้ directory ใดๆอันนึง ซึ่งจะมี directory บนสุดอยู่ directory เดียวคือ root directory (/) ในแต่ละ directory จะประกอบไปด้วย file และ directory หรืออาจจะเป็น directory เปล่า ไม่มีอะไรอยู่ข้างในก็ได้ แต่มี file (directory) อยู่ ๒ ชนิดที่จะต้องมีอยู่ในทุกๆ directory คือ './' และ '../'

  bin = binary เก็บ execable binary file พื้นฐานทั่วไป
  boot เก็บ ไฟล์ที่เกี่ยวข้องกับการ boot ระบบ (optional)
  dev = device เก็บ file เพื่อใช้ access device
  etc = et cetera เก็บ ไฟล์ configuration ทั่วๆไป (general used) ในระบบ
  home home directory ของแต่ละ user
  lib = library เก็บ library ของระบบเช่น system modules, security lib
  mnt = mount เก็บ foo directory เพื่อ mount disk (optional)
  opt = optional เก็บ pre-loaded s/w
  proc = process เก็บข้อมูลเกี่ยวกับ ระบบ และ process ี่กำลังรันนิ่ง
  root = root home directory
  sbin = superuser binary เป็น executable binary ของกลุ่ม superuser
  tmp = temporary 
  usr = user เก็บไฟล์สำคัญๆหลายอย่างเช่น library, execuable bianry, ฯลฯ ที่สามารถแชร์กันภายใน user ต่างๆได้
  var = variables เก็บ spooling, log, message files

3.3 การ mount disk

ในระบบ unix จะไม่มีระบบ drive lebel เหมือนในระบบของ mikrosoft window$ ถ้าจตะ aaccess disk partition จะต้องทำการ mount เข้ามาไว้ใน directory ว่าง ซะก่อน และ Linux เอง support File System หลายแบบมาก เวลาจะ mount บางทีอาจจะต้องบอก FS type ด้วยตัวอย่างการ mount

 $ mount -t vfat /dev/fd0 /mnt/floppy
 เป็นการ mount (do$) floppy disk ไว้ที่ directory /mnt/floppy
 $ mount -t ext2 /dev/hda5 /mnt/home
 เป็นการ mount logical partition แรกของ hd ในเส้น primary ไว้ยัง directory สำหรับ user (/home)
 $ mount 
 
 ถ้าเราไม่ ส่ง arg เข้าไปเลย mount จะส่งข้อมูลของ partition ที่ถูก mount ทั้งหมดออกมาแทน

3.4 การ link

ในการ link ไฟล์หรือ directory สามรถทำได้ด้วยคำสั่ง ln การ Link ในระบบ unix แบ่งเป็น ๒ อย่างคือ symbolic (soft) link และ hard link ความแตกต่างของการ link ทั้ง ๒ คือ symbolic link จะคล้ายๆกับ shortcut ในระบบของ mikro$oft window$ ส่วนของ hard link จะเป็นการ link ที่ทั้ง ๒ ไฟล์ map ตำแหน่งใน physical เดียวกัน (inode เดียวกัน)


Next Previous Contents