在linux中查找2个目录之间的差异

嗨,大家好,

      I was trying to find the difference between two directories, dir structure as follows.
  • DIR1 /子目录/ file.txt的
  • DIR2 /子目录/ nffile.txt
  • 当我尝试使用“diff -r dir1 dir2”时,它仅显示文件中的内容差异,但我希望新增文件的实习生。

    我们可以使用“diff”命令找到这些目录之间的差异。


    尝试使用--brief选项,如:

    $ diff --recursive --brief dir1 dir2
    Only in dir1/dir1: file1
    Only in dir2/dir1: file2
    Only in dir1: dir2
    $
    

    Alt.1 - 使用差异

    diff <(ls dir1) <(ls dir2)
    

    Alt.2 - 不使用差异的脚本

     for i in /my/directory/*; do
        name=$(basename "$i")
        if [[ ! -e "/my/other/directory/$name" ]]; then
           echo $name not found in other directory
        fi
     done
    

    diff -qrN dir1 dir2
    

    如果其中一个目录的名称可能与参数混淆

    diff -qrN -- -f -z
    

    其中-f和-z实际上是目录名称

    删除q参数以获得有关更改内容的更多详细信息。 如果你想更详细地使用以下内容

    diff -rupN -- dir1 dir2
    
    链接地址: http://www.djcxy.com/p/78325.html

    上一篇: Finding difference between 2 directories in linux

    下一篇: Bash script that copies the differences in two directories to a third directory?