rev flags & options
Basic usage
Reverse each line of a file character by character.
rev file.txt
Pipe usage
Reverse text from stdin.
echo "hello world" | rev
Reverse each line
Each line is reversed independently.
printf "abc\n123\nxyz\n" | rev
Extract file extension
Common trick: get the last field by reversing, cutting, and reversing again.
echo "archive.tar.gz" | rev | cut -d. -f1 | rev
Get last path component
echo "/usr/local/bin/python3" | rev | cut -d/ -f1 | rev
Check for palindromes
word="racecar"; [ "$(echo $word | rev)" = "$word" ] && echo "palindrome"