3 ms·
Here's a coreutils (two-liner) version: printf '\xEF\xBB\xBF' >bom.dat find . -name '*.csv' \ -exec sh -c 'head --bytes 3 {} | cmp --quiet - bom.dat' \
by nemetroid 5y ago
Here's a coreutils (two-liner) version:
printf '\xEF\xBB\xBF' >bom.dat
find . -name '*.csv' \
-exec sh -c 'head --bytes 3 {} | cmp --quiet - bom.dat' \; \
-print
The -exec option for find can be used as a filter (though -exec disables the default action, -print, so it must be reenabled after).
Could be made into a oneliner by replacing the 'bom.dat' argument to cmp with '<(printf ...)'.
- xorcist 5y agoThe cmp in coreutils understands: -n, --bytes=LIMIT compare at most LIMIT bytes so head is not really necessary: find . -name '*.csv' -type f -exec cmp -sn 3 {} bom.dat \; -print Using -exec as a filter is a nice feature more people should use. That -type was put there just to avoid directories.