zoukankan      html  css  js  c++  java
  • mv,Directory not empty不能目录覆盖

    一。
    mv /test1/* /test2/test1
    rm -rf /test1

    二。

    You can however use rsync 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 rsyncs 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.

    #!/bin/bash
    
    # usage source1 .. sourceN dest
    
    length=$(($#-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 mv will complete the merge and preserve the files intended to be overwritten
  • 相关阅读:
    webmagic使用
    网站文件下载链接
    正则表达式
    JS 页面刷新或重载
    History
    【问题&解决】fonts/fontawesome-webfont.woff2 404 (Not Found)
    ckeditor的使用
    Windows Server 2012 R2 或 2016 无法安装 .Net 3.5.1
    自定义配置文件的读取
    MVC中上传文件大小限制的解决办法
  • 原文地址:https://www.cnblogs.com/timssd/p/4576008.html
Copyright © 2011-2022 走看看