🐧 Linux / Shell Scripting
Intermediate
What is the tr command used for?
Answer
tr (translate) reads from stdin and replaces or deletes individual characters. tr 'a-z' 'A-Z' converts lowercase to uppercase. tr 'A-Z' 'a-z' does the reverse. tr -d '\n' deletes all newlines (joins all lines into one). tr -d '[:space:]' removes all whitespace. tr -s ' ' squeezes multiple spaces into one. echo "hello" | tr '[a-m]' '[A-M]'. Common use: cat file | tr ',' '\n' converts CSV commas to newlines. tr only works on single characters, not strings — use sed for multi-character replacements. It's very fast for character-level transformation of large files.