2

I'm trying to compare two directories that contain binary files, on AIX 6. I'm using diff in preference to dircmp, as I'm trying to maintain a consistent output format between this and my Linux servers, where dircmp is not available.

According to the diff man page,

If the Directory1 and Directory2 parameters are specified, the diff command compares the text files that have the same name in both directories. Binary files that differ, common subdirectories, and files that appear in only one directory are listed.

However, the binary files are also being compared, and their differences output to stdout, resulting in the terminal screen being flooded with unprintable characters, even modifying the size of my window (I'm using pUTTY). The version of diff doesn't have the -q option. Is there any way to suppress this output and just report that the files differ? I'd prefer not to use rsync -n, as that needs to be run twice, with to and from parameters reversed, to find missing files on both sides.

Related questions: here and here

  • 1
    diff and dircmp are in the same fileset (bos.rte.compare). It's a bit strange that you have one and not the other. – Mat Sep 23 '15 at 11:22
  • Agh, you're right. I was conflating my AIX and Linux servers. It's Linux that doesn't have dircmp. I'll edit the question with my real reason for not wanting to use it. – rojomoke Sep 23 '15 at 16:24
2

There's a limit to how much portable code you can write without having conditionals to execute different things on different systems. Don't feel bad about using dircmp if available or GNU diff if available.

if type dircmp >/dev/null 2>/dev/null; then
  dircmp dir1 dir2
else
  diff -r dir1 dir2
fi

If you only want to know which files have changed and you don't care about listing contents, you can filter the diff output to retain only header lines. (Warning: if you have file names with newlines, the output may be unparseable.)

diff -r dir1 dir2 | grep -v '^[<>0-9]'

Make that grep -v '[^<>]' to keep information about the range of changed lines, but still filter out the content of the changed lines.

  • diff -C 0 still outputs non-printing characters. I'm not quite sure how to interpret the line from the man page: Produces a diff command comparison with a number of lines of copied context equal to the value specified by the Lines variable. – rojomoke Sep 24 '15 at 13:57
  • @rojomoke Oh, sorry, that was a stupid idea: diff -C 0 removes context but still outputs the changed parts themselves. You can use grep to filter away all changed parts. – Gilles Sep 24 '15 at 15:05
1

You can pipe the output through cat -v so that non-printing characters are shown as ^x or M-x, so that at least your terminal is not corrupted. If you know what sort of headings are printed by each file diff you can grep for just them, eg | grep -E 'Only in|differ'. (I dont have an aix to find examples of these).

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.