48

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?

58

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 – user35538 Feb 8 '13 at 16:51
  • @user35538 Could you please be more specific? What didn't work, what did you enter? – Daniel Beck Feb 8 '13 at 17:03
  • 2
    diff --exclude="direxclude" -r dir1 dir2 variant? – STTR Feb 8 '13 at 17:04
  • 1
    @STTR Ubuntu 12.04 – user35538 Feb 8 '13 at 17:39
  • 1
    @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 '18 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.