{"id":7278,"date":"2018-11-22T17:22:15","date_gmt":"2018-11-22T14:22:15","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-rev-command\/"},"modified":"2018-11-22T17:22:15","modified_gmt":"2018-11-22T14:22:15","slug":"linux-rev-command-tutorial-for-beginners-with-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-rev-command-tutorial-for-beginners-with-examples\/","title":{"rendered":"Linux rev Command Tutorial for Beginners (with Examples)"},"content":{"rendered":"<article readability=\"54.745621351126\">\n<p>Sometimes, while working on the Linux command line, you may want to reverse a string or line(s) of text. You&#8217;ll be glad to know there are command line utilities that let you do exactly this. Here, in this tutorial, we will discuss one such tool, dubbed rev. But before we do that, it&#8217;s worth mentioning that all examples here have been tested on an Ubuntu 18.04 LTS machine.<\/p>\n<h2 id=\"linux-rev-command\">Linux rev command<\/h2>\n<p>The rev command in Linux reverses lines of text characterwise. Following is its syntax:<\/p>\n<pre class=\"command\"><code spellcheck=\"false\">rev [option] [file...]<\/code><\/pre>\n<p>And here&#8217;s what the man page says about it:<\/p>\n<pre><code spellcheck=\"false\"> The\u00a0 rev utility copies the specified files to standard output, revers?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ing the order of characters in every line.\u00a0 If no files are\u00a0 specified,<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 standard input is read.<\/code><\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a better idea on how the rev command works.<\/p>\n<h2 id=\"q-how-to-use-rev-command\">Q1. How to use rev command?<\/h2>\n<p>Simple, just execute &#8216;rev&#8217; sans any option.<\/p>\n<pre class=\"command\"><code spellcheck=\"false\">rev<\/code><\/pre>\n<p>When you execute the tool in such a way, it will wait for you to enter some input. You can enter a word or a line, and as soon as you&#8217;re done, press the Enter key, and you&#8217;ll see reversed text in the output.<\/p>\n<p>For example, I entered the following input:<\/p>\n<pre><code spellcheck=\"false\">hello world<\/code><\/pre>\n<p>And got the following output:<\/p>\n<pre><code spellcheck=\"false\">dlrow olleh<\/code><\/pre>\n<h2 id=\"q-how-rev-command-works-with-files\">Q2. How rev command works with files?<\/h2>\n<p>This is also pretty straightforward. Just pass the name of the file as input, and you&#8217;ll see reversed contents in output.<\/p>\n<p>Here&#8217;s an example:<\/p>\n<p><a class=\"fancybox\" id=\"img-rev-files\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/rev-files.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/11\/linux-rev-command-tutorial-for-beginners-with-examples.png\" alt=\"How rev command works with files\" width=\"303\" height=\"182\" title=\"\"><\/a><\/p>\n<p>So you can see that the lines in file &#8216;test.txt&#8217; got reversed in the output.<\/p>\n<h2 id=\"q-how-to-see-help-and-version-information\">Q3. How to see help and version information?<\/h2>\n<p>Use the -V and -h command line options for this.<\/p>\n<pre class=\"command\"><code spellcheck=\"false\">rev -V<\/code><\/pre>\n<pre class=\"command\"><code spellcheck=\"false\">rev -h<\/code><\/pre>\n<p>Here&#8217;s the output these commands produced on my system:<\/p>\n<p><a class=\"fancybox\" id=\"img-rev-v-h-options\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/rev-v-h-options.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/11\/linux-rev-command-tutorial-for-beginners-with-examples-1.png\" alt=\"How to see help and version information\" width=\"301\" height=\"216\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-reverse-line-wise-instead-of-character-wise\">Q4. How to reverse line wise, instead of character wise?<\/h2>\n<p>While the rev command works character wise on lines of text, there&#8217;s another command &#8211; dubbed tac &#8211; that reverses the information lines wise. You can learn more about tac by heading <a href=\"https:\/\/www.howtoforge.com\/linux-tac-command\/\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>The rev command doesn&#8217;t have a steep learning curve. In fact, it doesn&#8217;t really offer many command line options. In this tutorial, we have discussed majority stuff. To learn more about rev, you can head to the <a href=\"https:\/\/linux.die.net\/man\/1\/rev\" target=\"_blank\" rel=\"noopener noreferrer\">tool&#8217;s man page<\/a>.<\/p>\n<\/article>\n<aside class=\"authorbox\" readability=\"10\">\n<img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/11\/linux-rev-command-tutorial-for-beginners-with-examples.jpg\" alt=\"Himanshu Arora\" title=\"\"> <\/p>\n<p><strong>About Himanshu Arora<\/strong><\/p>\n<p>Himanshu Arora has been working on Linux since 2007. He carries professional experience in system level programming, networking protocols, and command line. In addition to HowtoForge, Himanshu&#8217;s work has also been featured in some of world&#8217;s other leading publications including Computerworld, IBM DeveloperWorks, and Linux Journal.<\/p>\n<\/aside>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-rev-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/11\/linux-rev-command-tutorial-for-beginners-with-examples-2.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-rev-command%2F&amp;text=Linux+rev+Command+Tutorial+for+Beginners+%28with+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/11\/linux-rev-command-tutorial-for-beginners-with-examples-3.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/11\/linux-rev-command-tutorial-for-beginners-with-examples-4.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-rev-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/11\/linux-rev-command-tutorial-for-beginners-with-examples-5.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes, while working on the Linux command line, you may want to reverse a string or line(s) of text. You&#8217;ll be glad to know there are command line utilities that let you do exactly this. Here, in this tutorial, we will discuss one such tool, dubbed rev. But before we do that, it&#8217;s worth mentioning [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-7278","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/7278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=7278"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/7278\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=7278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=7278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=7278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}