the title sumarises my question. given directories a and b, i want to be able to generate a list of files that are in b but not in a.
a normal diff does this, but it also shows files in a not in b:
$ diff -u /mnt/Media/a ~/b
Only in /mnt/Media/a: abab
Only in /home/conor/b: blah
i would also like diff to list filenames only - none of the "Only in .." stuff
thanks
pick-up one of these :
$ LANG=C diff -qr a b | awk -F"Only in b: " '/^Only in b:/{print $2}'
or
$ LANG=C diff -qr a b | grep -oP "^Only in b: \K.*"
or
$ LANG=C diff -qr a b | grep '^Only in b:' | cut -d: -f2-
LANG=C
is only there to avoid displaying in any locale language but in English.
See man diff
The uniq
command is more useful than you might imagine. Consider two directories dirA
and dirB
:
% ls -R dirA dirB
dirA:
s1/ s2/
dirA/s1:
f2
dirA/s2:
f1 f2
dirB:
s1/ s2/
dirB/s1:
f1 f2
dirB/s2:
f1
%
File s1/f1
is missing from dirA
, and file s2/f2
is missing from dirB
.
Create lists of the contents of the two directories:
% (cd dirA; find . -type f >../listA)
% (cd dirB; find . -type f >../listB)
Now find the lines which are present only in listB
:
% cat listA listA listB | sort | uniq -u
./s1/f1
%
Ta-dah!
Typically when I have to do this, I go low-tech:
cd ~/a
find . -type f | sort > ~/fooa
cd ~/b
find . -type f | sort > ~/foob
vimdiff ~/fooa ~/foob
It lets me refine the results. "Oh, whoops, I wanted to exclude .svn directories from ~/a", so rerun the ~/fooa file without .svn directories and then rediff.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With