Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบ >> Linux

วิธี Navigate และใช้ Linux Directory Structure

Linux directory systems ต่างจาก Windows และอาจ confuse new users คิด Linux directory structure ว่าเป็น tree Root ของ tree คือที่มันโต และใน Linux คือที่ directories กิ่งก้านออกไป

Directory separator คือ forward-slash (/), ย่อว่า slash ตัวอย่าง path ไป root directory บ่อยครั้งเรียกว่า slash (/)

Linux Directory Structure คืออะไร?

ผู้คุ้นเคย Linux เคยได้ยิน terms เช่น root, lib, และ boot นี่คือ examples ของ Linux distribution directories

Linux systems ใช้ Filesystem Hierarchy Standard (FHS) define content และ directory structure ของ Linux distributions ทั้งหมด

Basic Navigation

Linux Directory structure หมายถึง folder ของ hard drive ที่ Linux ติดตั้ง

เริ่มรัน ls (list storage) command กด Enter คำสั่งนี้แสดง list of folders ใน current working directory

จำไว้ว่าแต่ละ distribution มาพร้อม folders ต่างๆ ใน home directory

List command ย่อมาจาก list storage แต file system เริ่มด้วย single forward-slash (/) ใส่คำสั่ง:

ls /

จะแสดง directory structure ของ Linux file system, setup ของ hard drive, หรือ default folder structure

แต่ละ folder มี designated purpose Home directory คือที่ users อยู่ ใช้คำสั่งดูใน user home directory:

ls /home

Clear screen: พิมพ์ clear หรือ ctrl L จำว่า ctrl L อาจไม่ทำงานบนทุก distro แต clear command จะทำงาน

กลับไป ls command คำสั่งสำคัญที่สุดต้องรู้และเข้าใจ list items ใน directory ที่คุณอยู่

แตเพิ่ม additional commands ให้ ls ได้ เช่น ls -l / แสดง output ต่างจากแค่ / ลอง:

ls -l /

เห็นข้อมูลมากขึ้น ทุกอย่างบนบรรทัดของตัวเอง -l = long listing

หมายถึงอยากดู details มากขึ้น และทุก item บรรทัดแยกกันอ่านง่าย บาง distributions ใช้ ll เป็น alias สำหรับ -l

Important Folders ที่ควรรู้

มี folders เยอะใน Linux system เราจะพูดถึงสำคัญที่สุดด้านล่าง

The Home Directory

Home directory โดย default คือที่ all users มี personal working space ของตัวเอง แต่ละ user จะมี folder ใน /home directory

อยากดู listing ทุก folders ใน home directory:

ls -l /home

เพราะคุณอยู่ใน home directory แล้ว ก็แค่ ls ดู contents ได้โดยไม่ต้อง path

ทุก directory ใน Linux directory structure แยกด้วยและเริ่มด้วย forward slash (/) กล่าวคือ ls โดยไม่มี path จะแสดง contents ของ current directory

อยากเปลี่ยน directory กลับไป root of file system:

cd /

อยากดู directories ใน root:

ls

เพราะอยู่ใน root directory ไม่ใช่ home directory จะเห็น list ทุก folders ใน root

Long list ใน root directory:

ls -l

The Root Directory (/root)

ทุก directories และ files บนระบบอยู่ใน root file แทนด้วย symbol / ทุก files หรือ directories เริ่มที่ root Path ของไฟล์/ไดเรกทอรีจะแสดงแบบ:

Root/home/user/videos

Root directory สำหรับ single user และเป็น most powerful user บน Linux system

Lib Directory Shared libraries (/lib)

/lib directory คือที่ files containing code (libraries) อยู่ files นี้มี code snippets ส่งไฟล์ไป hard drive, draw windows บน desktop, หรือ control peripherals

Media Directory (/media)

Media directory คือที่เห็น data files ของ mounted external hard drives, thumb drives, DVDs, หรือ Blu-ray disks

Boot Directory (/boot)

Files และ folders ที่ระบบต้องการเริ่มต้นอยู่ใน /boot directory Usage standardized ใน Filesystem Hierarchy Standard

Configuration ที่ต้อง boot machine อยู่ใน boot directory อย่าลบ directory นี้

Standard directories อื่นๆ:

  • /dev ที่ all device files อยู่ เช่น external USB หรือ webcam
  • /var ย่อจาก variable ที่ programs store runtime info: user tracking, system logging, caches, และ files อื่นๆ ที่ system programs manage และ create
  • Users' personal directories ใน /home
  • /proc มี info เกี่ยวกับ system: CPU และ Linux system kernel เป็น virtual system
  • /bin ที่ all essential runnable programs (user binaries) อยู่
  • /etc folder มี configuration files

อ่าน Wikipedia summary สำหรับ full breakdown ของแต่ละ directory และการใช้งาน

ดู Current Directory

ถ้าไม่รู้ว่าอยู่ directory ไหน ใช้คำสั่ง pwd (print working directory)

Results จะแบบ:

/home/username

ถ้ารัน ls default setting จะแสดง contents ของ folder ที่อยู่ ตามที่อธิบาย

สีหมายถึงอะไร?

สมมติคุณอยู่ใน /etc folder รันคำสั่ง:

ls -l /etc

จะเห็นข้อมูลเยอะและสีหลายสี

General rule of thumb:

  • Blue = folder
  • White = file
  • Green = program หรือ binary

สีอาจแตกต่างตาม distribution ส่วนใหญ่แตไม่ใช่ทุก distro มาพร้อม pre-set colors

Permission Strings คืออะไร?

ทุก file มี stream of letters ด้านซ้ายของ listing เรียกว่า permission string

ดู first character ใน string d = directory แม้ Linux distro ไม่ใช้สีต่างกัน คุณยังรู้ว่า character string เริ่ม d คือ directory

Files และ programs เริ่มด้วย hyphen (-)

l = link ที่ link ไปอีก file

Quick Navigation Overview

ls command list storage แสดงอะไรใน current working directory ไม่รู้ current directory ใช้ pwd command

File system เริ่มต้นด้วย single forward-slash (/) ใช้ cd command สลับระหว่าง directories ดูใน directory ที่สลับไป: ls command กลับ home directory: /home/username

cd command ช่วย navigate file system ls แสดงใน current directory ls -1 แสดง long listing

แม้ Linux distributions ต่างๆ จะมี minor differences file system layouts คล้ายกันมาก Best way เข้าใจ Linux directory structure คือ follow suggestions ด้านบน และ familiarize กับวิธีทำงาน

แค่อย่า touch /boot directory Practice navigate ระบบด้วย terminal ติด cd, ls, และ pwd commands จะไม่ break อะไร ไม่ค่อยนานคุณจะ intuitively รู้หา documentation, apps และ resources ที่ต้องใช้