rev command in Linux with example

In this tutorial, How do I use the rev command used to reverse the character of the line in LinuxLinux the essential for DevOps Roles. Now, let’s rev command in Linux.

The “rev” command in Linux is a utility that is used to reverse the order of characters in each line of a file or standard input. It is particularly useful for reversing the contents of a file or reversing the output of another command.

The syntax rev command in Linux

rev [option] [file...]

Some common options for the “rev” command include:

  • -V: Displays the version information for the command.
  • -h: Shows the help information.
  • -c: Treats input as single characters instead of entire lines.

On the man page, the describes it

  • rev – reverse lines characterwise.
  • man rev – More details information about rev command.
rev command in Linux with example

For example

Using the rev command reverses the output of the hostname command as below

[root@ip-10-0-0-236 ~]# hostname
[root@ip-10-0-0-236 ~]# hostname | rev
[root@ip-10-0-0-236 ~]#

How to get 8 last characters use the combine rev command and cut command 🙂

[root@ip-10-0-0-236 ~]# hostname
[root@ip-10-0-0-236 ~]# hostname | rev | cut -b 1-8 | rev

Sorting File Lines by Last Character

[ec2-user@ip-172-31-45-95 ~]$ cat domain.txt

[ec2-user@ip-172-31-45-95 ~]$ cat domain.txt  | rev | sort | rev


Through the article, you can use rev command examples in Linux as above. Please note that the “rev” command does not modify the original file; it only displays the reversed output on the terminal or redirects it to another file.

I hope will this your helpful. rev Command – Reverse Order of Characters on Command-Line. Thank you for reading the DevopsRoles page!

, ,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.