Skip to content

tr command

Translate, squeeze or delete characters.

On this page

Syntax

tr [options] set1 [set2]

Provided by the coreutils package. Run man tr for the full manual.

Common options

OptionWhat it does
-dDelete characters in set1
-sSqueeze repeated characters into one
-cUse the complement of set1

Examples

  1. Lowercase to uppercase

    echo "hello" | tr a-z A-Z
  2. Uppercase to lowercase

    tr '[:upper:]' '[:lower:]' < file.txt
  3. Delete digits

    echo "abc123" | tr -d 0-9
  4. Squeeze repeated spaces

    tr -s ' ' < file.txt
  5. Replace newlines with spaces

    tr '\n' ' ' < list.txt
  6. Remove Windows line endings

    tr -d '\r' < win.txt > unix.txt

tr guides

← All Linux commands · Suggest a fix

Back to top