XK0-005 practice question 8 of 10

A file called testfile has both uppercase and lowercase letters: $ cat testfile ABCDEfgH IJKLmnoPQ abcdefgH ijklLMNopq A Linux administrator is…

Full set: 487 questions

A file called testfile has both uppercase and lowercase letters:

$ cat testfile ABCDEfgH IJKLmnoPQ abcdefgH ijklLMNopq

A Linux administrator is tasked with converting testfile into all uppercase and writing it to a new file with the name uppercase.

Which of the following commands will achieve this task?

Answer options
A: tr '(A-Z}' '{a-z}' uppercase
B: echo testfile | tr "[Z-A]" "[z-a]" uppercase
C: cat testfile | tr '{z-a)' '{Z-A}' uppercase
D: tr '[a-z]' '[A-Z]' uppercase Correct answer
Correct Answer:
D. tr '[a-z]' '[A-Z]' < testfile > uppercase
Explanation

The tr (translate) utility reads characters from standard input and replaces or deletes them before writing the results to standard output. To convert lowercase ASCII characters to uppercase, tr requires the source character set [a-z] as its first argument and the target replacement set [A-Z] as its second argument. The syntax tr '[a-z]' '[A-Z]' properly specifies this translation mapping. Redirection operators (such as outputfile) direct standard input from testfile and standard output to uppercase. Among the provided choices, option D specifies the correct tr command syntax and character range order required to perform lowercase-to-uppercase translation across all text input.

Why Incorrect

A. tr '(A-Z}' '{a-z}' uppercase: Uses incorrect character ranges and reverses translation order, mapping uppercase characters into lowercase instead of converting lowercase to uppercase.
B. echo testfile | tr "[Z-A]" "[z-a]" uppercase: Passes only the string literal "testfile" rather than file contents, and specifies invalid reverse character ranges [Z-A] and [z-a].
C. cat testfile | tr '{z-a)' '{Z-A}' uppercase: Uses invalid reverse character ranges (z-a) and improper brace syntax, which prevents valid character translation by tr.

References

GNU Coreutils Manual: Section 11.2 tr: Translate characters. https://www.gnu.org/software/coreutils/manual/html_node/tr-invocation.html

IEEE Std 1003.1-2017 (POSIX.1): tr utility specification. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/tr.html

Scroll to Top