How to Use the rev Command on Linux

Share
  • July 26, 2019

Fatmawati Achmad Zaenuri/Shutterstock

Linux’s rev command reverses strings of text. This command can operate either on provided text or a file, and it seems deceptively simple. But like many command-line utilities, its real power becomes apparent when you combine it with other commands.

The rev command is one of those simple Linux utilities that, at first glance, appears to be something of an oddity. It performs a single function: it reverses strings. And apart from being able to print a quick help page (-h) and show you its version number (-V), it doesn’t accept any command-line options.

So, rev reverses strings, and that’s it? No variations or options? Well, yes and no. Yes, it has no permutations, but no, that’s hardly all. This tutorial shows you how to combine it for powerful operations.

When you use rev as a building block in more complicated command sequences, it really starts to show its worth. rev is one of a group of commands (like tac and yes) that are facilitators. It’s easier to appreciate their usefulness when you see how they make the use of other commands more efficient.

Using the rev Command

Used on the command line with no other parameters, rev takes any typed input, reverses it, and then prints it in the terminal window. It keeps doing this until you hit Ctrl+C to exit.

rev

"rev" used with "stdin" in a terminal window.

If you type some text and press Enter, it makes rev print the string in reverse—unless you provide it with a palindrome, of course.

"rev" with a palindrome in a terminal window.

Passing Text to rev

You can use echo to pipe text to rev.

echo one two three | rev

Read the remaining 35 paragraphs

Source : How to Use the rev Command on Linux