4

我正在尝试将我的 Library/Fonts 目录与我的 Dropbox 中的一个文件夹进行符号链接,这样我就不必继续安装和找出哪台机器有我需要的字体。当我尝试这个时:

ln -s Fonts/ ~/Library/Fonts

我得到这个错误作为回报:

ln: /Users/Username/Library/Fonts/: File exists

我无法删除该文件夹,因为它是系统要求的,因此不会让您删除。

4

3 回答 3

1

此方法在目标文件夹已经是符号链接时才有效。

使用lnOSX 或 BSD 派生的 unix 附带的:

ln -s -h -F /source/folder/to/use /destination/folder/to/overwrite

-h是关键。否则你会得到类似~/Library/Fonts/Fonts的东西,因为它会遍历该文件夹。-F单独不会尝试覆盖,因为一旦进入该文件夹就不会看到冲突。

ln 手册页的相关部分:

      ln [-Ffhinsv] source_file ... target_dir

-s    Create a symbolic link.
-h    If the target_file or target_dir is a symbolic link, do not follow it.
      This is most useful with the -f option, to replace a symlink which may
      point to a directory.
-F    If the target file already exists and is a directory, then remove it
      so that the link may occur.

GNU coreutils ln用户:

如果您使用的是软件包中的GNU (linux、brew、macports 等),请使用:lncoreutils-T

ln -sTf /source/folder/to/use /destination/folder/to/overwrite

此外,使用GNU ln,您可以替换普通文件夹。查看其手册页中的-t选项,使用它来指定目标文件夹的父级:

ln -sf -t /destination/folder/to/overwrite/.. /source/folder/to/use

需要尾随/..来定位目录内的创建,将其保留在原位。

于 2012-10-01T10:39:30.947 回答
1

ln -s -F将在创建链接之前强制创建删除原始目标的链接。

于 2012-10-01T01:19:49.463 回答
1

从您的 Dropbox 目录中删除 Fonts 文件夹(显然您需要将要保存的任何文件移动到其他位置),然后键入:

ln -s ~/Library/Fonts Fonts

请注意,您希望最后一个 Fonts 目录的尾随/

编辑地址评论:你说得对,这只链接到一个 /Library/Fonts 文件夹。您可以尝试在一台机器上执行此操作,然后在另一台机器上尝试:

  1. 关闭 Dropbox
  2. 保存 ~/Dropbox/Fonts 文件夹
  3. 执行与第一台计算机相同的符号链接功能 ( ln -s ~/Library/Fonts Fonts)
  4. 复制任何可能不在这台机器上的字体
  5. 重新打开 Dropbox

我还没有尝试过,所以我不知道它是否会起作用,但它应该没有害处。

另一种绝对可行的方法是设置一个 cron 作业,~/Library/Fonts 文件夹中不存在的字体复制到 ~/Dropbox/Fonts 文件夹,反之亦然。如果符号链接技巧有效,我认为那将是首选。

于 2012-09-30T23:44:59.860 回答