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.

Terminal window
rev [option] [file]
OptionDescription
-V, —versionDisplay version information
-h, —helpDisplay help information
ParameterDescription
fileThe name of the file to be reversed
Terminal window
echo "Hello, World!" | rev

Reverses the string “Hello, World!”.

Terminal window
rev filename.txt

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

Reverse a Character String with Tail Command

Section titled “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.

Terminal window
rev file.txt

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

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

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

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

Section titled “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”.

{Questions}

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