Skip to content

rev Linux Command Guide

The Linux rev command is used to reverse lines character-wise. It reads each line from the input and reverses the order of characters on that line before displaying it on the standard output. This command is particularly useful for manipulating text and data streams in various command line tasks. By using the rev command, you can easily reverse the content of files, strings, or data pipelines, allowing for quick and efficient text processing.

rev Syntax:

Terminal window
rev [option] [file]

Options:

OptionDescription
-V, —versionDisplay version information
-h, —helpDisplay help information

Parameters:

ParameterDescription
fileThe name of the file to be reversed

rev Command Samples:

Reverse a String

Terminal window
echo "Hello, World!" | rev

Reverses the string “Hello, World!“.

Reverse each line in a File

Terminal window
rev filename.txt

Reverses each line in the file “filename.txt”.

Reverse a Character String with Tail Command

Terminal window
echo "Linux Commands" | rev | tail -c +2

Reverses the string “Linux Commands” and removes the first character using the tail command.

Reverse a File with rev Command

Terminal window
rev file.txt

Displays the content of the file “file.txt” in reverse order.

Reverse Specific Characters in a String

Terminal window
echo "12345ABCDE" | rev | cut -c 3-

Reverses the string “12345ABCDE” and displays characters starting from the 3rd position using the cut command.

Reverse specific columns in a CSV File

Terminal window
awk -F',' '{print $2,$1}' file.csv | rev

Reverses the columns in a CSV file “file.csv”.

Reverse specific fields in a Tab-Separated File

Terminal window
awk -F'\t' '{print $1,$3,$2}' data.tsv | rev

Reverses specific fields in a tab-separated file “data.tsv”.

rev FAQ:

{Questions}

Applications of the rev command

  • Reverse lines in a file
  • Reverse characters in a string
  • Create backwards text for creative purposes