I have a binary file:
# file /tmp/43174744S.0601.Z
/tmp/43174744S.0601.Z: compress'd data 16 bits
Even grep detects it as binary:
# grep "" /tmp/43174744S.0601.Z
Binary file /tmp/43174744S.0601.Z matches
Now I want to exclude binary-files by the I or --binary-files=without-match option, but it still finds the file?!
# grep -I "" /tmp/43174744S.0601.Z
Binary file /tmp/43174744S.0601.Z matches
# grep --binary-files=without-match "" /tmp/43174744S.0601.Z
Binary file /tmp/43174744S.0601.Z matches
# grep -Il "" /tmp/43174744S.0601.Z
/tmp/43174744S.0601.Z
Is this a bug? Because other binary files are found / not found depending on the used option:
# grep -I "" /usr/lib/*.so
# grep "" /usr/lib/*.so
Binary file /usr/lib/klibc-abS-oVB3xeRN8SFypUWbQvR33nc.so matches
Binary file /usr/lib/libdmmp.so matches
Binary file /usr/lib/libmpathcmd.so matches
Binary file /usr/lib/libmpathpersist.so matches
Binary file /usr/lib/libmultipath.so matches
So it does work, but not for this specific file.
Note: Tested with "grep (GNU grep) 2.16" and "grep (GNU grep) 3.4".
Update1
I extracted the first 2 bytes of the file and it still happens:
# head -c2 /tmp/43174744S.0601.Z > /tmp/43174744S.0601.C2.Z
# cat /tmp/43174744S.0601.C2.Z | od -a
0000000 us gs
0000002
# grep -I "" /tmp/43174744S.0601.C2.Z
Binary file /tmp/43174744S.0601.C2.Z matches
Update2
This is really strange. After creating a new file with the same content, grep seems to act correctly?!
# echo -n $'\37'$'\35' > /tmp/test
# cat /tmp/test | od -a
0000000 us gs
0000002
# cat /tmp/43174744S.0601.C2.Z | od -a
0000000 us gs
0000002
# grep "" /tmp/43174744S.0601.C2.Z
Binary file /tmp/43174744S.0601.C2.Z matches
# grep "" /tmp/test
#
If I use cp /tmp/43174744S.0601.C2.Z /tmp/test, its broken again. So it must be related to this file.
Update3
As requested the output of hexdump:
# hexdump -C /tmp/43174744S.0601.C2.Z
00000000 1f 9d |..|
00000002
# hexdump -C /tmp/test
00000000 1f 1d |..|
00000002