After many years of administration of Unix/Linux systems and using bash for many tasks i’ve discovered the command
tac, the contrary of
What this command do it’s to concatenate and print files in reverse order, it writes each file to standard output, last line first.
bash$ cat file1.txt This is the line 1. This is the line 2. bash$ tac file1.txt This is the line 2. This is the line 1.
This is the basic usage of
tac but you could use it also for other things like recovering a text file with a bad block:
( cat badfile.log ; tac badfile.log | tac ) > goodfile.log
When there is a bad block in the middle of your file, you can see its beginning with `cat’ and its end with `tac’. But both commands terminates with an error. So this sequence rebuilds a new file without the bad block.
A similar command is
rev that copies the specified files to the standard output, reversing the order of characters in every line.
For example taking the former example we have:
bash$ cat file1.txt This is the line 1. This is the line 2. bash$ rev file1.txt .1 enil eht si sihT .2 enil eht si sihT
And naturally you can combine the two, to have a file totally inverted:
bash$ cat file1.txt This is the line 1. This is the line 2. bash$ rev file1.txt | tac .2 enil eht si sihT .1 enil eht si sihT
- None Found