Skip to content

Instantly share code, notes, and snippets.

@hym3242
Last active October 25, 2023 15:45
Show Gist options
  • Save hym3242/30ae3e0215cbcbabda11064df0966232 to your computer and use it in GitHub Desktop.
Save hym3242/30ae3e0215cbcbabda11064df0966232 to your computer and use it in GitHub Desktop.
netcat/cat in raw mode (not line buffered, every keypress is immediately sent over)

Put this in your .bashrc/.profile:

rawcat() { sh -c 'trap "stty icanon" SIGINT; stty -icanon; cat $@;' _ $@; }
rawnc() { sh -c 'trap "stty icanon" SIGINT; stty -icanon; nc $@;' _ $@; }

The trap is used to set cat/nc to icanon state when it is Ctrl+C'd, otherwise it will be stuck in -icanon even if you run the normal /bin/cat, or any program that reads stdin like cat, like hexdump.

When using cat > file stty would complain, but still works as expected for some unknown reason

see man stty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment