问题描述
Osx mv和cp没有--parents选项,那么如何模拟它呢?
Osx mv and cp does not have the --parents option, so how does one emulate it ?
即mv x/y/a.txt s/x/y/a.txt,如果s为空,将显示找不到目录的错误,除非先执行mkdir,否则这样做很麻烦,因为这样做会成千上万个文件.
I.e. mv x/y/a.txt s/x/y/a.txt when s is empty gives a no directory found error unless one does a mkdir first which is rather cumbersome when trying to do this did thousands of files.
推荐答案
解决方案(适用于所有具有rsync的平台)是:
The solution (which works on all platforms that has an rsync) is:
使用查找或其他工具来创建一个文件,其中包含您要移动/复制的文件,即
Use find or some other tool to create a file with the files you want moved/copied, i.e.
find *.mp3 > files.txt
然后使用rsync files-from来指定它,并使用--remove-source-files使其表现得像mv -p,没有它,则表现得像cp -p:
Then use rsync files-from to specify it and by using --remove-source-files it behaves like a mv -p and without it works like cp -p:
rsync --files-from=files.txt --remove-source-files src dest
比本地mv/cp慢,但它的可恢复性和rsync具有很多其他选项,这些选项否则对清理文件也有帮助.
Slower than a native mv/cp but its resumable and rsync got alot more options that can otherwise help too for cleaning up your files.
这篇关于如何在OSX上模拟cp和mv --parent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!