zoukankan      html  css  js  c++  java
  • patch文件制作,排除符号链接的方法

    #!/bin/sh

    #parameter check
    # $1 is regarded as the original folder
    # $2 is regarded as the latest folder
    # $3 is regraded as the patch file
    if [ $# -lt 3 ];then
    echo "usage:$0 original_dir dest_dir patch_file"
    exit -1;
    fi

    #variable declare
    ori_dir=$1
    new_dir=$2
    patch_file=$3

    #remove the old patch file
    if [ -f ${patch_file} ];then
    rm ${patch_file}
    fi

    #find out all the files, except symbol link
    ori_files=`cd ${ori_dir}; find ./ -type f ! -type l`

    for file in ${ori_files};do
      if [ -f ${ori_dir}/${file} ];then
        if [ -f ${new_dir}/${file} ];then
          #remove the "./" symbol from the file string.
          file=`echo ${file} | sed s/"./"//`
          diff -uNr ${ori_dir}/${file} ${new_dir}/${file} >> ${patch_file}
        fi
      fi
    done

    2. 另外一种方法:

    (1)查找某个目录下的所有符号链接文件,重定向到一个文件

    find 某个目录 -type l > symbolic_list

    (2)由于符号链接文件中包含了路径"/",所以在每一行的头和尾加上引号"

    sed -i -e "s/^/"/" -e "s/$/"/" symbolic_list

    (3)使用diff命令制作patch文件,用其X参数排除符号链接文件

    diff -uNr -X symbolic_list originalSourceDirectory newSourceDirectory > xxxx.patch

    这样制作出来的patch文件也是不包含原始目录下symbolic link文件

    PS:patch文件的使用(以下命令中的x代表去掉patch文件中的第几个"/",0代表不去掉,1代表去掉第一个"/",以此类推)

    patch -px -d 目录 < patch文件

    diff命令手册    : diff
    patch命令手册: patch

  • 相关阅读:
    hdu 1754
    hdu 1166
    poj 1193
    如何由XSD自动生成XML和实体类
    WinForm(C#)CheckedlistBox绑定数据,并获得选中的值(ValueMember)和显示文本(DisplayMember)
    C#读写共享文件夹
    去除TFS版本控制信息
    SQL 触发器
    C#中操作WMI的类库-实现远程登录共享
    VS 制作安装包小窥
  • 原文地址:https://www.cnblogs.com/eric-geoffrey/p/3161996.html
Copyright © 2011-2022 走看看