Bash 5 reference · Text and System Tools

tr (Linux command)

Translate, squeeze or delete characters, such as changing case, removing carriage returns or splitting words onto lines.

Bash 5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

tr [-d] [-s] SET1 [SET2]

Parameters

ParameterDescription
'a-z' 'A-Z' Map one set to another.
-d '\r' Delete characters.
-s ' ' Squeeze repeated characters.

Examples

Case and squeeze
echo 'make me loud' | tr a-z A-Z
echo 'too    many   spaces' | tr -s ' '

Output

MAKE ME LOUD
too many spaces

Run this on your computer — see “Get Started” for setup.

Split words and remove CR
echo 'one two three' | tr ' ' '\n'
printf 'line\r\n' | tr -d '\r' | od -c | head -1

Output

one
two
three
0000000   l   i   n   e  \n

Run this on your computer — see “Get Started” for setup.

Was this page helpful?