将文件从一个特定子目录复制到其他特定子目录



我找不到这个问题的好答案,所以请忍受我,因为这是一个非常简单的问题。

我在特定目录的内部有文件,需要在指定时间使用CRON将其复制到其他特定目录中。这样:

/var/www/html/files/client1/1.txt
/var/www/html/files/client2/1.txt
/var/www.html/files/client3/1.txt 
... and so on for many directories

每个文件" 1.TXT"都是特定于客户端的,因此必须专门复制到目标文件夹。

/var/www/html/desintation/client1/1.txt
/var/www/html/desintation/client2/1.txt
/var/www/html/desintation/client3/1.txt
...and so on...

如果您只想将我指向一个起点,那对我来说很酷。但是我的问题基本上是,如何确保客户端文件始终最终进入客户端1目标?因为在我看来,就像通配符一样,我无法解释这一点,并且很有可能文件最终会陷入错误的目录。

假设您在/var/www/html/files目录中,也许考虑以下内容:

find . -name 1.txt -exec cp "{}" "/var/www/html/destination/{}" ;

"查找。-Name 1.txt"位将找到一个从当前目录中名为1.TXT的相对路径的列表:

./client1/1.txt
./client2/1.txt
./client3/1.txt

" exec"部分将使用它来执行命令,例如:

cp "./client1/1.txt" "/var/www/html/destination/./client1/1.txt"
cp "./client2/1.txt" "/var/www/html/destination/./client2/1.txt"
cp "./client3/1.txt" "/var/www/html/destination/./client3/1.txt"

您可以通过添加回声来实验,以查看如果您实际运行它将输出的命令:

find . -name 1.txt -exec echo cp "{}" "/var/www/html/destination/{}" ;

最新更新