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 Linux? Linux the essential for DevOps Roles.

The syntax rev command

rev [option] [file...]

For example

Use rev command reverse the output of hostname command as below

[root@ip-10-0-0-236 ~]# hostname
ip-10-0-0-236.us-east-2.compute.internal
[root@ip-10-0-0-236 ~]# hostname | rev
lanretni.etupmoc.2-tsae-su.632-0-0-01-pi
[root@ip-10-0-0-236 ~]#

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

[root@ip-10-0-0-236 ~]# hostname
ip-10-0-0-236.us-east-2.compute.internal
[root@ip-10-0-0-236 ~]# hostname | rev | cut -b 1-8 | rev
internal

Sorting File Lines by Last Character

[ec2-user@ip-172-31-45-95 ~]$ cat domain.txt
devopsroles.com
abc.xyz
huuphan.com

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

Conclusion

Thought the article, you can use rev command examples in Linux as above. I hope will this your helpful. rev Command – Reverse Order of Characters on Command Line

, ,

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 DevopsRoles.com 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 *

Comment moderation is enabled. Your comment may take some time to appear.

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