≡ Menu

rev command

HowTo: Reverse a String In Unix / Linux Shell?

How do I reverse lines of a file or files under Linux or Unix like operating systems?
[click to continue…]

Shell script reverse lines of a file

Q. How do I reverse lines of a file under Linux / UNIX bash shell?

A. You need to use the rev utility or command. It copies the specified files to the standard output, reversing the order of characters in every line. If no files are specified, the standard input is read.

Display one line

tail -1 /etc/passwd


Reverse one line

$ tail -1 /etc/passwd | rev