Last Updated : 17 Jul, 2025
The rev
command in Linux is used to reverse the characters in each line of a string or text. It reads input line by line and outputs each line with its characters in reverse order. If no file is specified, rev
reads from standard input; otherwise, it processes the contents of the given file(s) and writes the reversed output to the terminal.
Here, we will explore the syntax, examples, and options associated with the rev command to effectively utilize it in your Linux environment.
Syntaxrev [option] [file...]
where,
Use the man rev
command to access the manual page and learn more about the usage and options of the rev
command.
man revExample 2: How to Reverse a String Using the rev Command
changing the order of characters in the string so that the first character becomes the last, the second becomes the second-last, and so on
Syntax:rev {press Enter}Example 3: Displaying Reverse text in the Terminal
[string] {press Enter}
When you reverse text in the terminal, you use a command (like rev
) to take a string or file input and output the text with the character order reversed, directly in the terminal window.
echo "enter the text" |revExample 4: Reverse the text into the text file
Suppose we have a text file named as 'sample.txt'.
Using rev command on sample file. It will display the result on the terminal as follows:
Each line in the file is processed individually, and the characters within each line are reversed.
Common Options for the rev commandThe rev command comes with a few options that can be helpful for specific tasks. Below are the available options:
1. -V (version):This option displays the version information of the rev command and then exits
Syntax:rev -V2. -h (help):
This option prints a help message, displaying the available options and usage of the rev command.
Syntax:rev -hConclusion
The rev command in Linux is a useful utility for reversing the order of characters in each line of text, whether it's from a file or direct input. While the command is simple, it can be powerful when combined with other Linux commands for text manipulation tasks. By understanding its syntax, options, and examples, you can incorporate rev into your Linux workflow to simplify text processing tasks.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4