Diff files present in two different directories

前端 未结 8 2115
你的背包
你的背包 2020-11-30 16:23

I have two directories with the same list of files. I need to compare all the files present in both the directories using the diff command. Is there a simple co

8条回答
  •  一向
    一向 (楼主)
    2020-11-30 17:00

    If it's GNU diff then you should just be able to point it at the two directories and use the -r option.

    Otherwise, try using

    for i in $(\ls -d ./dir1/*); do diff ${i} dir2; done
    

    N.B. As pointed out by Dennis in the comments section, you don't actually need to do the command substitution on the ls. I've been doing this for so long that I'm pretty much doing this on autopilot and substituting the command I need to get my list of files for comparison.

    Also I forgot to add that I do '\ls' to temporarily disable my alias of ls to GNU ls so that I lose the colour formatting info from the listing returned by GNU ls.

提交回复
热议问题