how.wtf

rev command in Linux and how to reverse strings

· Thomas Taylor

What is the rev command in Linux?

What is the rev command?

As the name implies, the rev command (short for reverse) allows users to reverse a line of characters or a file.

How is the rev command used?

The rev command is typically supplied a string of characters or a file input.

rev with a file

If a file named example.txt contains:

1This is a line of text
2txet fo enil a si siht
3another one

and rev is supplied example.txt, then the output will showcase the reversed result.

1% rev example.txt
2txet fo enil a si sihT
3this is a line of text
4eno rehtona

rev with standard input

rev accepts standard input by default.

1% rev
2this is a line
3enil a si siht

OR

1% echo this is a line | rev
2enil a si siht

This is useful for scripting capabilities:

1foo="I want this text reversed"
2bar=$(echo $foo | rev)
3echo $bar

#linux  

Reply to this post by email ↪