Linux 如何递归复制文件夹及其子文件夹下的文件作为符号链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7456039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 06:14:13  来源:igfitidea点击:

How to recursively copy files under a folder and its subfolders as symbolic links

linuxunix

提问by Tohid

In linux or freebsd, Is there a way to copy all files under a folder and its subfolders as symbolic link ? I need to copy thousands of files into different locations as symbolic links and only have 2-3 configuration files as the actual file. The reason I'm doing this is, I have dozen of websites with with exactly the same engine code, but different configuration and look. I want to copy the engine as symbolic link so every change I make to original files will be applied to other websites as well. I can't make symbolic link to the engine folder itself, because the configuration file is under that folder, and I can't copy files one by one ! cause obviously it's not practical. Any suggestion ?

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

采纳答案by jpa

The command you are looking for is cp -rs /path/to/source dest.

您正在寻找的命令是cp -rs /path/to/source dest.

Note that you need to provide full path to the source directory so that it can make absolute symlinks.

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

回答by Kent

i don't know if this is what you want: (see example below)

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

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