You are not logged in.

#1 2011-09-25 14:00:33

keen90
Member
From: Europe
Registered: 2010-04-07
Posts: 106

[Solved] bash diff util for directories needed

Hi there

I have two dirs with nearly the same content.
Lets call them A and B.
A contains some files which are not in B, I want to a list of these files. I do not care about files existing in both dirs which have not the same content. It's only about the files existing or not.

My first thought was something like that

$ find A > contentOfA
$ find B > contentOfB
$ diff contentOfA contentOfB

but here I also get files which are in B but not in A.
Is there an easier way to do this?

Regards,
Keen

Last edited by keen90 (2011-09-25 15:18:44)

Offline

#2 2011-09-25 14:04:46

keen90
Member
From: Europe
Registered: 2010-04-07
Posts: 106

Re: [Solved] bash diff util for directories needed

---sorry no post

Last edited by keen90 (2011-09-25 14:15:00)

Offline

#3 2011-09-25 14:32:57

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [Solved] bash diff util for directories needed

Use 'comm' instead of diff - 'man comm'.

comm -23 contentOfA contentOfB

should do.

You can use diff like this

[karol@black ~]$ tree
.
├── A
│   ├── a
│   ├── b
│   ├── c
│   └── d
└── B
    ├── a
    ├── b
    ├── e
    └── f

2 directories, 10 files
[karol@black ~]$ diff A B
Only in A: c
Only in A: d
Only in B: e
Only in B: f

Last edited by karol (2011-09-25 14:38:21)

Offline

#4 2011-09-25 15:15:51

berbae
Member
From: France
Registered: 2007-02-12
Posts: 1,302

Re: [Solved] bash diff util for directories needed

Using the rsync command with the --dry-run option like that :

rsync --dry-run --ignore-existing --verbose A/* B

Take care not to forger the --dry-run option to do nothing but to show the files in A which don't exist in B.

Offline

Board footer

Powered by FluxBB