Finding difference between 2 directories in linux
嗨,大家好,
1 | I was trying to find the difference between two directories, dir structure as follows. |
当我尝试使用"diff -r dir1 dir2"时,它只显示文件中的内容差异,但我想要新增加文件的实习生。
我们可以使用"diff"命令找到这些目录之间的差异的任何可能性。
尝试使用
1 2 3 4 5 | $ diff --recursive --brief dir1 dir2 Only in dir1/dir1: file1 Only in dir2/dir1: file2 Only in dir1: dir2 $ |
1 | diff -qrN dir1 dir2 |
如果其中一个目录的名称可能与参数混淆
1 | diff -qrN -- -f -z |
其中-f和-z实际上是目录名
删除
1 | diff -rupN -- dir1 dir2 |
Alt.1 - 使用diff
1 | diff <(ls dir1) <(ls dir2) |
Alt.2 - 不使用diff的脚本
1 2 3 4 5 6 | 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 |