Linux rev Command

Categories:

Linux rev command

The rev command in Linux reverses lines of text characterwise.

Following is its syntax: rev [option] [file…]

1rev [option] [file…]

And here’s what the man page says about it: The rev utility copies the specified files to standard output, revers? ing the order of characters in every line. If no files are specified, standard input is read.

123The rev utility copies the specified files to standard output, revers?ing the order of characters in every line. If no files are specified,standard input is read.

Following are some examples that should give you a better idea on how the rev command works.

To use rev command

Simple, just execute ‘rev’ sans any option. rev

1rev

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’re done, press the Enter key, and you’ll see reversed text in the output.

For example, I entered the following input: hello world

1hello world

And got the following output: dlrow olleh

1dlrow olleh
rev command works with files

This is also pretty straightforward. Just pass the name of the file as input, and you’ll see reversed contents in output.

So you can see that the lines in file ‘test.txt’ got reversed in the output.

To see help and version information

Use the -V and -h command line options for this. rev -V rev -h

12rev -Vrev -h

Here’s the output these commands produced on my system

To reverse line wise, instead of character wise

While the rev command works character wise on lines of text,there’s another command – dubbed tac – that reverses the information lines wise. You can learn more about tac by heading here.

Conclusion

The rev command doesn’t have a steep learning curve. In fact, it doesn’t really offer many command line options.