{
    "mode": "man",
    "parameter": "tr",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/man/tr/json",
    "generated": "2026-10-20T19:23:30Z",
    "synopsis": "tr [OPTION]... STRING1 [STRING2]",
    "sections": {
        "NAME": {
            "content": "tr - translate or delete characters\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "tr [OPTION]... STRING1 [STRING2]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Translate, squeeze, and/or delete characters from standard input, writing to standard output.\nSTRING1 and STRING2 specify arrays of characters ARRAY1 and ARRAY2 that control the action.\n",
            "subsections": [
                {
                    "name": "-c -C --complement",
                    "content": "use the complement of ARRAY1\n",
                    "flag": "-C",
                    "long": "--complement"
                },
                {
                    "name": "-d --delete",
                    "content": "delete characters in ARRAY1, do not translate\n",
                    "flag": "-d",
                    "long": "--delete"
                },
                {
                    "name": "-s --squeeze-repeats",
                    "content": "replace each sequence of a repeated character that is listed in the last specified AR‐\nRAY, with a single occurrence of that character\n",
                    "flag": "-s",
                    "long": "--squeeze-repeats"
                },
                {
                    "name": "-t --truncate-set1",
                    "content": "first truncate ARRAY1 to length of ARRAY2\n\n--help display this help and exit\n",
                    "flag": "-t",
                    "long": "--truncate-set1"
                },
                {
                    "name": "--version",
                    "content": "output version information and exit\n\nARRAYs  are  specified as strings of characters.  Most represent themselves.  Interpreted se‐\nquences are:\n\n\\NNN   character with octal value NNN (1 to 3 octal digits)\n\n\\\\     backslash\n\n\\a     audible BEL\n\n\\b     backspace\n\n\\f     form feed\n\n\\n     new line\n\n\\r     return\n\n\\t     horizontal tab\n\n\\v     vertical tab\n\nCHAR1-CHAR2\nall characters from CHAR1 to CHAR2 in ascending order\n\n[CHAR*]\nin ARRAY2, copies of CHAR until length of ARRAY1\n\n[CHAR*REPEAT]\nREPEAT copies of CHAR, REPEAT octal if starting with 0\n\n[:alnum:]\nall letters and digits\n\n[:alpha:]\nall letters\n\n[:blank:]\nall horizontal whitespace\n\n[:cntrl:]\nall control characters\n\n[:digit:]\nall digits\n\n[:graph:]\nall printable characters, not including space\n\n[:lower:]\nall lower case letters\n\n[:print:]\nall printable characters, including space\n\n[:punct:]\nall punctuation characters\n\n[:space:]\nall horizontal or vertical whitespace\n\n[:upper:]\nall upper case letters\n\n[:xdigit:]\nall hexadecimal digits\n\n[=CHAR=]\nall characters which are equivalent to CHAR\n\nTranslation occurs if -d is not given and both STRING1 and STRING2 appear.  -t is  only  sig‐\nnificant  when  translating.   ARRAY2  is  extended to length of ARRAY1 by repeating its last\ncharacter as necessary.  Excess characters of ARRAY2 are ignored.  Character  classes  expand\nin  unspecified  order;  while  translating,  [:lower:] and [:upper:] may be used in pairs to\nspecify case conversion.  Squeezing occurs after translation or deletion.\n",
                    "long": "--version"
                }
            ]
        },
        "BUGS": {
            "content": "Full support is available only for safe single-byte locales, in which  every  possible  input\nbyte  represents  a  single character.  The C locale is safe in GNU systems, so you can avoid\nthis issue in the shell by running LCALL=C tr instead of plain tr.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Written by Jim Meyering.\n",
            "subsections": []
        },
        "REPORTING BUGS": {
            "content": "GNU coreutils online help: <https://www.gnu.org/software/coreutils/>\nReport any translation bugs to <https://translationproject.org/team/>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright © 2023 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3  or  later\n<https://gnu.org/licenses/gpl.html>.\nThis  is free software: you are free to change and redistribute it.  There is NO WARRANTY, to\nthe extent permitted by law.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Full documentation <https://www.gnu.org/software/coreutils/tr>\nor available locally via: info '(coreutils) tr invocation'\n\nGNU coreutils 9.4                           January 2026                                       TR(1)",
            "subsections": []
        }
    },
    "summary": "tr - translate or delete characters",
    "flags": [
        {
            "flag": "-C",
            "long": "--complement",
            "arg": null,
            "description": "use the complement of ARRAY1"
        },
        {
            "flag": "-d",
            "long": "--delete",
            "arg": null,
            "description": "delete characters in ARRAY1, do not translate"
        },
        {
            "flag": "-s",
            "long": "--squeeze-repeats",
            "arg": null,
            "description": "replace each sequence of a repeated character that is listed in the last specified AR‐ RAY, with a single occurrence of that character"
        },
        {
            "flag": "-t",
            "long": "--truncate-set1",
            "arg": null,
            "description": "first truncate ARRAY1 to length of ARRAY2 --help display this help and exit"
        },
        {
            "flag": "",
            "long": "--version",
            "arg": null,
            "description": "output version information and exit ARRAYs are specified as strings of characters. Most represent themselves. Interpreted se‐ quences are: \\NNN character with octal value NNN (1 to 3 octal digits) \\\\ backslash \\a audible BEL \\b backspace \\f form feed \\n new line \\r return \\t horizontal tab \\v vertical tab CHAR1-CHAR2 all characters from CHAR1 to CHAR2 in ascending order [CHAR*] in ARRAY2, copies of CHAR until length of ARRAY1 [CHAR*REPEAT] REPEAT copies of CHAR, REPEAT octal if starting with 0 [:alnum:] all letters and digits [:alpha:] all letters [:blank:] all horizontal whitespace [:cntrl:] all control characters [:digit:] all digits [:graph:] all printable characters, not including space [:lower:] all lower case letters [:print:] all printable characters, including space [:punct:] all punctuation characters [:space:] all horizontal or vertical whitespace [:upper:] all upper case letters [:xdigit:] all hexadecimal digits [=CHAR=] all characters which are equivalent to CHAR Translation occurs if -d is not given and both STRING1 and STRING2 appear. -t is only sig‐ nificant when translating. ARRAY2 is extended to length of ARRAY1 by repeating its last character as necessary. Excess characters of ARRAY2 are ignored. Character classes expand in unspecified order; while translating, [:lower:] and [:upper:] may be used in pairs to specify case conversion. Squeezing occurs after translation or deletion."
        }
    ],
    "examples": [],
    "see_also": [],
    "tldr": {
        "source": "official",
        "description": "Translate characters: run replacements based on single characters and character sets.",
        "examples": [
            {
                "description": "Replace all occurrences of a character in a file, and print the result",
                "command": "tr < {{path/to/file}} {{find_character}} {{replace_character}}"
            },
            {
                "description": "Replace all occurrences of a character from another command's output",
                "command": "echo {{text}} | tr {{find_character}} {{replace_character}}"
            },
            {
                "description": "Map each character of the first set to the corresponding character of the second set",
                "command": "tr < {{path/to/file}} '{{abcd}}' '{{jkmn}}'"
            },
            {
                "description": "Delete all occurrences of the specified set of characters from the input",
                "command": "tr < {{path/to/file}} {{-d|--delete}} '{{input_characters}}'"
            },
            {
                "description": "Compress a series of identical characters to a single character",
                "command": "tr < {{path/to/file}} {{-s|--squeeze-repeats}} '{{input_characters}}'"
            },
            {
                "description": "Translate the contents of a file to upper-case",
                "command": "tr < {{path/to/file}} \"[:lower:]\" \"[:upper:]\""
            },
            {
                "description": "Strip out non-printable characters from a file",
                "command": "tr < {{path/to/file}} {{-cd|--complement --delete}} \"[:print:]\""
            }
        ]
    }
}