简体   繁体   English

如何以文件夹及其子文件夹的形式递归复制文件作为符号链接

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

In linux or freebsd, Is there a way to copy all files under a folder and its subfolders as symbolic link ? 在linux或freebsd中,有没有办法将文件夹及其子文件夹下的所有文件复制为符号链接? I need to copy thousands of files into different locations as symbolic links and only have 2-3 configuration files as the actual file. 我需要将数千个文件作为符号链接复制到不同的位置,并且只有2-3个配置文件作为实际文件。 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 ? 有什么建议吗?

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. 请注意,您需要提供源目录的完整路径,以便它可以创建绝对符号链接。

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    

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM