Diff directories a and b. show only files in b, not in

the title brings up 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.

normal diff does this, but also shows files in 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 display only file names - none of the "Only in .." materials

thank

+5
source share
3 answers

Try

choose one of them:

$ 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-

Note

LANG=C

only there to avoid displaying in any language of the language, but in English.

Doc

Cm. man diff

+7
source

The team is uniqmore useful than you could imagine. Consider two directories dirAand 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
%

s1/f1 dirA, s2/f2 dirB.

:

% (cd dirA; find . -type f >../listA)
% (cd dirB; find . -type f >../listB)

, listB:

% cat listA listA listB | sort | uniq -u 
./s1/f1
% 

-!

+4

Generally, when I have to do this, I go for low tech:

cd ~/a
find . -type f | sort > ~/fooa
cd ~/b
find . -type f | sort > ~/foob
vimdiff ~/fooa ~/foob

This allows me to refine the results. "Oh screams, I wanted to exclude the .svn directories from ~ / a," so restart the ~ / fooa file without the .svn directories, and then reinstall.

+2
source

All Articles