54

I think I have two directories with the same content, but I want to check it.

Also, I want to exclude a folder that is inside both directories.

How can I do it?

1 Answer 1

64

command line:

diff --exclude=direxclude -r dir1 dir2

openSUSE 12.1: ok.

sttr@linux-sgfb:/tmp> md dir1
sttr@linux-sgfb:/tmp> md dir2
sttr@linux-sgfb:/tmp> cd dir2
sttr@linux-sgfb:/tmp/dir2> md 10
sttr@linux-sgfb:/tmp/dir2> md 11
sttr@linux-sgfb:/tmp/dir2> md 12
sttr@linux-sgfb:/tmp/dir2> md 14
sttr@linux-sgfb:/tmp/dir2> cd ..
sttr@linux-sgfb:/tmp> cd dir1
sttr@linux-sgfb:/tmp/dir1> md 15
sttr@linux-sgfb:/tmp/dir1> md 11
sttr@linux-sgfb:/tmp/dir1> md 12
sttr@linux-sgfb:/tmp/dir1> md 17
sttr@linux-sgfb:/tmp/dir1> cd ..
sttr@linux-sgfb:/tmp> diff --exclude="11" -r dir1 dir2
Only in dir2: 10
Only in dir2: 14
Only in dir1: 15
Only in dir1: 17
sttr@linux-sgfb:/tmp> diff --exclude=11 -r dir1 dir2
Only in dir2: 10
Only in dir2: 14
Only in dir1: 15
Only in dir1: 17
sttr@linux-sgfb:/tmp>

CentOS 6.3 64: ok.

[root@local tmp]# mkdir dir1
....

Ubuntu 12.04 TLS: ok.

Ubuntu 12.04 TLS

13
  • 2
    @STTR sorry but it didn't work
    – tirenweb
    Feb 8, 2013 at 16:51
  • 2
    diff --exclude="direxclude" -r dir1 dir2 variant?
    – STTR
    Feb 8, 2013 at 17:04
  • 1
    @STTR Ubuntu 12.04
    – tirenweb
    Feb 8, 2013 at 17:39
  • 2
    @STTR I understand that -x foldername can be used to explicitly list all folders that shouldn't be used for comparison. Supposed I want to exclude all .git files from being used in the diff, but there could be multiple .git folders across multiple directories. how would you do that?
    – alpha_989
    Aug 1, 2018 at 1:00
  • 2
    This answer doesn't really answers the question. It asks a way to ignore folder in both directories when diffing not to ignore ALL folders matching some name..
    – Foto Blysk
    May 9, 2019 at 16:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .