tr command
Translate, squeeze or delete characters.
- Text processing
- Package coreutils
- 3 options · 6 examples
Syntax
tr [options] set1 [set2]Provided by the coreutils package. Run man tr for the full manual.
Common options
| Option | What it does |
|---|---|
-d | Delete characters in set1 |
-s | Squeeze repeated characters into one |
-c | Use the complement of set1 |
Examples
Lowercase to uppercase
echo "hello" | tr a-z A-ZUppercase to lowercase
tr '[:upper:]' '[:lower:]' < file.txtDelete digits
echo "abc123" | tr -d 0-9Squeeze repeated spaces
tr -s ' ' < file.txtReplace newlines with spaces
tr '\n' ' ' < list.txtRemove Windows line endings
tr -d '\r' < win.txt > unix.txt
No example matches. Check the options table or search the guides.
tr guides
- TR Command in Linux: A Guide with Practical Examples Linux Commands · Updated Apr 2025
