Ad space (banner)
🖥️Linux Lessons
Lesson 59 / 61

Reversing Text with rev

rev is for when "I want to display a string backwards." rev stands for reverse, and it outputs each line of input with its characters flipped left-to-right.

Use it in the form rev filename. Each line of a file is reversed independently, and the order of the lines themselves doesn't change.

Running rev notes.txt displays each line of notes.txt with its characters flipped left-to-right.

A common early mistake is assuming this reverses the order of the lines themselves — it doesn't. rev only flips the character order within each line. To reverse the line order, use tac instead.

In real work, this doesn't come up too often, but it's occasionally used for a simple palindrome check, or lightweight obfuscation of part of a log.

Linux
Try it (type this into the pseudo terminal)
rev notes.txt

🧑‍💻 You can type this command into the Linux pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)