-
-
Notifications
You must be signed in to change notification settings - Fork 1
Linux tr Guide
Mattscreative edited this page Dec 5, 2025
·
2 revisions
Complete beginner-friendly guide to tr on Linux, covering Arch Linux, CachyOS, and other distributions including character translation, text transformation, and character manipulation.
tr (translate) translates or deletes characters.
Uses:
- Character translation: Replace characters
- Case conversion: Change case
- Character deletion: Remove characters
- Text transformation: Transform text
Why it matters:
- Text processing: Transform text
- Data cleaning: Clean up data
- Scripting: Useful in scripts
Basic usage:
# Translate characters
echo "hello" | tr 'e' 'E'
# Output: hElloChange case:
# Lowercase to uppercase
echo "hello" | tr 'a-z' 'A-Z'
# Output: HELLOUse sets:
# Translate set
echo "hello123" | tr 'a-z' 'A-Z'
# Output: HELLO123Remove characters:
# Delete characters
echo "hello123" | tr -d '0-9'
# -d = delete
# Output: helloRemove duplicates:
# Squeeze repeated
echo "hello world" | tr -s ' '
# -s = squeeze
# Output: hello worldInvert selection:
# Delete non-digits
echo "hello123" | tr -cd '0-9'
# -c = complement, -d = delete
# Output: 123Check installation:
# Check tr
which tr
# Usually in coreutils
# Install if missing
sudo pacman -S coreutilsThis guide covered tr usage, character translation, and text transformation for Arch Linux, CachyOS, and other distributions.
- sed and awk Guide - Text processing
- cut Guide - Field extraction
-
tr Documentation:
man tr
This guide covers Arch Linux, CachyOS, and other Linux distributions. For distribution-specific details, refer to your distribution's documentation.