How can you perform a recursive diff of the files in two directories (a and b):
$ diff -r a b
but only look at files whose name matches a given pattern. For example, using the same syntax available in the find command, this would look like:
$ diff -r a b -name "*crazy*"
which would show diffs between files with the same name and path in a and b, which have "crazy" in their name.
Effectively, I'm looking for the opposite of the --exclude option which is available in diff.
I couldn't make it work with
-X -
, so I used a different approach - letfind
find the files recursively according to my requirements and letdiff
compare individual files:Or, in one line:
This
grep -oP "^$a/\K.*"
is used to extract the path relative to the directorya
, i.e. it removes/your/dir/
from/your/dir/and/a/file
, to make itand/a/file
.Perhaps this is a bit indirect, but it ought to work. You can use
find
to get a list of files that don't match the pattern, and then "exclude" all those files:The
-X -
will makediff
read the patterns from stdin and exclude anything that matches. This should work provided your files don't have funny chars like*
or?
in their names. The only downside is that your diff won't include thefind
command, so the listeddiff
command is not that useful.(I've only tested it with GNU
find
anddiff
).EDIT:
Since only non-GNU
find
doesn't have-printf
,sed
could be used as an alternative:That's also assuming that non-GNU
diff
has-X
which I don't know.