The tr command in Linux is used for translating or deleting characters from standard input. It reads from the input, processes the characters according to the specified options, and outputs the result to standard output. Common uses include:
- Translating characters: You can replace specific characters with others.
- Deleting characters: You can remove specified characters from the input.
- Changing case: You can convert lowercase letters to uppercase and vice versa.
Example Usage
-
Translate characters:
echo "hello" | tr 'h' 'H'Output:
Hello -
Delete characters:
echo "hello world" | tr -d 'o'Output:
hell wrld -
Change case:
echo "Hello World" | tr 'a-z' 'A-Z'Output:
HELLO WORLD
You can combine options and use it in various ways to manipulate text in the command line.
