创建与使用符号链接
学习创建、检查和管理符号链接与硬链接,在不复制数据的情况下灵活组织文件。
创建与使用符号链接 是 CoddyKit 上的免费 Linux Command Line Mastery 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 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.logInspecting 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.logFollowing 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 contentsHard 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 linkSymbolic 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 directoryFinding 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.logUpdating 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 onlyPractical Uses
Symlinks shine for:
- A stable
currentpath 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 lQuick 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.
用 AI 导师学习 Linux Command Line Mastery — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 12
- 课程
- 48
常见问题解答
「创建与使用符号链接」课时是免费的吗?
是的 — 「创建与使用符号链接」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Linux Command Line Mastery 课程的其余内容,请升级到 CoddyKit PRO。 Linux Command Line Mastery 课程共包含 4 节课。
「创建与使用符号链接」这节课中我会学到什么?
学习创建、检查和管理符号链接与硬链接,在不复制数据的情况下灵活组织文件。 你通过在浏览器中直接运行的动手代码来练习 Linux Command Line Mastery,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Linux Command Line Mastery 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Linux Command Line Mastery 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「创建与使用符号链接」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Linux Command Line Mastery 课中编写并运行代码吗?
能。每节 Linux Command Line Mastery 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。