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: od -c shows every byte of a line, including the ones your terminal hides

Linux
~/tips/tip-linux-od-c-hidden-characters

head -n 3 config.env | od -c

Find the stray carriage return, tab or odd byte that breaks a script or config.

A config value looks right but does not work, and the reason is a character you cannot see. od -c prints every byte, with escapes for the invisible ones.

head -n 3 config.env | od -c

Normal characters show as themselves, and the rest gets a backslash: \t for a tab, \r for a carriage return, \n for the end of a line. Bytes without a name appear as three digit octal numbers. A line that ends in \r \n was saved with Windows line endings, which is the classic reason why a shell script fails with bad interpreter.

A small example:

printf 'a\tb\r\n' | od -c

prints a \t b \r \n, with the offset in front.

Other things I’d look for are a byte order mark at the start of a file, which shows as 357 273 277, and a non breaking space, 302 240, that sneaks in when text is copied from a web page. Both look like nothing in an editor and break parsers.

The numbers in the left column are offsets in octal by default. Add -A d for decimal offsets. For long files, run it on a few lines with head or sed -n first, because the output is several times bigger than the input. cat -A gives a shorter view, but od shows the exact bytes.

Further reading: GNU coreutils: od invocation

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link