The tr command in Unix-like operating systems, which name stands for TRanslate or TRansliterate, indicating its operation of replacing or removing specific characters in its input data set.

How to use

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'
would 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 also written as:
tr 'a-d' 'jkmn'


  • -s: The s flag causes tr to compress sequences of identical adjacent characters in its output to a single token.
    tr -s '\n'
    replaces sequences of one or more newline characters with a single newline.
  • -d: The d flag causes tr to delete all tokens of the specified set of characters from its input. In this case, only a single character set argument is used. The following command removes carriage return characters.
    tr -d '\r'