本文介绍了将文件复制到备份目录preserving文件夹结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件在目录复制到其备份目录,preserving的文件夹结构。例如。文件 AAA
在 MyFolder中/测试/ AAA
到 .MyFolder.bck /测试/ AAA
I have to copy a file in a directory, to its backup directory, preserving the folder structure. E.g. the file aaa
in MyFolder/Test/aaa
to .MyFolder.bck/Test/aaa
我试图用
cp --parents MyFolder/Test/aaa .MyFolder.bck;
但结果是 .MyFolder.bck / MyFolder中/测试/ AAA
,而不是 .MyFolder.bck /测试/ AAA
(这是一个我想要的)。
But the result is .MyFolder.bck/MyFolder/Test/aaa
and not .MyFolder.bck/Test/aaa
(which is the one I want).
推荐答案
您需要 CD
的目录,然后复制文件:
You need to cd
to the directory and then copy the file:
(cd MyFolder && cp --parents Test/aaa ../.MyFolder.bck)
围绕命令的支架使其在一个子shell中运行,而不是在当前的shell。这样做的好处是,它可以节省您不必 CD
返回后原来的目录。
这篇关于将文件复制到备份目录preserving文件夹结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!