【问题标题】:How to recursively copy files under a folder and its subfolders as symbolic links如何递归地将文件夹及其子文件夹下的文件复制为符号链接
【发布时间】:2011-09-18 21:54:14
【问题描述】:

在 linux 或 freebsd 中,有没有办法将文件夹及其子文件夹下的所有文件复制为符号链接?我需要将数千个文件作为符号链接复制到不同的位置,并且只有 2-3 个配置文件作为实际文件。我这样做的原因是,我有十几个网站具有完全相同的引擎代码,但配置和外观不同。我想将引擎复制为符号链接,因此我对原始文件所做的每项更改也将应用于其他网站。 我无法对引擎文件夹本身进行符号链接,因为配置文件在该文件夹下,我无法逐个复制文件!因为显然这不切实际。 有什么建议吗?

【问题讨论】:

  • 如果你想要符号链接,你不需要递归。您可以链接子目录的最顶层。

标签: linux unix


【解决方案1】:

您要查找的命令是cp -rs /path/to/source dest

请注意,您需要提供源目录的完整路径,以便它可以创建绝对符号链接。

【讨论】:

  • 我试过 -rs 但没用。我得到 cp: 非法选项 -- s。
  • FreeBSD 似乎没有该选项 :( 但你是对的!它适用于 Linux
【解决方案2】:

我不知道这是不是你想要的:(见下面的例子)

dir one is your central "engine"
dir two is one of your website.

kent@ArchT60:/tmp$ tree one two
one
|-- 1.txt
|-- 2.txt
|-- 3.txt
|-- 4.txt
|-- 5.txt
|-- dirA
|   |-- a
|   |-- b
|   `-- c
|-- dirB
`-- dirC
two
|-- myConf_a.conf
|-- myConf_b.conf
|-- myConf_c.conf
|-- myConf_d.conf
`-- myConf_e.conf

kent@ArchT60:/tmp$ ln -s /tmp/one/* /tmp/two/.

kent$  tree -l /tmp/two
/tmp/two
|-- 1.txt -> /tmp/one/1.txt
|-- 2.txt -> /tmp/one/2.txt
|-- 3.txt -> /tmp/one/3.txt
|-- 4.txt -> /tmp/one/4.txt
|-- 5.txt -> /tmp/one/5.txt
|-- dirA -> /tmp/one/dirA
|   |-- a
|   |-- b
|   `-- c
|-- dirB -> /tmp/one/dirB
|-- dirC -> /tmp/one/dirC
|-- myConf_a.conf
|-- myConf_b.conf
|-- myConf_c.conf
|-- myConf_d.conf
`-- myConf_e.conf    

【讨论】:

    猜你喜欢
    • 2018-10-16
    • 2020-09-29
    • 2021-03-04
    • 1970-01-01
    • 2014-07-28
    • 2022-10-14
    • 2011-07-19
    • 1970-01-01
    • 2021-05-17
    相关资源
    最近更新 更多