Linux Command Line Mastery · บทเรียน

การสร้างและใช้งานลิงก์สัญลักษณ์

เรียนรู้การสร้าง ตรวจสอบ และจัดการลิงก์สัญลักษณ์กับลิงก์ฮาร์ด เพื่อจัดระเบียบไฟล์ได้อย่างยืดหยุ่นโดยไม่ต้องคัดลอกข้อมูล

บทเรียน 4 จาก 413 ขั้นตอน

การสร้างและใช้งานลิงก์สัญลักษณ์ เป็นบทเรียน Linux Command Line Mastery ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Linux Command Line Mastery และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

What Is a Link

A link is a filesystem entry that points to another file. Links let one file appear in multiple places without duplicating its data, saving space and easing organization.

Linux has two kinds: symbolic links and hard links.

Creating a Symbolic Link

A symbolic link (symlink) is a small file holding a path to its target. Create one with ln -s: the target first, then the link name.

ln -s /var/log/app.log current.log

Inspecting Links

ls -l shows symlinks with an arrow pointing to their target, and the type character l at the start of the permissions.

ls -l current.log
# lrwxrwxrwx 1 user user 16 ... current.log -> /var/log/app.log

Following a Link

Reading or writing through a symlink transparently affects the target. Editing current.log edits /var/log/app.log.

cat current.log   # reads the target file's contents

Hard Links

A hard link is a second name for the exact same data on disk. Both names are equal; deleting one leaves the data until the last link is gone.

ln original.txt backup.txt   # no -s means hard link

Symbolic vs Hard

Key differences:

  • Symlinks can cross filesystems and link directories; hard links cannot.
  • A symlink breaks if its target moves; a hard link keeps the data alive.
  • Symlinks store a path; hard links share an inode.

Broken Links

If a symlink's target is deleted or moved, the link becomes dangling. Accessing it fails. ls often shows broken links in red.

rm /var/log/app.log
cat current.log   # error: No such file or directory

Finding the Target

Use readlink to print where a symlink points, and readlink -f to resolve the full real path through chained links.

readlink current.log
readlink -f current.log

Updating and Removing Links

To repoint a symlink, use ln -sf to force-replace it. To remove a link, rm deletes the link itself, never the target file.

ln -sf /var/log/new.log current.log   # repoint
rm current.log                        # remove the link only

Practical Uses

Symlinks shine for:

  • A stable current path pointing at the latest versioned release.
  • Putting config files in a dotfiles repo, linked into $HOME.
  • Sharing a dataset across projects without copies.

Listing All Links in a Directory

To audit existing links, combine ls with a filter. The find command can list every symlink under a path, helping you spot broken or stray ones.

find . -type l

Quick Check

Test your understanding of links.

Recap

You learned to work with links: create symlinks with ln -s, inspect them with ls -l and readlink, understand hard vs symbolic differences, recognize broken links, repoint with ln -sf, and apply them to releases, dotfiles, and shared data.

เริ่มต้นได้ฟรี

เรียนรู้ Linux Command Line Mastery ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

คำถามที่พบบ่อย

บทเรียน “การสร้างและใช้งานลิงก์สัญลักษณ์” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การสร้างและใช้งานลิงก์สัญลักษณ์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Linux Command Line Mastery ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Linux Command Line Mastery มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การสร้างและใช้งานลิงก์สัญลักษณ์”

เรียนรู้การสร้าง ตรวจสอบ และจัดการลิงก์สัญลักษณ์กับลิงก์ฮาร์ด เพื่อจัดระเบียบไฟล์ได้อย่างยืดหยุ่นโดยไม่ต้องคัดลอกข้อมูล คุณปฏิบัติ Linux Command Line Mastery ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Linux Command Line Mastery หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Linux Command Line Mastery บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การสร้างและใช้งานลิงก์สัญลักษณ์” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Linux Command Line Mastery นี้ได้ไหม

ได้ บทเรียน Linux Command Line Mastery ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การดูเนื้อหาไฟล์: `cat`, `less`, `more`
  2. การค้นหาไฟล์: `find` และ `locate`
  3. สิทธิ์และเจ้าของ: `chmod`, `chown`
  4. การสร้างและใช้งานลิงก์สัญลักษณ์
← กลับไปที่ Linux Command Line Mastery