Binary classification prompt during recovered archive inspection
0 reputation · 20 Apr 2024, 01:01 UTC
0 reputation · 20 Apr 2024, 01:01 UTC
When verifying data restored from backup archives, the preprocessor pipeline can hand less decompressed files that are mostly text but contain occasional null bytes. The goal is to page through these recovered files without manual intervention, yet less applies a content heuristic based on null bytes and control characters to decide whether input is binary. That boundary is implementation-defined and has changed across releases, so a file that opens cleanly on one system may trigger a binary warning or refusal on another.
Using -f bypasses the binary and non-regular-file checks, but forced display can emit raw escape sequences that alter terminal state. Piped input further complicates verification because less cannot display percentage position without a known file size, making it difficult to confirm that every recovered byte was actually viewed.
Which less version or configuration yields a deterministic binary-versus-text boundary for restored files filtered through LESSOPEN? Should verification workflows avoid relying on the pager's internal classification and instead pre-screen files with an explicit null-byte threshold? Is there a documented way to suppress the binary prompt for recovered archives without forcing display of potentially harmful escape sequences?
34775 reputation · 20 Apr 2024, 01:12 UTC
When verifying data restored from backup archives, the less pager may treat the decompressed stream as binary if it encounters a null byte (\x00) or any byte with the high bit set (>= 0x80). The exact count that triggers the “Binary output? y/n” prompt is not documented as configurable and can differ between less releases.
The binary‑detection heuristic runs after the LESSOPEN command finishes, so any pipeline that adds or removes null bytes will change whether the prompt appears. No standard less flag unconditionally suppresses the prompt without either modifying the input stream or risking terminal‑state changes from forced‑display options such as -F or -X.
Practical steps
less -V. Note the release number.\x00 byte (e.g., printf 'hello\x00world) and pipe it to less. Observe whether the binary prompt appears.less:
tr -d '\x00' | less
or, via LESSOPEN,
LESSOPEN='|/usr/bin/zcat -q %s' less file.gz
Be aware that stripping null bytes can corrupt archive formats where those bytes are structural.-F or -X, reset the terminal with stty sane and verify that no raw escape sequences remain by piping output through cat -v.To tailor the recommendation, please provide the output of less -V on your system.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.