The lightest text tool
tr works on individual characters, not lines or words. Read stdin, translate or delete characters, write stdout. No regex, no fields. Just character mappings.
The four useful modes
tr 'a-z' 'A-Z'— translate set 1 to set 2 (1:1).tr -d 'aeiou'— delete every vowel.tr -s '\n'— squeeze runs of newlines into one.tr -c 'a-zA-Z' '_'— complement: replace every non-letter with underscore.
Special character classes
tr understands [:upper:], [:lower:], [:digit:], [:space:], [:punct:]. tr -d '[:punct:]' nukes punctuation; tr '[:upper:]' '[:lower:]' is the locale-aware lowercase.
What tr can't do
It can't replace strings — only characters. tr 'foo' 'bar' doesn't change foo into bar; it maps f→b, o→a, o→r per character. For string-level replacement, use sed.
Daily uses
- Strip Windows line endings:
tr -d '\r' < in.txt > out.txt - Tab-to-space:
tr '\t' ' ' - Random uppercase:
echo 'hello' | tr a-z A-Z - Compress whitespace:
tr -s '[:space:]' ' '