1. 一。mv /test1/* /test2/test1rm -rf /test1
  2.  
  3. 二。
  4.  
  5. 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.

  1.  
  1. rsync -av /source/ /destination/
  2. (after checking)
  3. rm -rf /source/
  4. --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
  1. cd source; find -type f | xargs -n 1 -I {} mv {} dest/{}
  1. 三。

I'd recommend these four steps:

  1. cd ${SOURCE};
  2. find . -type d -exec mkdir -p ${DEST}/\{} \;
  3. find . -type f -exec mv \{} ${DEST}/\{} \;
  4. find . -type d -empty -delete

or better yet, here's a script that implements semantics similar to mv:

  1. #!/bin/bash
  2. DEST=${@:${#@}}; for SRC in ${@:1:$(({#@} -1))}; do (
  3. cd $SRC;
  4. find . -type d -exec mkdir -p ${DEST}/\{} \;
  5. find . -type f -exec mv \{} ${DEST}/\{} \;
  6. find . -type d -empty -delete
  7. ) done

Here is a script that worked for me. I prefer mv over rsync, so I use Jewel and Jonathan Mayer's solutions.

  1. #!/bin/bash
  2. # usage source1 .. sourceN dest
  3. length=$(($#-1))
  4. sources=${@:1:$length}
  5. DEST=$(readlink -f ${!#})
  6. for SRC in $sources; do
  7. pushd $SRC;
  8. find . -type d -exec mkdir -p ${DEST}/{} \;
  9. find . -type f -exec mv {} ${DEST}/{} \;
  10. find . -type d -empty -delete
  11. popd
  1. if you use use mv --backup=numbered
  2. (or one of the other options for the --backup switch),
  3. then mv will complete the merge and preserve the files intended to be overwritten

mv,Directory not empty不能目录覆盖的更多相关文章

  1. [linux] mv: cannot move $ to $: Directory not empty

    最近测试某流程时,跑的过程报错了,于是检查脚本修改后重新测试.脚本是改过来了,但在shell中运行某步时碰到了如题报错! $ mv MP_genus_network_files/ tax_networ ...

  2. /Users/XX/Library/Developer/Xcode/DerivedData/XX.app/xxsdk.bundle Directory not empty

    今天在升级xcode后真机调试偶然发现这个问题,查了一些资料发现还是不能完全解决 解决方法:参考的(http://blog.csdn.net/alincexiaohao/article/details ...

  3. 【Linux 命令】 rsync 目录覆盖软链接,保持软链接不变并同步目录内容

    需求:有两个相同文件名的目录需要使用其中一个目录覆盖另外一个  问题: 被覆盖目录下存在软链接,但在源目录下软链接是一个目录 需要解决的方案: 要求将原目录里和被覆盖目录里冲突的目录文件复制到B的软链 ...

  4. OC报错,after command failed: Directory not empty

    Directory not empty这个错误经常出现,出现的原因也很多,今天主要记录一下楼主自己碰到的这种情况. 全部错误提示: error: couldn't remove ‘路径/app-fzy ...

  5. Xcode 编译运行报错: CpResource /user/xxxx/ xxx Directory not empty

    之前遇到过相同的问题,总是记吃不记打,踩过的坑后面还会踩进去... 仅以次标记加深一下印象 错误特征RT 确认该类型错误是library或frameWork的search路径问题 首先找到编译错误的路 ...

  6. 04_Linux目录文件操作命令1(mv ls cd...)_我的Linux之路

    上一节已经给大家讲了Linux的目录结构,相信大家已经对Linux的整个目录结构有所了解 现实中,服务器(包含Linux,Unix,windows server)一般都摆放在机房里,因为一个机房摆放了 ...

  7. Linux文件与目录管理 - ls, cp, mv

    [root@www ~]# ls [-aAdfFhilnrRSt] 目录名称 [root@www ~]# ls [--color={never,auto,always}] 目录名称 [root@www ...

  8. Shell命令-文件及目录操作之mkdir、mv

    文件及目录操作 - mkdir.mv 1.mkdir:创建目录 mkdir命令的功能说明 mkdir命令用于创建目录,默认情况下,要创建的目录已存在,会提示文件存在,不会继续创建目录. mkdir命令 ...

  9. Linux 移动或重命名文件/目录-mv 的10个实用例子

    本文导航 -初识 mv 命令03% -1.移动文件08% -2.移动多个文件15% -3.移动目录23% -4.重命名文件或目录27% -5. 重命名目录35% -6. 打印移动信息39% -7. 使 ...

随机推荐

  1. red-hat6.5 yum 源配置,cloud-init 安装 This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register

    This system is not registered to Red Hat Subscription Management. You can use subscription-manager t ...

  2. 你应该了解的 7个Linux ls 命令技巧

    在前面我们系列报道的两篇文章中,我们已经涵盖了关于‘ls’命令的绝大多数内容.本文时‘ls命令’系列的最后一部分.如果你还没有读过该系列的其它两篇文章,你可以访问下面的链接. 15 个‘ls’命令的面 ...

  3. JS浏览器对象-计时器

    setInterval用法 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...

  4. Engineer Economic

    1.选择题 10.下列哪项不属于总成本费用() A.生产成本    B.机会成本    C.管理费用    D.财务费用 第1章 11.下列哪项关于自有资金的表述是错误的(D) A.自有资金包括资本金 ...

  5. (转)苹果推送通知服务教程 Apple Push Notification Services Tutorial

    本文译自http://www.raywenderlich.com/.原文由iOS教程团队 Matthijs Hollemans 撰写,经原网站管理员授权本博翻译. 在iOS系统,考虑到手机电池电量,应 ...

  6. 设计模式16---设计模式之组合模式(Composite)(行为型)

    1.场景模拟 使用软件模拟大树的根节点和树枝节点和叶子节点 抽象为两类,容器节点和叶子节点 2.不用模式的解决方案 package demo14.composite.example1; import ...

  7. C语言函数指针(转载)

    二.通常的函数调用 一个通常的函数调用的例子:/* 自行包含头文件 */void MyFun(int x); /* 此处的声明也可写成:void MyFun(int) */int main(int a ...

  8. SVN 代码下载,上传

    代码下载,如: svn co https://99.99.16.1:8080/svn/pavenas/webpy --username bg 代码上传,如: svn commit -m "备 ...

  9. Eclipse 添加快捷方式

    1.在/usr/share/applications创建一个desktop文件,命名为eclipse.desktop 文件内容如下 [Desktop Entry]Name=EclipseType=Ap ...

  10. [Leetcode][001] Two Sum (Java)

    题目在这里: https://leetcode.com/problems/two-sum/ [标签]Array; Hash Table [个人分析] 这个题目,我感觉也可以算是空间换时间的例子.如果是 ...