阅读时应理解为 `ln(-s x) y`,而不是 `(ln -s) (x y)`

2作者: _as_text17 天前
我总是记不住 `ln -s x y` 的操作数顺序,现在我终于明白了原因:这个命令支持两种同时的解析方式。 `(ln -s) (x y)` — 预期的解读。`-s` 代表 "symbolic"(符号链接),参数顺序与 `cp x y` 相同。很好,但我不相信这种类比——在经历了 `find`、`dd` 或 `tar` 之后。 而且,很奇怪的是,我们一开始将符号链接命名为 `x y`,但后来如果 `ls -l y`,我们会看到 `y -> x`。为什么会颠倒呢?使用 `ln -s` 使得 `-s` 无法强制执行约定:只有链接本身被定义为符号链接,而我们需要自己去弄清楚这对操作数意味着什么。 `ln (-s x) y` — 我的解读。`-s` 代表 "source"(源)。你将 x 声明为新名称 y 的内容来源。 “等等,在符号链接术语中,x 被称为 ‘target’(目标)!” 这就是我的困惑所在。我一直将 "source" 和 "target" 视为反义词,所以这个助记符总是失效。但 x 既是:链接的目标,也是内容的来源。¹ 所有指向资源的符号链接构成一个以原始文件为根的树: v1/ ← 原始文件 ├── v2 (ln -s v1 v2) │ └── v3 (ln -s v2 v3) └── v4 (ln -s v1 v4) 每个带有 `-s` 的 `ln` 都会扩展一个分支。偏序关系 `x < y`(当且仅当 `ln -s x y`)甚至可以通过 `st_birthtime` 来见证——文件系统记录了 Hasse 图的构建历史。 总结:`ln -s old new` 将 `new` 推入一个以 `old` 为根的堆栈。`-s` 代表 "source"(源),而不仅仅是 "symbolic"(符号链接)。 --- ¹ 就像拓扑学学生最终意识到一个集合既可以是闭集也可以是开集一样——这些词并不是反义词,只是独立的属性。我想知道什么样的形式拓扑结构可以让 "source" 和 "target" 对应于 "open"(开集)和 "closed"(闭集)。
查看原文
I could never remember the operand order for `ln -s x y`, and now I&#x27;ve realized why: the command supports two simultaneous parsings.<p>`(ln -s) (x y)` — the intended reading. `-s` for &quot;symbolic,&quot; argument order same as in `cp x y`. Fine, but I don&#x27;t trust such analogies — not after `find`, `dd`, or `tar`.<p>Also, it is weird how at birth we denote the symlink as `x y`, but later if we `ls -l y` we&#x27;ll see `y -&gt; x`. Why the reversal? Using `ln -s` makes `-s` powerless to impose a convention: only the link itself is qualified as symbolic, and it is left to us to figure out what that means for the operands.<p>`ln (-s x) y` — my reading. `-s` for &quot;source.&quot; You&#x27;re declaring x as the source of content for the new name y.<p>&quot;But wait, x is called the &#x27;target&#x27; in symlink terminology!&quot; This was my confusion. I&#x27;d been treating &quot;source&quot; and &quot;target&quot; as antonyms, so the mnemonic kept breaking. But x is both: target of the link, source of the content.¹<p>All symlinks to a resource form a tree rooted at the original:<p>v1&#x2F; ← original<p><pre><code> ├── v2 (ln -s v1 v2) │ └── v3 (ln -s v2 v3) └── v4 (ln -s v1 v4) </code></pre> Each `ln` with `-s` extends a branch. The partial order `x &lt; y` (iff `ln -s x y`) is even witnessed by `st_birthtime` — the filesystem records the Hasse diagram&#x27;s construction history.<p>tl;dr: `ln -s old new` pushes `new` onto a stack rooted at `old`. The `-s` is for &quot;source,&quot; not just &quot;symbolic.&quot;<p>---<p>¹ Like how topology students eventually realize a set can be both closed and open — the words aren&#x27;t antonyms, just independent properties. I wonder what formal topology scaffolding could make &quot;source&quot; and &quot;target&quot; correspond to &quot;open&quot; and &quot;closed.&quot;