brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: grep --line-buffered keeps a terminal pipe from stalling

Terminal
~/tips/tip-terminal-grep-line-buffered-pipe

tail -f /var/log/syslog | grep --line-buffered ERROR | cut -c1-100

Makes grep print each match immediately when it feeds another command.

A pipe from tail -f into grep and then another command often shows nothing for a long time.

tail -f /var/log/syslog | grep --line-buffered ERROR | cut -c1-100

When grep writes to a pipe it buffers the output in blocks, so the next program only sees lines after many matches. --line-buffered flushes after each line. Only the grep that feeds another pipe needs it. The last command in the chain writes to the terminal and is already line buffered. For programs without such a flag, stdbuf -oL often helps.

Further reading: grep manual page

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link