--- layout: page author: Alessandro Luini category-page: advanced category-title: Advanced commands tags: translate title: tr ---
tr is a command in Unix-like operating systems. It is an abbreviation of translate or transliterate, indicating its operation of replacing or removing specific characters in its input data set.
The utility reads a byte stream from its standard input and writes the result to the standard output. As arguments, it takes two sets of characters (generally of the same length), and replaces occurrences of the characters in the first set with the corresponding elements from the second set. For example,
tr 'abcd' 'jkmn'
maps all characters a to j, b to k, c to m, and d to n.
The character set may be abbreviated by using character ranges. The previous example could be written:
tr 'a-d' 'jkmn'
tr -s '\n'replaces sequences of one or more newline characters with a single newline.
tr -d '\r'