一。
mv /test1/* /test2/test1
rm -rf /test1
二。
You can however usersync
with the--remove-source-files
option (and possibly others) to merge one directory into another.
rsync
won't delete any directories, so you will have to do something like
find -type d -empty -delete
afterwards to get rid of the empty source directory tree.
?
rsync -av /source/ /destination/
(after checking)
rm -rf /source/
--remove-source-files
has the advantage of only removing files that were transferred successfully,
so you can use
find
to remove empty directories and will be left with everything that wasn't transferred without having to check
rsync
s output
cd source; find -type f | xargs -n 1 -I {} mv {} dest/{}
三。
I'd recommend these four steps:
cd ${SOURCE};
find . -type d -exec mkdir -p ${DEST}/\{} \;
find . -type f -exec mv \{} ${DEST}/\{} \;
find . -type d -empty -delete
or better yet, here's a script that implements semantics similar to
mv
:
#!/bin/bash
DEST=${@:${#@}}; for SRC in ${@:1:$(({#@} -1))}; do (
cd $SRC;
find . -type d -exec mkdir -p ${DEST}/\{} \;
find . -type f -exec mv \{} ${DEST}/\{} \;
find . -type d -empty -delete
) done
Here is a script that worked for me. I prefer mv over rsync, so I use Jewel and Jonathan Mayer's solutions.
|
if you use use
mv --backup=numbered
(or one of the other options for the --backup switch),
then
mv
will complete the merge and preserve the files intended to be overwritten
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
