您的位置:首页 > 其它

mv,Directory not empty不能目录覆盖

2015-06-14 23:36 447 查看
一。
mv  /test1/* /test2/test1
rm -rf /test1

二。

You can however use [code]rsync
with the
--remove-source-files
option (and possibly others) to merge one directory into another.
[/code]
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 [code]find
to remove empty directories and will be left with everything that wasn't transferred without having to check
rsync
s output[/code]
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

0 down vote
Here is a script that worked for me. I prefer mv over rsync, so I use Jewel and Jonathan Mayer's solutions.
#!/bin/bash# usage source1 .. sourceN destlength=$(($#-1))
sources=${@:1:$length}
DEST=$(readlink -f ${!#})
for SRC in $sources; do
pushd $SRC;
find . -type d -exec mkdir -p ${DEST}/{} \;
find . -type f -exec mv {} ${DEST}/{} \;
find . -type d -empty -delete
popd
if you use use 
mv --backup=numbered
(or one of the other options for the --backup switch),then [code]mv
will complete the merge and preserve the files intended to be overwritten
[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: