0
0
Linux CLIscripting~5 mins

tr (translate characters) in Linux CLI - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the tr command do in Linux?
The tr command translates or replaces characters from input text. It reads from standard input and writes to standard output.
Click to reveal answer
beginner
How do you use tr to change all lowercase letters to uppercase?
Use tr 'a-z' 'A-Z'. This replaces every lowercase letter with its uppercase version.
Click to reveal answer
intermediate
What happens if the second set of characters in tr is shorter than the first?
The last character of the second set is repeated to match the length of the first set.
Click to reveal answer
beginner
How can you delete characters using tr?
Use the -d option with the characters to delete. For example, tr -d 'aeiou' deletes vowels.
Click to reveal answer
intermediate
Explain the use of tr -s option.
The -s option squeezes repeated characters into one. For example, tr -s ' ' replaces multiple spaces with a single space.
Click to reveal answer
What does tr '0-9' ' ' do?
AReverses digits
BDeletes digits
CConverts digits to asterisks
DReplaces digits with spaces
Which option deletes characters in tr?
A-d
B-s
C-c
D-r
How do you convert uppercase letters to lowercase using tr?
Atr 'A-Z' 'a-z'
Btr 'a-z' 'A-Z'
Ctr '0-9' 'a-z'
Dtr -d 'A-Z'
What does tr -s '\n' do?
ADeletes newlines
BReplaces newlines with spaces
CSqueezes multiple newlines into one
DDuplicates newlines
If the second set is shorter in tr, what happens?
AError occurs
BSecond set is repeated to match first
CCharacters are deleted
DNo change happens
Describe how to use tr to replace all vowels with asterisks in a text.
Think about specifying vowels as first set and '*' as second set.
You got /4 concepts.
    Explain the difference between tr -d and tr -s options with examples.
    Consider how each option changes the input text differently.
    You got /3 concepts.