有没有办法从终端中的文件末尾向后读取字符?

use*_*261 3 command-line cat less

例如,less 允许您从头开始逐行阅读。是否有类似的实用程序或行可以在终端中运行,可以逐个字符地向后显示文件?如果没有,一个“猫”之类的实用程序如何按字符向后显示整个文件?

Sco*_*and 6

这样做:

cat /tmp/aa | tac | rev
Run Code Online (Sandbox Code Playgroud)

其中 tac 逐行反转文件,保持字符完整......然后 rev 通过简单地反转每个给定行的字符来完成它,保持逐行完整......所以例如:

cat /tmp/aa 


Is there a way to read characters backwards from the end of a file in the terminal?

For instance, less allows you to read line by line, starting from the beginning. Is there a similar utility or line that could be run in the terminal that could display a file backward character by character?



cat /tmp/aa | tac | rev


retcarahc yb retcarahc drawkcab elif a yalpsid dluoc taht lanimret eht ni nur eb dluoc taht enil ro ytilitu ralimis a ereht sI .gninnigeb eht morf gnitrats ,enil yb enil daer ot uoy swolla ssel ,ecnatsni roF

lanimret eht ni elif a fo dne eht morf sdrawkcab sretcarahc daer ot yaw a ereht sI
Run Code Online (Sandbox Code Playgroud)

  • 不错的答案,但这里的 `cat` 太多了:`tac /tmp/aa | 转速` (5认同)
  • 实际上,如果您提供文件作为参数,`tac` 可以更有效地反向打印行,因为它可以向后查找原始文件,而不必将其复制到临时缓冲区中。另外,结合`tac | rev` 与逐个字符向后打印文件不完全相同;它在反转之前有效地将换行符从文件末尾移动到开头。 (4认同)