LinuxCommandLibrary

trans

Translate text from one language to another

TLDR

Translate a word (language is detected automatically)

$ trans "[word_or_sentence_to_translate]"
copy

Get a brief translation
$ trans [[-b|-brief]] "[word_or_sentence_to_translate]"
copy

Translate a word into french
$ trans :[fr] [word]
copy

Translate a word from German to English
$ trans [de]:[en] [Schmetterling]
copy

Behave like a dictionary to get the meaning of a word
$ trans [[-d|-dictionary]] [word]
copy

SYNOPSIS

tr [OPTION]... SET1 [SET2]

PARAMETERS

-c, -C, --complement
    Use the complement of SET1.

-d, --delete
    Delete characters in SET1.

-s, --squeeze-repeats
    Replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that character.

-t, --truncate-set1
    First truncate SET1 to length of SET2 if SET1 is longer.

--help
    Display help message and exit.

--version
    Output version information and exit.

DESCRIPTION

The tr command in Linux is a powerful utility used for character translation, deletion, and squeezing of repeated characters from standard input. It reads standard input, performs the specified operations on it, and writes the result to standard output.

tr is commonly used for tasks like changing lowercase letters to uppercase, removing specific characters, or replacing one set of characters with another. It operates on a character-by-character basis, making it versatile for text manipulation in shell scripts and command-line workflows.

While simple in its operation, the correct usage of character sets and options like -d (delete), -s (squeeze), and -c (complement) allows for efficient text transformations. Be mindful of locale settings, as they can influence the interpretation of character ranges.

CAVEATS

The tr command works character-by-character, not word-by-word. It can be tricky to use with multibyte characters or when needing more sophisticated string processing. Regular expressions are not supported directly.

CHARACTER SETS

SET1 and SET2 can be character sets defined using character ranges (e.g., a-z), character classes (e.g., [:lower:]), or literal characters.
Special characters like backslash need to be properly escaped within the character sets.

HISTORY

The tr command is a standard Unix utility, appearing early in the history of Unix-like operating systems. Its purpose has remained largely consistent: to provide a simple and efficient way to translate or delete characters. Over time, options like -s and -d were added to enhance its functionality. It is a fundamental tool widely used in scripting and command-line environments.

SEE ALSO

sed(1), awk(1), grep(1)

Copied to clipboard