Skip to content
daniel@MacBookPro:~
Shell & TerminalFix September 4, 2026 3 min read

Fixing a Terminal That Shows Garbled Output or Invisible Text

You accidentally catted a binary file and now your terminal shows strange characters, wrong colors, or doesn't echo what you type. The shell is fine — the terminal's display state is what actually broke.

A terminal showing garbled characters, wrong colors, or not echoing typed input after cat-ing a binary file is a terminal emulator display-state problem, not a shell problem — the fix targets the terminal’s settings, not the shell itself.

Step 1: confirm this is actually a display-state issue

If commands still technically execute (even though you can’t see them clearly, or output looks wrong) rather than the shell hanging or refusing input entirely, this is very likely a terminal display/settings problem rather than a shell or process issue.

Step 2: try typing reset blind

reset

Even if you can’t see what you’re typing due to the corrupted display state, typing reset followed by Enter and pressing it works blind — reset reinitializes the terminal to sane default settings and typically clears whatever corrupted state a stray escape sequence left behind.

Step 3: try stty sane as a lighter-weight alternative

stty sane

stty sane restores standard terminal line-discipline settings (echo, line buffering, signal characters) without doing a full terminal reset — often sufficient for less severe corruption, and faster than a full reset.

Step 4: if typing blind doesn’t work, try Ctrl-J instead of Enter

stty sane[Ctrl-J]

If Enter itself isn’t registering correctly due to the corrupted state, Ctrl-J sends a raw linefeed character directly, which can submit the command even when Enter’s normal behavior is affected.

Step 5: close and reopen the terminal tab as a fallback

If neither reset nor stty sane restores normal behavior, closing the specific terminal tab or window and opening a new one is a reliable fallback — since the shell process itself is unaffected by this class of bug, a fresh terminal window connecting to a new shell session resolves it immediately, at the cost of losing that specific session’s state.

Step 6: avoid the root cause going forward

file suspicious-file    # check file type before viewing
less suspicious-file     # less handles binary content more gracefully than cat

Checking a file’s type with file before running cat on it, or using less (which detects and handles binary content more carefully) instead of cat for anything you’re not certain is plain text, avoids triggering this class of corruption in the first place.

Step 7: understand why this specifically affects the display, not the shell

Binary files often contain byte sequences that happen to match terminal escape sequences — commands the terminal emulator interprets as instructions (change color, move cursor, switch character sets) rather than displaying as visible text. cat-ing such a file sends these bytes directly to the terminal, which dutifully executes whatever escape sequences it finds, regardless of whether that was the actual intent.

Why this fix targets the terminal, not the shell, specifically

Since the shell and terminal emulator are separate programs connected via a pty, a corrupted display state lives entirely in the terminal emulator’s rendering and settings — the shell process underneath continues running completely normally, which is exactly why reset (a terminal-directed command) fixes the problem rather than needing to restart the shell or any running process at all.