$linuxjunkies
>

rev(1)

Reverse lines characterwise.

UbuntuDebianFedoraArch

Synopsis

rev [FILE]...

Description

The rev command reads each line of input and outputs it with characters in reverse order. It processes files line by line, preserving the newline at the end of each reversed line.

If no files are specified, rev reads from standard input. Multiple files are processed in sequence, with each line reversed independently.

Common options

FlagWhat it does
-h, --helpDisplay help message and exit
-V, --versionDisplay version information and exit

Examples

Reverse a simple string; outputs 'olleh'

echo 'hello' | rev

Reverse each line in the hostname file

rev /etc/hostname

Reverse multiple lines; outputs 'cba', 'fed', 'ihg'

echo -e 'abc\ndef\nghi' | rev

Reverse lines from both file1.txt and file2.txt

rev file1.txt file2.txt

Reverse each filename from a directory listing

ls | rev

Reverse twice to verify the operation (output matches original)

cat script.sh | rev | rev

Related commands