Text and processing

The tr command

Changes or deletes characters. Very useful to uppercase or clean text.

Syntax

tr [opciones] conjunto1 [conjunto2]

Most useful options

-dDeletes the characters of the set
-sSqueezes repeats

Copy-ready examples

$ echo hola | tr a-z A-ZTo uppercase
$ echo hola | tr -d oDeletes the letter o
$ printf 'aaa\n' | tr -s aSqueezes repeats

You can try them in the browser terminal: it does not touch your computer.

Typical mistakes

  • tr works character by character, not with words.

Related commands

FAQ

Can it replace one word with another?

No: that is sed. tr only changes, deletes or squeezes characters.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course